I am currently working on a video player for Windows using OpenGL. It works great, but one of my main goal is accuracy. That is, the image displayed should be exactly the image that was saved as a video.
Taking away everything video/file/input related, I have something along these lines as my glutDisplayFunc:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLubyte frame[256*128*4]; // width*height*RGBA_size
for (int i=0;i<256*128;i++)
{
frame[i*4] = 0x00; // R
frame[i*4+1] = 0xAA; // G
frame[i*4+2] = 0x00; // B
frame[i*4+3] = 0x00; // A
}
glRasterPos2i(0,0);
glDrawPixels(256,128,GL_RGBA,GL_UNSIGNED_BYTE,frame);
glutSwapBuffers();
Combined with the code for glut..
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(256, 128);
glutCreateWindow("...");
glutDisplayFunc(Render);
glPixelZoom(1,-1); // use top-to-bottom display
glEnable(GL_DEPTH_TEST);
glutMainLoop();
This is pretty straightforward and a huge simplification of the actual code. A frame with a RGB value #00AA00 is created and drawn with glDrawPixels.
As expected, the output is a green window. On first glance all seems good.
But when I use a tool such as http://instant-eyedropper.com/ to know the exact RGB value of a pixel, I realize that not all of the pixels are displayed as #00AA00.
Some pixels will have a value of #00A900. It will be the case of the first pixel in the top-left corner, as well as the 3rd, the 5th and so on on the same line and for every uneven line.
Now it can’t be a problem with Instant Eyedropper or with Windows since other programs output the right color for the same file.
Now my question:
Could it be possible that glDrawPixels somehow changes the pixels values, maybe as a way to go faster?
I would expect such a function to display exactly what we input in it, so I’m not quite sure what to think of it.
OpenGL has enabled color dithering by default. So your GPU actually may perform color dithering for some reason. Try disabling it with
glDisable(GL_DITHER);. Also be aware of colour management issues.