Sign in to follow this  

glReadPixels ??

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ... ^^

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 ...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this