glReadPixels ??

Started by
5 comments, last by silvermace 19 years, 7 months ago
Hi Here is my simple code : unsigned char* buffer = new unsigned char[width * height * 3]; glReadPixels(0, 0, width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer); but I get an error from glReadPixels : GL_INVALID_OPERATION this code is not between glBegin / glEnd Does anyone has an example of glReadPixels ? I just want to get the frame buffer and to save it in a file Is it the best solution to do that ? and how to use glReadPixels ?? thx a lot ... ^^
Advertisement
do you have a valid OpenGL context?
Here's what the blue book says about errors glReadPixels can cause

Quote:GL_INVALID_ENUM is generated if format or type is not an accepted value.

GL_INVALID_VALUE is generated if either width or height is not negative.

GL_INVALID_OPERATION is generated if format is GL_COLOR_INDEX and the color buffers store RGBA color components.

GL_INVALID_OPERATION is generated if format is GL_STENCIL_INDEX and there is no stencil buffer.

GL_INVALID_OPERATION is generated if format is GL_DEPTH_COMPONENT and there is no depth buffer.

GL_INVALID_OPERATION is generated if glReadPixels is called between a call to glBegin and the corresponding call to glEnd.


The only thing I can see with your code that may be what's causing the error is the use of GL_BGR_EXT (though I would've thought you'd be able to use it here), however that should cause a GL_INVALID_ENUM error, not a GL_INVALID_OPERATION error. Try using GL_RGB or something like that, it may work.

[edit]Well the extension description in the extension registry clearly states you can use GL_BGR_EXT for glReadPixels which isn't surprising as it's an extension for use with glReadPixels (which I didn't know before) [smile] , so it's most likely an invalid context like chowe6685 said[/edit]
well...
Yes, I think my context is correct, I can draw geometry, I have camera, lights, maps ..etc..
I surely did a mistake in the initialisation
Can you give me the steps to init this context ? just to check if mine is correct ??
thx ...
try the GL_RGB thingo, also check that your not trying
to copy a rect. thats larger than your screen size. test
it out with copying 256x256 first

if that fails, you could always try using glCopyTexSubImage2D

tried checking the specs on this extension?
http://oss.sgi.com/projects/ogl-sample/registry/EXT/bgra.txt
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
well thx but I dont think this function is usefull for me
I tried GL_RGB and I've got the same result :(

About the OGL context, I've read somewhere that we must use functions like glReadBuffer or glPixelStore before glReadPixels... ??
DO you have any ideas on it ?

I just want to get the frame buffer and save it in a file

thx
thats a really strange problem, i've never ever setup a context
in any kind of special manner, and have used glReadPixels without
problems.

could you provide any code? that would help...
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website

This topic is closed to new replies.

Advertisement