1 2/* Draw test patterns to help determine correct gamma value for a display. 3 When the intensities of the inner squares nearly match the intensities 4 of their frames (from some distance the borders should disappear) then 5 you've found the right gamma value. 6 7 You can set Mesa's gamma values (for red, green and blue) with the 8 MESA_GAMMA environment variable. But only on X windows! 9 For example: 10 setenv MESA_GAMMA 1.5 1.6 1.4 11 Sets the red gamma value to 1.5, green to 1.6 and blue to 1.4. 12 See the main README file for more information. 13 14 For more info about gamma correction see: 15 http://www.inforamp.net/~poynton/notes/colour_and_gamma/GammaFAQ.html 16 17 This program is in the public domain 18 19 Brian Paul 19 Oct 1995 20 Kai Schuetz 05 Jun 1999 */ 21 22/* Conversion to GLUT by Mark J. Kilgard */ 23 24 25#include <stdio.h> 26#include <string.h> 27#include <stdlib.h> 28#include "glut_wrap.h" 29 30static void 31Reshape(int width, int height) 32{ 33 glViewport(0, 0, (GLint) width, (GLint) height); 34 35 glMatrixMode(GL_PROJECTION); 36 glLoadIdentity(); 37 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 38 glMatrixMode(GL_MODELVIEW); 39 glShadeModel(GL_FLAT); 40} 41 42/* ARGSUSED1 */ 43static void 44key_esc(unsigned char key, int x, int y) 45{ 46 if(key == 27) exit(0); /* Exit on Escape */ 47} 48 49static GLubyte p25[] = { 50 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 51 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 52 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 53 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 54 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 55 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 56 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 57 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 58 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 59 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 60 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 61 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 62 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 63 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 64 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 65 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 66}; 67 68static GLubyte p50[] = { 69 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 70 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 71 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 72 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 73 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 74 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 75 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 76 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 77 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 78 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 79 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 80 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 81 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 82 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 83 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 84 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 85}; 86 87static GLubyte p75[] = { 88 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 89 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 90 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 91 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 92 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 93 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 94 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 95 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 96 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 97 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 98 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 99 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 100 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 101 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 102 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 103 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 104}; 105 106static GLubyte *stippletab[4] = {NULL, p25, p50, p75}; 107 108static void 109gamma_ramp(GLfloat yoffs, GLfloat r, GLfloat g, GLfloat b) 110{ 111 GLint d; 112 113 glColor3f(0.0, 0.0, 0.0); /* solid black, no stipple */ 114 glRectf(-1.0, yoffs, -0.6, yoffs + 0.5); 115 116 for(d = 1; d < 4; d++) { /* increasing density from 25% to 75% */ 117 GLfloat xcoord = (-1.0 + d*0.4); 118 GLfloat t = d * 0.25; 119 120 glColor3f(r*t, g*t, b*t); /* draw outer rect */ 121 glRectf(xcoord, yoffs, xcoord+0.4, yoffs + 0.5); 122 123 glColor3f(0.0, 0.0, 0.0); /* "clear" inner rect */ 124 glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375); 125 126 glColor3f(r, g, b); /* draw stippled inner rect */ 127 glEnable(GL_POLYGON_STIPPLE); 128 glPolygonStipple(stippletab[d]); 129 glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375); 130 glDisable(GL_POLYGON_STIPPLE); 131 } 132 glColor3f(r, g, b); /* solid color, no stipple */ 133 glRectf(0.6, yoffs, 1.0, yoffs + 0.5); 134} 135 136static void 137display(void) 138{ 139 gamma_ramp( 0.5, 1.0, 1.0, 1.0); /* white ramp */ 140 gamma_ramp( 0.0, 1.0, 0.0, 0.0); /* red ramp */ 141 gamma_ramp(-0.5, 0.0, 1.0, 0.0); /* green ramp */ 142 gamma_ramp(-1.0, 0.0, 0.0, 1.0); /* blue ramp */ 143 glFlush(); 144} 145 146int 147main(int argc, char **argv) 148{ 149 glutInitWindowSize(500, 400); 150 glutInit(&argc, argv); 151 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); 152 glutCreateWindow("gamma test patterns"); 153 glutReshapeFunc(Reshape); 154 glutDisplayFunc(display); 155 glutKeyboardFunc(key_esc); 156 157 glutMainLoop(); 158 return 0; /* ANSI C requires main to return int. */ 159} 160