Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: glReadPixels and glDrawPixels question

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    4

    glReadPixels and glDrawPixels question

    Hi evrybody,
    I'm puzzled by this: why when I draw a single pixel using Drawpixels on position x,y and read it back right after that I don't get the updated pixel data?
    here's my code:
    Code :
    uchar color_vals[4];
    glRasterPos2i(x, y);
    glDrawPixels(1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color_vals);
    glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color_vals);
    I would appreciate it if anyone would clarify this for me

  2. #2
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: glReadPixels and glDrawPixels question

    first thing that pops into my head is checking glReadBuffer().
    In general using DrawPixels/ReadPixels is a bad idea. I used those but as soon as i tried my app on an Intel onboard chip it was soooooooooooo slow! use better textures instead?
    still try checking those params at glReadBuffer though they are BACK by default.

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: glReadPixels and glDrawPixels question

    If I am not mistaken, coordinates passed to glRasterPos are considered "object coordinates" thus treated like vertices coordinates set by glVertex. They are transformed by the modelview and projection matrices, then clipped and transformed to window coordinates.

    I think you want to set window coordinates directly since glReadPixels takes window coordinates, so use glWindowPos instead of glRasterPos

  4. #4
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: glReadPixels and glDrawPixels question

    actually true. or set modelview matrix to ortho (with the window size). glWindowPos just bypasses the transformation stuff and goes directly.

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    4

    Re: glReadPixels and glDrawPixels question

    first thing that pops into my head is checking glReadBuffer().
    glReadBuffer and glDrawPixels both use GL_BACK in doublebuffered mode by default.

    you're right about it being slow but at the moment it's my only choice.

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    4

    Re: glReadPixels and glDrawPixels question

    use glWindowPos instead of glRasterPos
    for some reason again unknown to me, my compiler complains about glWindowPos2i.
    Code :
    `glWindowPos2i' undeclared (first use this function)

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: glReadPixels and glDrawPixels question

    for some reason again unknown to me, my compiler complains about glWindowPos2i.
    So your are willingly using the wrong function because this one does not cause a compiler error?? You are joking!

    Solve your issue about glWindowPos and it would solve your problem. Check opengl headers version, update your drivers, you need gl 1.4 or greater.

  8. #8
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    354

    Re: glReadPixels and glDrawPixels question

    To use glWindowPos2i you need to call wglGetProcAddress(...) or glxGetProcAddress(...).

  9. #9
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: glReadPixels and glDrawPixels question

    Ah yes I forgot this. You can use glew or glee to not worry about this kind of problem.

  10. #10
    Junior Member Newbie
    Join Date
    Sep 2008
    Posts
    4

    Re: glReadPixels and glDrawPixels question

    thanks for the info. I'll give it a try.

Posting Permissions

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