OpenGL does not draw the exact color I specified!

Hi!

I draw a simple quad with the color 128, 128, 128 (RGB) with orth. projection. Blending and lights are disabled and I use the shade model GL_FLAT.

My problem is, that the rendered quad has the color 130, 132, 130 instead of 128, 128, 128…

What do I have to switch on/off to get my rectangle rendered with the color 128, 128, 128?

Thanks!

How do you specify your colors? Could it be the conversion to floating point 0…1 color that looses some precision?

It’s pretty much like


int red = 128;
int green = 128;
int blue = 128;

gl.glColor3d((double)red/255.0,
                (double)green/255.0,
                (double)blue/255.0);

I think the conversion is not the problem. A conversion mistake does not explain why the value for green is different to the red and blue color values. A conversion mistake would result in three equal values.

I should maybe add here, that I determined the rendered color values by taking a screenshot. I wrote the color values in the 0…255 notation to make my post a bit more convenient to read :slight_smile:

Maybe you don’t get a 24 bit backbuffer. Instead getting a 16 bit 5,6,5 format. That would explain why green is different from red and blue.

Use the following code to print out your frame buffer’s bit depths:


            int[] parm = new int[1];
            
            int r,g,b,a,d,s;
            
            gl.glGetIntegerv(GL.GL_RED_BITS,     parm); r = parm[0];
            gl.glGetIntegerv(GL.GL_GREEN_BITS,   parm); g = parm[0];
            gl.glGetIntegerv(GL.GL_BLUE_BITS,    parm); b = parm[0];
            gl.glGetIntegerv(GL.GL_ALPHA_BITS,   parm); a = parm[0];
            gl.glGetIntegerv(GL.GL_DEPTH_BITS,   parm); d = parm[0];
            gl.glGetIntegerv(GL.GL_STENCIL_BITS, parm); s = parm[0];
            
            System.out.println(  "R=" + r + 
                               ", G=" + g +
                               ", B=" + b +
                               ", A=" + a +
                               ", D=" + d +
                               ", S=" + s);

Wow! Of course! I’m such an idiot! I accidentally set up my graphics cards to use only 16 bits color depth a few days ago. I just turned it back to 32 bits and BANG it works fine. (I’m missing a smiley here for self-punishment).

Thank you very much! You rescued my computer graphics grade :slight_smile: