This is a simple OpenGL app that runs in full screen (game mode), shows every other pixel in alternating color, and displays the screen resolution (m x n grid of pixels) and the screen dimension in millimeters.
Note: The pixels are actually black and white, but because this screenshot is reduced in size, you see a gray background. Click on this image to see the full sized one.
The implementation is very simple. We use glutGet (GLUT_SCREEN_WIDTH) to get the screen width in pixels and glutGet (GLUT_SCREEN_HEIGHT) to get the screen height. To get the width and height in millimeters, we use glutGet (GLUT_SCREEN_WIDTH_MM) and glutGet (GLUT_SCREEN_HEIGHT_MM) consecutively. This would even tell us the width and height of a single pixel in millimeters. For example, pixel width in millimeters is equal to screen width in millimeters divided by the screen width in pixels. Same can be done for the height.
//------------------------------------------------------------------------- // Draw string representing the resolution of your screen //------------------------------------------------------------------------- void drawResolutionStr () { glColor3f (0, 0, 1); printw (20, 20, 0, "Resolution: %d x %d pixels, %d x %d mm", glutGet (GLUT_SCREEN_WIDTH), glutGet (GLUT_SCREEN_HEIGHT), glutGet (GLUT_SCREEN_WIDTH_MM), glutGet (GLUT_SCREEN_HEIGHT_MM)); glColor3f (1, 0, 0); printw (20, 45, 0, "Pixel Dimensions: %.4f x %.4f mm", (float)glutGet (GLUT_SCREEN_WIDTH_MM) / glutGet (GLUT_SCREEN_WIDTH), (float)glutGet (GLUT_SCREEN_HEIGHT_MM) / glutGet (GLUT_SCREEN_HEIGHT)); }
You can find the full source code here. If you have any issues compiling or running the app, check out this section for details about compiling and running an OpenGL app that uses the GLUT library.
Filed under: C, OpenGL
