Help!
New to opengl, and having trouble understanding how to use blending.
Does it not work with glDrawPixels?
I want a sort of fading effect between frames.
The rough idea in pseudo code is:
//init RGBA pixel buffer
pixels = AllocMem( width*height*4 );
while (looping) {
//clear viewport
glClear;
//enable blending
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ZERO );
//draw previous framebuffer;
glDrawPixels( width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels );
//disable blending
glDisable(GL_BLEND);
//set color
glColor4f( 1, 1, 1, 0.9 );
//draw points
glBegin( GL_POINTS );
...
...
glEnd;
//copy framebuffer to pixel buffer
glReadPixels( x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels );
SwapBuffers;
}
I thought this would draw the previous framebuffer with decreasing alpha, so the older points would gradually fade away. However, they seem to be drawn at full intensity. If blending is left enabled, the points drawn in the current frame are blended with the previous, so blending is working. What am I doing wrong, or do I need to copy the buffer to a texture instead and forget about using glReadPixels? I’ve read that glDrawPixels treats the pixels the same as typical fragments, so I don’t know why it wouldn’t work.