problem with glDrawPixels

Hi.
I’m writing an app with OpenGL that displays a portion of a very large image as background. This background must fit the entire OpenGL window, and this window can be resized (in this case the portion displayed must change accordingly).
My app uses glDrawPixels to do this.
Now I have a problem and two questions.
The problem is:
Several times, when I resize the window (and only with particular dimensions of the window, the bitmap is not displayed correctly. The bitmap presents distortion artifacts and is displayed in gray-scale (my image is RGB). Other times the background is displayed in the correct manner.

Now:

  • Where is the problem? My videocard currently is a Matrox G200 MMS (multimonitor).
  • There is another way to display the image? The image can be of any size and must mantain 1:1 ratio with window’s dimension.

I include portion of my code.

//update bitmap of the background
CBackground::CaptureArea(CDIBSection& image, CRect rect)
{
// CDIBSection & CFilterCrop belongs to PAINTLIB
CFilterCrop crop(rect.left, rect.right, rect.top, rect.bottom);

crop.Apply(&image,&back);
nrows = back.GetHeight();
ncols = back.GetWidth();

rgb_data = new unsigned char[nrowsncols3];
size_x = ncols;
size_y = nrows;

for(row = 0; row < nrows; row++)
{
for ( col = 0; col < ncols; col++)
{
pixel = back.GetPixel(col, row);
index = ((nrows-row-1)ncols+col) * 3;
ucp = (unsigned char
)(&pixel);
rgb_data[index] = ucp[RGBA_RED];
rgb_data[index+1] = ucp[RGBA_GREEN];
rgb_data[index+2] = ucp[RGBA_BLUE];
}
}

}

// Render background
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
//ensure that bitmap is inside viewing frustum
glRasterPos2f( left+1, bottom-1);
glDrawPixels(bg.GetSizeX(), bg.GetSizeY(), GL_RGB, GL_UNSIGNED_BYTE, bg.GetRGBData());
glEnable(GL_ALPHA_TEST);
glEnable(GL_TEXTURE_2D);

Please help me.
Best regards.

Hi!
Sorry I was too lazy to read your code but I can only tell you one thing:
Don´t use glDrawPixels\glReadPixels ´cause they are perhaps the slowest functions available in OpenGl…
So if speed is concerned use a textured quad which you make the size of the screen…

HTH, XBTC!

XBCT is right: use textured quads. It requires more work, but will give you top performance and more flexibility than glDrawPixels if you know how to use texture mapping. More detailed create a texture that can contain you background and is power of 2 in dimensions (for example, a 1024x512 texture for a 640x480 background). If your card wont support bug textures, you’ll need to tile the background (having multiple 256x256 texture, for example). Then render the texture quad or quads in an ortho projection, using texcoords to match the quad vertices to your image portion inside the texture.

Thanks.
In any case, I fixed the bug using
glPixelStorei(GL_UNPACK_ALIGNMENT,1)

I’ll switch to texture mapping ASAP.

Bye Bye.
Nicola Mosca
somewhere in time