Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* $Id: gamma.c,v 1.2 2000/03/18 01:13:29 brianp Exp $ */
  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. You can set Mesa's gamma values (for red, green and blue) with the
  7. MESA_GAMMA environment variable. But only on X windows!
  8. For example:
  9. setenv MESA_GAMMA 1.5 1.6 1.4
  10. Sets the red gamma value to 1.5, green to 1.6 and blue to 1.4.
  11. See the main README file for more information.
  12. For more info about gamma correction see:
  13. http://www.inforamp.net/~poynton/notes/colour_and_gamma/GammaFAQ.html
  14. This program is in the public domain
  15. Brian Paul 19 Oct 1995
  16. Kai Schuetz 05 Jun 1999 */
  17. /* Conversion to GLUT by Mark J. Kilgard */
  18. /*
  19. * $Log: gamma.c,v $
  20. * Revision 1.2 2000/03/18 01:13:29 brianp
  21. * colors were computed incorrectly (Hans Nelles)
  22. *
  23. * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
  24. * Imported sources
  25. *
  26. * Revision 3.1 1999/06/19 01:35:38 brianp
  27. * merged in Kai Schuetz's RGB changes
  28. *
  29. * Revision 3.0 1998/02/14 18:42:29 brianp
  30. * initial rev
  31. *
  32. */
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include <stdlib.h>
  36. #include <GL/glut.h>
  37. static void
  38. Reshape(int width, int height)
  39. {
  40. glViewport(0, 0, (GLint) width, (GLint) height);
  41. glMatrixMode(GL_PROJECTION);
  42. glLoadIdentity();
  43. glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  44. glMatrixMode(GL_MODELVIEW);
  45. glShadeModel(GL_FLAT);
  46. }
  47. /* ARGSUSED1 */
  48. static void
  49. key_esc(unsigned char key, int x, int y)
  50. {
  51. if(key == 27) exit(0); /* Exit on Escape */
  52. }
  53. static GLubyte p25[] = {
  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. 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. };
  71. static GLubyte p50[] = {
  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. 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. };
  89. static GLubyte p75[] = {
  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. 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
  105. 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff,
  106. };
  107. static GLubyte *stippletab[4] = {NULL, p25, p50, p75};
  108. static void
  109. gamma_ramp(GLfloat yoffs, GLfloat r, GLfloat g, GLfloat b)
  110. {
  111. GLint d;
  112. glColor3f(0.0, 0.0, 0.0); /* solid black, no stipple */
  113. glRectf(-1.0, yoffs, -0.6, yoffs + 0.5);
  114. for(d = 1; d < 4; d++) { /* increasing density from 25% to 75% */
  115. GLfloat xcoord = (-1.0 + d*0.4);
  116. GLfloat t = d * 0.25;
  117. glColor3f(r*t, g*t, b*t); /* draw outer rect */
  118. glRectf(xcoord, yoffs, xcoord+0.4, yoffs + 0.5);
  119. glColor3f(0.0, 0.0, 0.0); /* "clear" inner rect */
  120. glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375);
  121. glColor3f(r, g, b); /* draw stippled inner rect */
  122. glEnable(GL_POLYGON_STIPPLE);
  123. glPolygonStipple(stippletab[d]);
  124. glRectf(xcoord + 0.1, yoffs + 0.125, xcoord + 0.3, yoffs + 0.375);
  125. glDisable(GL_POLYGON_STIPPLE);
  126. }
  127. glColor3f(r, g, b); /* solid color, no stipple */
  128. glRectf(0.6, yoffs, 1.0, yoffs + 0.5);
  129. }
  130. static void
  131. display(void)
  132. {
  133. gamma_ramp( 0.5, 1.0, 1.0, 1.0); /* white ramp */
  134. gamma_ramp( 0.0, 1.0, 0.0, 0.0); /* red ramp */
  135. gamma_ramp(-0.5, 0.0, 1.0, 0.0); /* green ramp */
  136. gamma_ramp(-1.0, 0.0, 0.0, 1.0); /* blue ramp */
  137. glFlush();
  138. }
  139. int
  140. main(int argc, char **argv)
  141. {
  142. glutInit(&argc, argv);
  143. glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
  144. glutInitWindowPosition(50, 50);
  145. glutInitWindowSize(500, 400);
  146. glutCreateWindow("gamma test patterns");
  147. glutReshapeFunc(Reshape);
  148. glutDisplayFunc(display);
  149. glutKeyboardFunc(key_esc);
  150. glutMainLoop();
  151. return 0; /* ANSI C requires main to return int. */
  152. }