blob: 1b002ed7e8077a65a686c969b11fd2da9ffca4b1 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001
Brian Paul586b4f62000-03-18 01:13:29 +00002/* $Id: gamma.c,v 1.2 2000/03/18 01:13:29 brianp Exp $ */
jtgafb833d1999-08-19 00:55:39 +00003
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 $
Brian Paul586b4f62000-03-18 01:13:29 +000028 * Revision 1.2 2000/03/18 01:13:29 brianp
29 * colors were computed incorrectly (Hans Nelles)
30 *
31 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
32 * Imported sources
jtgafb833d1999-08-19 00:55:39 +000033 *
34 * Revision 3.1 1999/06/19 01:35:38 brianp
35 * merged in Kai Schuetz's RGB changes
36 *
37 * Revision 3.0 1998/02/14 18:42:29 brianp
38 * initial rev
39 *
40 */
41
42
43#include <stdio.h>
44#include <string.h>
45#include <stdlib.h>
46#include <GL/glut.h>
47
48static void
49Reshape(int width, int height)
50{
51 glViewport(0, 0, (GLint) width, (GLint) height);
52
53 glMatrixMode(GL_PROJECTION);
54 glLoadIdentity();
55 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
56 glMatrixMode(GL_MODELVIEW);
57 glShadeModel(GL_FLAT);
58}
59
60/* ARGSUSED1 */
61static void
62key_esc(unsigned char key, int x, int y)
63{
64 if(key == 27) exit(0); /* Exit on Escape */
65}
66
67static GLubyte p25[] = {
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 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
82 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
83 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
84};
85
86static GLubyte p50[] = {
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 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
101 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
102 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
103};
104
105static GLubyte p75[] = {
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 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
120 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
121 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
122};
123
124static GLubyte *stippletab[4] = {NULL, p25, p50, p75};
125
126static void
127gamma_ramp(GLfloat yoffs, GLfloat r, GLfloat g, GLfloat b)
128{
129 GLint d;
130
131 glColor3f(0.0, 0.0, 0.0); /* solid black, no stipple */
132 glRectf(-1.0, yoffs, -0.6, yoffs + 0.5);
133
134 for(d = 1; d < 4; d++) { /* increasing density from 25% to 75% */
135 GLfloat xcoord = (-1.0 + d*0.4);
Brian Paul586b4f62000-03-18 01:13:29 +0000136 GLfloat t = d * 0.25;
jtgafb833d1999-08-19 00:55:39 +0000137
Brian Paul586b4f62000-03-18 01:13:29 +0000138 glColor3f(r*t, g*t, b*t); /* draw outer rect */
jtgafb833d1999-08-19 00:55:39 +0000139 glRectf(xcoord, yoffs, xcoord+0.4, yoffs + 0.5);
140
141 glColor3f(0.0, 0.0, 0.0); /* "clear" inner rect */
142 glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375);
143
144 glColor3f(r, g, b); /* draw stippled inner rect */
145 glEnable(GL_POLYGON_STIPPLE);
146 glPolygonStipple(stippletab[d]);
147 glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375);
148 glDisable(GL_POLYGON_STIPPLE);
149 }
150 glColor3f(r, g, b); /* solid color, no stipple */
151 glRectf(0.6, yoffs, 1.0, yoffs + 0.5);
152}
153
154static void
155display(void)
156{
157 gamma_ramp( 0.5, 1.0, 1.0, 1.0); /* white ramp */
158 gamma_ramp( 0.0, 1.0, 0.0, 0.0); /* red ramp */
159 gamma_ramp(-0.5, 0.0, 1.0, 0.0); /* green ramp */
160 gamma_ramp(-1.0, 0.0, 0.0, 1.0); /* blue ramp */
161 glFlush();
162}
163
164int
165main(int argc, char **argv)
166{
167 glutInit(&argc, argv);
168 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
169
170 glutInitWindowPosition(50, 50);
171 glutInitWindowSize(500, 400);
172
173 glutCreateWindow("gamma test patterns");
174 glutReshapeFunc(Reshape);
175 glutDisplayFunc(display);
176 glutKeyboardFunc(key_esc);
177
178 glutMainLoop();
179 return 0; /* ANSI C requires main to return int. */
180}