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