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.