132001f49Smrg 232001f49Smrg/* Draw test patterns to help determine correct gamma value for a display. 332001f49Smrg When the intensities of the inner squares nearly match the intensities 432001f49Smrg of their frames (from some distance the borders should disappear) then 532001f49Smrg you've found the right gamma value. 632001f49Smrg 732001f49Smrg You can set Mesa's gamma values (for red, green and blue) with the 832001f49Smrg MESA_GAMMA environment variable. But only on X windows! 932001f49Smrg For example: 1032001f49Smrg setenv MESA_GAMMA 1.5 1.6 1.4 1132001f49Smrg Sets the red gamma value to 1.5, green to 1.6 and blue to 1.4. 1232001f49Smrg See the main README file for more information. 1332001f49Smrg 1432001f49Smrg For more info about gamma correction see: 1532001f49Smrg http://www.inforamp.net/~poynton/notes/colour_and_gamma/GammaFAQ.html 1632001f49Smrg 1732001f49Smrg This program is in the public domain 1832001f49Smrg 1932001f49Smrg Brian Paul 19 Oct 1995 2032001f49Smrg Kai Schuetz 05 Jun 1999 */ 2132001f49Smrg 2232001f49Smrg/* Conversion to GLUT by Mark J. Kilgard */ 2332001f49Smrg 2432001f49Smrg 2532001f49Smrg#include <stdio.h> 2632001f49Smrg#include <string.h> 2732001f49Smrg#include <stdlib.h> 2832001f49Smrg#include "glut_wrap.h" 2932001f49Smrg 3032001f49Smrgstatic void 3132001f49SmrgReshape(int width, int height) 3232001f49Smrg{ 3332001f49Smrg glViewport(0, 0, (GLint) width, (GLint) height); 3432001f49Smrg 3532001f49Smrg glMatrixMode(GL_PROJECTION); 3632001f49Smrg glLoadIdentity(); 3732001f49Smrg glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 3832001f49Smrg glMatrixMode(GL_MODELVIEW); 3932001f49Smrg glShadeModel(GL_FLAT); 4032001f49Smrg} 4132001f49Smrg 4232001f49Smrg/* ARGSUSED1 */ 4332001f49Smrgstatic void 4432001f49Smrgkey_esc(unsigned char key, int x, int y) 4532001f49Smrg{ 4632001f49Smrg if(key == 27) exit(0); /* Exit on Escape */ 4732001f49Smrg} 4832001f49Smrg 4932001f49Smrgstatic GLubyte p25[] = { 5032001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5132001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5232001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5332001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5432001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5532001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5632001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5732001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5832001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 5932001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 6032001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 6132001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 6232001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 6332001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 6432001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 6532001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 6632001f49Smrg}; 6732001f49Smrg 6832001f49Smrgstatic GLubyte p50[] = { 6932001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7032001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7132001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7232001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7332001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7432001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7532001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7632001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7732001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7832001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 7932001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 8032001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 8132001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 8232001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 8332001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 8432001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 8532001f49Smrg}; 8632001f49Smrg 8732001f49Smrgstatic GLubyte p75[] = { 8832001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 8932001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9032001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9132001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9232001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9332001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9432001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9532001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9632001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9732001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9832001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 9932001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 10032001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 10132001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 10232001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 10332001f49Smrg 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff, 10432001f49Smrg}; 10532001f49Smrg 10632001f49Smrgstatic GLubyte *stippletab[4] = {NULL, p25, p50, p75}; 10732001f49Smrg 10832001f49Smrgstatic void 10932001f49Smrggamma_ramp(GLfloat yoffs, GLfloat r, GLfloat g, GLfloat b) 11032001f49Smrg{ 11132001f49Smrg GLint d; 11232001f49Smrg 11332001f49Smrg glColor3f(0.0, 0.0, 0.0); /* solid black, no stipple */ 11432001f49Smrg glRectf(-1.0, yoffs, -0.6, yoffs + 0.5); 11532001f49Smrg 11632001f49Smrg for(d = 1; d < 4; d++) { /* increasing density from 25% to 75% */ 11732001f49Smrg GLfloat xcoord = (-1.0 + d*0.4); 11832001f49Smrg GLfloat t = d * 0.25; 11932001f49Smrg 12032001f49Smrg glColor3f(r*t, g*t, b*t); /* draw outer rect */ 12132001f49Smrg glRectf(xcoord, yoffs, xcoord+0.4, yoffs + 0.5); 12232001f49Smrg 12332001f49Smrg glColor3f(0.0, 0.0, 0.0); /* "clear" inner rect */ 12432001f49Smrg glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375); 12532001f49Smrg 12632001f49Smrg glColor3f(r, g, b); /* draw stippled inner rect */ 12732001f49Smrg glEnable(GL_POLYGON_STIPPLE); 12832001f49Smrg glPolygonStipple(stippletab[d]); 12932001f49Smrg glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375); 13032001f49Smrg glDisable(GL_POLYGON_STIPPLE); 13132001f49Smrg } 13232001f49Smrg glColor3f(r, g, b); /* solid color, no stipple */ 13332001f49Smrg glRectf(0.6, yoffs, 1.0, yoffs + 0.5); 13432001f49Smrg} 13532001f49Smrg 13632001f49Smrgstatic void 13732001f49Smrgdisplay(void) 13832001f49Smrg{ 13932001f49Smrg gamma_ramp( 0.5, 1.0, 1.0, 1.0); /* white ramp */ 14032001f49Smrg gamma_ramp( 0.0, 1.0, 0.0, 0.0); /* red ramp */ 14132001f49Smrg gamma_ramp(-0.5, 0.0, 1.0, 0.0); /* green ramp */ 14232001f49Smrg gamma_ramp(-1.0, 0.0, 0.0, 1.0); /* blue ramp */ 14332001f49Smrg glFlush(); 14432001f49Smrg} 14532001f49Smrg 14632001f49Smrgint 14732001f49Smrgmain(int argc, char **argv) 14832001f49Smrg{ 14932001f49Smrg glutInitWindowSize(500, 400); 15032001f49Smrg glutInit(&argc, argv); 15132001f49Smrg glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); 15232001f49Smrg glutCreateWindow("gamma test patterns"); 15332001f49Smrg glutReshapeFunc(Reshape); 15432001f49Smrg glutDisplayFunc(display); 15532001f49Smrg glutKeyboardFunc(key_esc); 15632001f49Smrg 15732001f49Smrg glutMainLoop(); 15832001f49Smrg return 0; /* ANSI C requires main to return int. */ 15932001f49Smrg} 160