View Full Version : Strange colors on FBO

10-04-2006, 06:51 AM
Hi All,

I am using a FBO to create images from the opengl scene.

The strange thing is that color does not match. Only pure colors like Red, Green, Blu look like Real red, green, blu.

Does anybody know why? Does it matter somehow how the rendering context is created?

Thanks in advance,


10-04-2006, 06:54 AM
Any more hints would be really appreciable. But who had the same problems as you (if any) it would be really hard to find out what is the problem.

Maybe you speek about texturing...

10-04-2006, 07:01 AM

The goal is to get a bitmap from OpenGL scene.

I did this way:

int nRenderbufferSize = 1024;

uint uFramebuffer = gl.GenFramebuffersEXT();

gl.BindFramebufferEXT(gl.FRAMEBUFFER_EXT, uFramebuffer);

uint uColourbuffer = gl.GenRenderbuffersEXT();
gl.BindRenderbufferEXT(gl.RENDERBUFFER_EXT, uColourbuffer);
gl.RenderbufferStorageEXT(gl.RENDERBUFFER_EXT, gl.RGBA, nRenderbufferSize, nRenderbufferSize);
gl.FramebufferRenderbufferEXT(gl.FRAMEBUFFER_EXT, gl.COLOR_ATTACHMENT0_EXT, gl.RENDERBUFFER_EXT, uColourbuffer);

uint uDepthbuffer = gl.GenRenderbuffersEXT();
gl.BindRenderbufferEXT(gl.RENDERBUFFER_EXT, uDepthbuffer);
gl.RenderbufferStorageEXT(gl.RENDERBUFFER_EXT, gl.DEPTH_COMPONENT, nRenderbufferSize, nRenderbufferSize);
gl.FramebufferRenderbufferEXT(gl.FRAMEBUFFER_EXT, gl.DEPTH_ATTACHMENT_EXT, gl.RENDERBUFFER_EXT, uDepthbuffer);

// Make sure it worked.
Debug.Assert(gl.CheckFramebufferStatusEXT(gl.FRAME BUFFER_EXT) == gl.FRAMEBUFFER_COMPLETE_EXT);

int nDrawBuffer = gl.GetIntegerv(gl.DRAW_BUFFER);
int nReadBuffer = gl.GetIntegerv(gl.READ_BUFFER);

// Draw here

// Bitmap storage here

How can colors don't match with this code?



10-04-2006, 07:19 AM
It is most possible that your bitmap storage code is wrong. To test it, you could copy your FBO image to a texture and render it to screen.
A hint: maybe you donwload the image to the bitmap using the GL_RGBA storage type, in this case you should use GL_BRGA (as windows and opengl uses different color byte ordering).

10-04-2006, 07:26 AM

On the texture, colors are fine. With both GL_RGBA and GL_BGRA colors don't match, and they don't match in different way...

I really don't know what to check.

Thanks again,


10-04-2006, 08:38 AM
I guess full piece of code could help, however I won't be able to check it (I'm not using GL under java). But it could really help (if not me, surely others).

Also if you could explain better what you mean with 'colors do not match'. Don't you use additive colors in some way and subtractive one in other ways ?

10-04-2006, 12:06 PM
I can add that the bitmap is dithered, fills are made up from different pixels colors.

What does it mean? I am reading from a 32bbp FBO and storing on a 32bbp bitmap...

Thanks again,


10-04-2006, 12:21 PM
Hi Guy,

I got a big improvement althought not perfect yet.

I had to change Bitmap PixelFormat from 32bppArgb to 32bppRgb.

Now colors match BUT on the bitmap fills are made up from different pixel colors.

Now the question is:

What is the best match between windows pixel format 32bppRgb and glReadPixel formats GL_RGB, GL_RGBA, GL_RGB_MODE, etc. ?!?!

Thanks a lot,


10-04-2006, 01:09 PM
The windows rgb format is equal to gl bgr format, as i already said. You shoudl read BRGA data from FBO and place it in a 32 bit windows bitmap.

10-06-2006, 12:53 AM
I was reading RGBA and storing to a 32bpp bitmap, this caused the problem.

Reading RGB and storing to 24bpp bitmap is ok.

Thanks a lot for your help.