PDA

View Full Version : Drawing tons of points



fizzlesticks
04-02-2012, 07:11 PM
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.

Alfonse Reinheart
04-02-2012, 08:27 PM
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.

fizzlesticks
04-02-2012, 08:49 PM
Ya, I know, unfortunately opengl is required for the assignment :(

zeoverlord
04-03-2012, 04:06 AM
Use a texture instead and transfer the rendered pixels using glTexSubImage2D.
And transfer at least line by line instead of individual pixels

fizzlesticks
04-03-2012, 02:49 PM
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.

Rosario Leonardi
04-03-2012, 03:50 PM
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.

fizzlesticks
04-03-2012, 05:18 PM
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,W INDOW_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.

ZbuffeR
04-04-2012, 03:11 AM
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).

V-man
04-04-2012, 05:22 AM
The storage format also has an effect


glTexSubImage2D(GL_TEXTURE_2D,0,0,0,WINDOW_WIDTH,W INDOW_HEIGHT,GL_RGB,GL_FLOAT,&amp;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.

fizzlesticks
04-04-2012, 11:59 PM
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.