CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001

    glReadPixels() Help!

    Hello, I am not familiar with OpenGL and its API, but I was wondering how I would go about using the function glReadPixels()? Yes, yes, I have looked at all of the declarations for it as MSDN, etc., but I still am I not sure how to utilize it. In order to use the function, must I intialize a bunch of OpenGL things as I would for DirectDraw? How would I incorporate this function in a Win32 program that reads the color values of pixels in a game running in OpenGL? Also, once pixel data is retrieved, say with the GL_RGB flag (or any other one for that matter. I'm not too familiar in which mode to use), how do I access the color information of the pixels? Is it stored in hexademical, etc? If possible, it would to great to have example code showing how to use glReadPixels(). Thank you very much in advance.

  2. #2
    Join Date
    Feb 2000
    Slovenia, Europe

    Re: glReadPixels() Help!

    This is a screencapture function I`m using.
    It captures RGB information of the screen and stores it in UNSIGNED_BYTE format, that is three bytes RGB.

    DB = uchar
    DW = ushort
    DD = ulong
    typedef struct{ DB Head[12];
    DW DX, DY, Head2;
    DB Pic[768*1024][3];
    } TypeTGA;
    TypeTGA TGA;

    char CaptureName[256];
    DD CaptureNo;
    DB TGAHead[12] = {0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    ScreenCapture (void)
    // Prepare targa header
    TGA.DX = Screen.Width;
    TGA.DY = Screen.Height;
    TGA.Head2 = 0x2018;

    glReadPixels (0,0,Screen.Width,Screen.Height,GL_RGB,GL_UNSIGNED_BYTE,TGA.Pic[0]);

    sprintf(CaptureName,"Snapshots\\Pic_%04x.TGA",CaptureNo); CaptureNo++;
    cc = fopen(CaptureName,"wb");
    fwrite(&TGA,1,(18 + 3*Screen.Width*Screen.Height),cc); fclose(cc);


  3. #3
    Join Date
    Mar 2013

    Re: glReadPixels() Help!


    I used you code but I have my output saved picture is reversed.

    Have you please an Idea about this problem?
    Thank you in advance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.