Results 1 to 4 of 4

Thread: problem with glDrawPixels

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2000

    problem with glDrawPixels

    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.

    - 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.bottom);

    nrows = back.GetHeight();
    ncols = back.GetWidth();

    rgb_data = new unsigned char[nrows*ncols*3];
    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
    //ensure that bitmap is inside viewing frustum
    glRasterPos2f( left+1, bottom-1);
    glDrawPixels(bg.GetSizeX(), bg.GetSizeY(), GL_RGB, GL_UNSIGNED_BYTE, bg.GetRGBData());

    Please help me.
    Best regards.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2000

    Re: problem with glDrawPixels

    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!

  3. #3
    Senior Member Regular Contributor
    Join Date
    Feb 2000

    Re: problem with glDrawPixels

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2000

    Re: problem with glDrawPixels

    In any case, I fixed the bug using

    I'll switch to texture mapping ASAP.

    Bye Bye.
    Nicola Mosca
    somewhere in time

Similar Threads

  1. glDrawPixels problem
    By imported_xargon in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 02-14-2006, 01:02 PM
  2. do i have any problem on glDrawPixels()?
    By wusheng in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-19-2004, 02:53 AM
  3. Problem with glDrawPixels
    By yaro_dup1 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-16-2003, 11:55 AM
  4. glDrawPixels Problem
    By mop in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-09-2003, 06:27 PM
  5. glDrawPixels problem
    By Menne in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 02-02-2002, 03:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean