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.

seccolor.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Exercise GL_EXT_secondary_color
  3. */
  4. #define GL_GLEXT_PROTOTYPES
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <GL/glut.h>
  9. static int Width = 600;
  10. static int Height = 200;
  11. static GLfloat Near = 5.0, Far = 25.0;
  12. static void Display( void )
  13. {
  14. GLfloat t;
  15. glClearColor(0.2, 0.2, 0.8, 0);
  16. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  17. for (t = 0.0; t <= 1.0; t += 0.25) {
  18. GLfloat x = t * 10.0 - 5.0;
  19. GLfloat g = t;
  20. /* top row: untextured */
  21. glColor3f(1, 0, 0);
  22. glPushMatrix();
  23. glTranslatef(x, 1.2, 0);
  24. #if defined(GL_EXT_secondary_color)
  25. glSecondaryColor3fEXT(0, g, 0);
  26. #endif
  27. glBegin(GL_POLYGON);
  28. glVertex2f(-1, -1);
  29. glVertex2f( 1, -1);
  30. glVertex2f( 1, 1);
  31. glVertex2f(-1, 1);
  32. glEnd();
  33. glPopMatrix();
  34. /* bottom row: textured */
  35. glColor3f(1, 1, 1);
  36. glEnable(GL_TEXTURE_2D);
  37. glPushMatrix();
  38. glTranslatef(x, -1.2, 0);
  39. #if defined(GL_EXT_secondary_color)
  40. glSecondaryColor3fEXT(0, g, 0);
  41. #endif
  42. glBegin(GL_POLYGON);
  43. glTexCoord2f(0, 0); glVertex2f(-1, -1);
  44. glTexCoord2f(1, 0); glVertex2f( 1, -1);
  45. glTexCoord2f(1, 1); glVertex2f( 1, 1);
  46. glTexCoord2f(0, 1); glVertex2f(-1, 1);
  47. glEnd();
  48. glPopMatrix();
  49. glDisable(GL_TEXTURE_2D);
  50. }
  51. glutSwapBuffers();
  52. }
  53. static void Reshape( int width, int height )
  54. {
  55. GLfloat ar = (float) width / (float) height;
  56. Width = width;
  57. Height = height;
  58. glViewport( 0, 0, width, height );
  59. glMatrixMode( GL_PROJECTION );
  60. glLoadIdentity();
  61. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  62. glMatrixMode( GL_MODELVIEW );
  63. glLoadIdentity();
  64. glTranslatef( 0.0, 0.0, -15.0 );
  65. }
  66. static void Key( unsigned char key, int x, int y )
  67. {
  68. (void) x;
  69. (void) y;
  70. switch (key) {
  71. case 27:
  72. exit(0);
  73. break;
  74. }
  75. glutPostRedisplay();
  76. }
  77. static void Init( void )
  78. {
  79. GLubyte image[4*4][3];
  80. GLint i;
  81. if (!glutExtensionSupported("GL_EXT_secondary_color")) {
  82. printf("Sorry, this program requires GL_EXT_secondary_color\n");
  83. exit(1);
  84. }
  85. /* setup red texture with one back texel */
  86. for (i = 0; i < 4*4; i++) {
  87. if (i == 0) {
  88. image[i][0] = 0;
  89. image[i][1] = 0;
  90. image[i][2] = 0;
  91. }
  92. else {
  93. image[i][0] = 255;
  94. image[i][1] = 0;
  95. image[i][2] = 0;
  96. }
  97. }
  98. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0,
  99. GL_RGB, GL_UNSIGNED_BYTE, image);
  100. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  101. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  102. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  103. #if defined(GL_EXT_secondary_color)
  104. glEnable(GL_COLOR_SUM_EXT);
  105. #endif
  106. glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
  107. printf("Squares should be colored from red -> orange -> yellow.\n");
  108. printf("Top row is untextured.\n");
  109. printf("Bottom row is textured (red texture with one black texel).\n");
  110. printf("Rows should be identical, except for lower-left texel.\n");
  111. }
  112. int main( int argc, char *argv[] )
  113. {
  114. glutInit( &argc, argv );
  115. glutInitWindowPosition( 0, 0 );
  116. glutInitWindowSize( Width, Height );
  117. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  118. glutCreateWindow(argv[0]);
  119. glutReshapeFunc( Reshape );
  120. glutKeyboardFunc( Key );
  121. glutDisplayFunc( Display );
  122. Init();
  123. glutMainLoop();
  124. return 0;
  125. }