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:


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

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.

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

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

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.

use glWindowPos instead of glRasterPos

for some reason again unknown to me, my compiler complains about glWindowPos2i.

`glWindowPos2i' undeclared (first use this function)

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.

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

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

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