Results 1 to 5 of 5

Thread: glReadPixels()

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2000
    Location
    germany
    Posts
    25

    glReadPixels()

    hi there.
    i want to add a 'save as' feature to my nice GL-scene. but i don't get glReadPixels() run. i use a double buffered window and it is NOT overlapped. glReadPixels does not fill the pixels array and sometimes it results in an 'int 3' ....

    // PixelStore and PixelTransfer are
    // at defaults;
    // r containes window size
    unsigned char * pixels_rgba = (unsigned char *) malloc (r.right * r.bottom * 4);

    glReadPixels(0, 0, 2, 2, GL_RED, GL_UNSIGNED_BYTE, &pixels_rgba);

    free(pixels_rgba);

    any hints??
    thanks a lot

    Kai

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: glReadPixels()

    you are not reading many pixels out, also why are you reading GL_RED?

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2000
    Location
    germany
    Posts
    25

    Re: glReadPixels()

    Originally posted by Gavin:
    you are not reading many pixels out, also why are you reading GL_RED?
    This is just a test and i reduced the area to 2x2 also to localize the prob. neither GL_RED nor GL_RGB ... worked.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: glReadPixels()

    try losing the ampersand.

  5. #5
    Member Contributor
    Join Date
    Jun 2001
    Posts
    55

    Re: glReadPixels()

    i use this code to make a screenshot and save it into a raw-file:

    Code :
    UByte* Data = new UByte[Width() * Height() * 3];
    if (Data)
    {
      glPixelStorei(GL_PACK_ALIGNMENT, 1);
      glReadPixels
      (
        0,
        0,
        Width(),
        Height(),
        GL_RGB,
        GL_UNSIGNED_BYTE,
        Data
      );
      ofstream File("Screenshot.raw", ios::binary);
      if (File.is_open())
        File.write(Data, Width() * Height() * 3);
      delete [] Data;
    }
    some explanations:
    typedef unsigned char UByte;

    Width() and Height() are 2 (wrapped) properties of my windowclass, guess what they mean (;


    i think gavain is right, u try writing the data to the address of the pointer und not the address the pointer points at

Similar Threads

  1. PBO and glReadPixels()
    By ehsan2004 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-24-2007, 05:20 AM
  2. about glReadPixels
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-05-2006, 08:18 PM
  3. glReadPixels
    By mphanke in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-04-2002, 08:24 AM
  4. glReadPixels()
    By hatemagnet in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-11-2002, 10:17 PM
  5. glReadPixels
    By Dagana in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 08-02-2001, 10:14 PM

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