View Full Version : Simple (?) Question On glDrawPixels

02-14-2008, 04:11 PM
Having trouble displaying JPEG images with glDrawPixels(). Using the code below, I can input and display a jpeg image as a TEXTURE. This means the image is being read into 'TextureArray' correctly. Can 'TextureArray' be used as the last parameter to the glDrawPixels command? If so, what should the other parameters be? Thank you.

int DrawGLScene(GLvoid)
glLoadIdentity ();

glPushMatrix ();
glTranslatef (1.3, 0, -5);
glBindTexture (GL_TEXTURE_2D, TextureArray[0]);
glBegin (GL_QUADS);
glTexCoord2f (0, 1); glVertex3f (-1, 1, 0);
glTexCoord2f (0, 0); glVertex3f (-1, -1, 0);
glTexCoord2f (1, 0); glVertex3f ( 1, -1, 0);
glTexCoord2f (1, 1); glVertex3f ( 1, 1, 0);
glPopMatrix ();

glRasterPos3f (-2.0, -1.5, -6);
glDrawPixels (360, 450, GL_RGB, GL_UNSIGNED_INT, // ???
(void *)(TextureArray[0]));

return TRUE;

02-14-2008, 06:31 PM
The "type" parameter would be GL_UNSIGNED_BYTE instead of GL_RGB, GL_UNSIGNED_INT. Because pixels are usually 8-bit per channel.

And, the last parameter of glDrawPixels() is the pointer to the actual pixel data. If the image data are stored in TextureArray, then, the param looks like:

However, I noticed that you also use TextureArray[0] into glBindTexture() call. Do you store pixel data in TextureAray, or store OpenGL texture object IDs in the array?

glBindTexture() needs the ID of the texture object, and glDrawPixels() needs the pointer to the pixel buffer (array).

02-14-2008, 07:04 PM
The snippet of code above is from a tutorial I downloaded, tweaked, compiled and ran. I don't really understand what it is doing. But if I comment out the call to glDrawPixels, the code correctly displays the jpeg image textured onto a rectangle. I was hoping that I could use TextureArray[0] in the call to glDrawPixels. But apparently there is a difference between a 'texture object' and a pointer to a pixel array. A JPEG loader library, including source code, comes with the tutorial. Next, I'll look at the code to see if I can figure out where (if) the image data is loaded into an array that I can pass to glDrawPixels. Thanks for your response.

02-14-2008, 08:11 PM
Funny how just a little hint in the right direction makes all the difference. songho - your discussion about 'texture objects' vs. 'pixel arrays' did the trick. Looking into the source code of the JPEG library from Apron Tutorials did the trick. I found where the pixel data is stored after being uncompressed, and, after some experimentation, found a way to extract that data and pass it over to the glDrawPixels routine. Voila - it works! Happy Valentine's Day!