Results 1 to 9 of 9

Thread: glReadPixels()

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    8

    glReadPixels()

    Hello. I've searched the forum and saw great examples on the usage of glReadPixels(), but everytime I check the values returned in color[3] they are always 204, 204, 204. Anyone knows why? Sorry if this question is dumb.

    Thanks!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: glReadPixels()

    You're doing something wrong. That's all I can say with the details you provided.

    Now, explain what you do. Preferably with code.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    8

    Re: glReadPixels()

    In my OnLButtonDown function, I have

    COrthoApp *m_orthodontics3dapp = (COrthoApp*)AfxGetApp();

    GLubyte color[3];

    glReadPixels(point.x,point.y,1,1,GL_RGB,GL_UNSIGNE D_BYTE,color);

    That's all. I have a break point after glReadPixels and when I check it, it says 204 204 204. Rather I think it's more like not changed by glReadPixels at all. Perhaps I'm not too familiar with VC programming. Please help?

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: glReadPixels()

    That was not very helpful.
    Do you have an OpenGL context current when reading? (Because 204 == 0xCC which is what some copilers use to tag uninitialzed data in debug mode. So maybe the OpenGL call did nothing to your local variable.)
    You are aware the point coordinates need to be in OpenGL screen coordinates (origin bottom left)?
    What's your glReadBuffer?
    What did you expect?

  5. #5
    Junior Member Newbie
    Join Date
    May 2003
    Posts
    2

    Re: glReadPixels()

    Can yu give the complete code?

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    8

    Re: glReadPixels()

    I'm sorry if I have irritated some of you, I'm a super newbie in this. I only have an extra glReadBuffer(GL_BACK) (since I use double buffering) before the glreadpixels line. I think the glreadpixels is not updating the color[3]. The device context should be correct, since it gets to breakpoint only in that child window and the coordinates are not windows coordinates (they are ok when I check the variables in debug). Does the fact that I'm using MFC with main frame/child windows matter?

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2004
    Posts
    8

    Re: glReadPixels()

    BTW I can't give the full code because that's all to that function (OnLButtonDown), and the rest of the files are in like megabytes. I had to take over somebody's job, that's why I'm so confused..

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: glReadPixels()

    If you're doing the read in the mouse down, you probably want to be reading from the front buffer since the back buffer that you drew to would already have been swapped to the front.

    Also, as has already been noted, you probably aren't reading at the point you think you are reading from... Windows coordinates (such as you get for the mouse position) read from upper left as 0,0 with positive Y going down, OpenGL coordinates (such as you want to pass to glReadPixels) read from the lower left as 0,0 with positive Y going up.
    Deiussum
    Software Engineer and OpenGL enthusiast

  9. #9
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: glReadPixels()

    I was not irritated, just straight.

    Again one reason for the function to not touch the color variable can be that you might not have an OpenGL context current at the time you do the call. Don't mix that term with device context (HDC).

    To check that:
    - Put a breakpoint on all wglMakeCurrent calls you find in the code and check if there is one != NULL when you're reaching the glReadPixels call.
    - You can also add a wglGetCurrentContext and wglGetCurrentDC right before the glReadPixels and check if they return valid handles and the ones you expected.
    - Add some simple drawing commands like
    glDrawBuffer(GL_FRONT);
    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glFinish();
    at that point and check if it works (=> red window).
    - Check if the color variable is really written by initializing it to some fancy number. (Could also be that you actually read some grey pixel from somewhere.)
    - For the experienced, switch to disassembly and check if you get through the OpenGL32.dll into the ICD.

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