Drawing tons of points

Hi, I’m making a simple ray tracer for a project and am trying to figure out the most efficient way to draw to every pixel on the screen. I’m currently using a 500x500 window and even before the ray tracing, just drawing black to every pixel using glBegin(GL_POINTS) is bringing the FPS down to about 5. Is there a better way that lets me specify the color for every pixel?

Thanks.

If all you’re using OpenGL to do is draw points you calculate on the CPU to the screen, there are far better ways to do that. Pretty much any GUI API will have faster ways of getting that done.

Ya, I know, unfortunately opengl is required for the assignment :frowning:

Use a texture instead and transfer the rendered pixels using glTexSubImage2D.
And transfer at least line by line instead of individual pixels

Thanks, that’s exactly what I was looking for. Although it didn’t help as much as I thought it would, only got around a 1 fps increase.

Can you show us the code of your render function?
Are you sure that the slow part is openGl?

Transfer a mem buffer on a texture and draw a quad with that texture shouldn’t take more than 2 ms (500 fps) on dx9 hardware.

void draw(){
	glClear(GL_COLOR_BUFFER_BIT);

	Segment* s;
	Vector out;
	Vector norm;
	bool todraw[WINDOW_HEIGHT][WINDOW_WIDTH];

	glTexSubImage2D(GL_TEXTURE_2D,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT,GL_RGB,GL_FLOAT,&colors);

	/*glBegin(GL_POINTS);
	for(int y=0;y<WINDOW_HEIGHT;y++){
		for(int x=0;x<WINDOW_WIDTH;x++){
				glColor3f(colors[y][x][0],colors[y][x][1],colors[y][x][2]);
				glVertex2i(x,y);
		}
	}
	glEnd();*/

	
	glBegin( GL_QUADS );
		glTexCoord2d(0.0,0.0); glVertex2i(0,0);
		glTexCoord2d(1.0,0.0); glVertex2i(WINDOW_WIDTH,0);
		glTexCoord2d(1.0,1.0); glVertex2i(WINDOW_WIDTH,WINDOW_HEIGHT);
		glTexCoord2d(0.0,1.0); glVertex2i(0,WINDOW_HEIGHT);
	glEnd();

	glFlush();
}

Right now, drawing using a texture is running at ~320fps. Using the commented out code to draw all the points runs at ~310.

only got around a 1 fps increase

Beware, this metric is misleading.
It could mean you went from 1 fps to 2 fps which is a great improvement (500ms spared).
It could mean you went from 200 to 201 which is totally insignificant (0.03 milliseconds difference).

The storage format also has an effect

glTexSubImage2D(GL_TEXTURE_2D,0,0,0,WINDOW_WIDTH,WINDOW_HEIGHT,GL_RGB,GL_FLOAT,&colors);

Are you sure that you have created a floating point texture?
Because if you haven’t, the driver will convert it which waste a little CPU time.

mmm ok, thanks for everything guys, it appears I’m just a tard. I was running the project in debug mode, once I switched to release the fps shot up to about 1600.