PDA

View Full Version : glReadPixels and glDrawPixels question



0blivi0n
09-28-2008, 11:34 PM
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:


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

_NK47
09-29-2008, 02:34 AM
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.

dletozeun
09-29-2008, 03:30 AM
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

_NK47
09-29-2008, 04:44 AM
actually true. or set modelview matrix to ortho (with the window size). glWindowPos just bypasses the transformation stuff and goes directly.

0blivi0n
09-29-2008, 10:48 AM
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.

0blivi0n
09-29-2008, 10:55 AM
use glWindowPos instead of glRasterPos
for some reason again unknown to me, my compiler complains about glWindowPos2i.

`glWindowPos2i' undeclared (first use this function)

dletozeun
09-29-2008, 01:30 PM
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.

trinitrotoluene
09-29-2008, 01:33 PM
To use glWindowPos2i you need to call wglGetProcAddress(...) or glxGetProcAddress(...).

dletozeun
09-29-2008, 02:13 PM
Ah yes I forgot this. You can use glew (http://www.opengl.org/sdk/libs/GLEW/) or glee (http://www.opengl.org/sdk/libs/GLee/) to not worry about this kind of problem.

0blivi0n
09-30-2008, 02:36 AM
thanks for the info. I'll give it a try.