I realize this is a common question, but reviewing the faq’s and redbook hasn’t helped. Its probably an assumption I’m making, so maybe a few thousand fresh eyes may help. I’m trying to read the back buffer into an array, do some image processing on the pixel values, write the array back to the back buffer, then swap buffers. I haven’t even made it to the image proc. point since I can’t seem to get Draw pixels to work. Her’s the code:
GLubyte Pixels = (GLubyte )calloc((26404804),sizeof(GLubyte));//2* to make sure
//image processing to go here
What do you mean it won’t work?
Make sure both the modelview is set to identity, and the projection matrix is set to an orthographic projection, with (0,0) in the lower left corner, before calling glRasterPos, especially if you want (0,0) to point to the lower left corner.
The corodinate passed to glRasterPos is transformed by both modelview and projection matrix, and if the resulting coordinate is outside the viewport, it will ve invalid and all drawing operations using the raster position won’t do anything.
For a 640x480 sized window, you can do this.
glOrtho(0, 640, 0, 480, -1, 1);
This way, you can use glRasterPos to directly target a certain pixel in the window.
Thanks Bob, You’ve lead me to a minor bug, but my big problem was my textures. I didn’t realize that glDrawPixels was sensitive to textures.