Results 1 to 3 of 3

Thread: glReadPixels

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    2

    glReadPixels

    What am I doing wrong? I run the following code to grab the contents of the frame buffer running my application in a window. w_, h_ denotes width, height of my window. I am using double buffering and do my grab just before I swap buffers. doing it after does not seem to make any change. My problem is that i get some other part of the screen or sometimes a small part of the window

    unsigned char* pixels = new unsigned char[ w_ * h_ * 3 ];

    glReadPixels( 0 , 0 , w_ , h_ , GL_RGB ,GL_UNSIGNED_BYTE , (GLvoid*) pixels);

    thanks Niels

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: glReadPixels

    Perhaps your origin is wrong, are you confusing window coords with viewport?

    There's may also a pixel transfer tweak on.


    [This message has been edited by dorbie (edited 03-05-2004).]

  3. #3
    Member Contributor
    Join Date
    Feb 2004
    Posts
    98

    Re: glReadPixels

    There's a distinct possibility that your OS does not allow the frame buffer to be read. This was fixed in later drivers for most systems. Later drivers being ones available about 2 years ago, so I don't imagine this is the problem.

    After a SwapBuffer command the contents of the framebuffer become undefined.

    Personally, I would change your array definition to "GLubyte pixels[q_ * h_ * 3];"

    new is a C++ operation, and a C++ array may not be the same as a C array. It might be, but I never trust the compiler and run-time of any system. Specifically, the C++ array might be the same as "struct { int length; void* ptr};" and you could be reading garbage in the system memory. Though I don't know why it wouldn't just SEGFAULT on you.

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