glDrawPixels

Started by
2 comments, last by bassman 19 years, 1 month ago
hi all, i've got a (noob) question regarding the glDrawPixels routine. i made a little glut program to try out this function, similar to the example program in the opengl programming guide. i just fill the following array with red pixels GLubyte check_image[CHECK_WIDTH][CHECK_HEIGHT][3]; and draw it with: glRasterPos2i(0,0); glDrawPixels(CHECK_WIDTH, CHECK_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, check_image); now the problem is that it gets drawn, only when i set my projection to orthographic: glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); when i have a perspective projection like this: glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30, (GLfloat)w / (GLfloat)h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); the array is not shown. this seems fairly odd to me. as far as i understand it the glDrawPixels function writes directly into the framebuffer, and projection settings should not influence the result. obviously they do. I'd be very happy if someone could explain the result or give me some pointers on how to use this function. greets, bassman
Advertisement
You are correct that the projection matrix does not affect the pixel transfer. However, it affect the raster position; that is, WHERE the image is draw. The raster position is transformed by the modelview and projection matix, just like any other vertex, before the final screen-space position is determined. That's why you need to correctly setup the projection matrix (and modelview also, of course) to get the image at the correct position.

But if you want to position the image in screen space, use glWindowPos instead. It sets the raster positon directly in window coordinates, bypassing any transformation.
If you're looking into glDrawPixels, also look into the GL_ARB_point_sprite extension; there's some overlap in utility, and ARB_point_sprite can be much more performant in certain situations. You don't often see glDrawPixels in production code.
Thanks for the help, it was greatly appreciated.

The glWindowPos function was exactly what I needed.
It was the first time I used extensions but it was
worth the effort.

Didn't take a look at GL_ARB_point_sprite yet as speed isn't
such a concern, the program I'm writing is educational,
but thanks for the tip.

greets,
Bassman





This topic is closed to new replies.

Advertisement