2 * Exercise GL_EXT_secondary_color
10 #include "glut_wrap.h"
12 static int Width
= 600;
13 static int Height
= 200;
14 static GLfloat Near
= 5.0, Far
= 25.0;
17 static void Display( void )
21 glClearColor(0.2, 0.2, 0.8, 0);
22 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
24 for (t
= 0.0; t
<= 1.0; t
+= 0.25) {
25 GLfloat x
= t
* 10.0 - 5.0;
28 /* top row: untextured */
31 glTranslatef(x
, 1.2, 0);
32 #if defined(GL_EXT_secondary_color)
33 glSecondaryColor3fEXT(0, g
, 0);
43 /* bottom row: textured */
45 glEnable(GL_TEXTURE_2D
);
47 glTranslatef(x
, -1.2, 0);
48 #if defined(GL_EXT_secondary_color)
49 glSecondaryColor3fEXT(0, g
, 0);
52 glTexCoord2f(0, 0); glVertex2f(-1, -1);
53 glTexCoord2f(1, 0); glVertex2f( 1, -1);
54 glTexCoord2f(1, 1); glVertex2f( 1, 1);
55 glTexCoord2f(0, 1); glVertex2f(-1, 1);
58 glDisable(GL_TEXTURE_2D
);
64 static void Reshape( int width
, int height
)
66 GLfloat ar
= (float) width
/ (float) height
;
69 glViewport( 0, 0, width
, height
);
70 glMatrixMode( GL_PROJECTION
);
72 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
73 glMatrixMode( GL_MODELVIEW
);
75 glTranslatef( 0.0, 0.0, -15.0 );
79 static void Key( unsigned char key
, int x
, int y
)
92 static void Init( void )
94 GLubyte image
[4*4][3];
96 if (!glutExtensionSupported("GL_EXT_secondary_color")) {
97 printf("Sorry, this program requires GL_EXT_secondary_color\n");
101 /* setup red texture with one back texel */
102 for (i
= 0; i
< 4*4; i
++) {
114 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 4, 4, 0,
115 GL_RGB
, GL_UNSIGNED_BYTE
, image
);
116 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
117 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
118 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_MODULATE
);
120 #if defined(GL_EXT_secondary_color)
121 glEnable(GL_COLOR_SUM_EXT
);
123 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL
, GL_SEPARATE_SPECULAR_COLOR
);
125 printf("Squares should be colored from red -> orange -> yellow.\n");
126 printf("Top row is untextured.\n");
127 printf("Bottom row is textured (red texture with one black texel).\n");
128 printf("Rows should be identical, except for lower-left texel.\n");
132 int main( int argc
, char *argv
[] )
134 glutInit( &argc
, argv
);
135 glutInitWindowPosition( 0, 0 );
136 glutInitWindowSize( Width
, Height
);
137 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
138 glutCreateWindow(argv
[0]);
140 glutReshapeFunc( Reshape
);
141 glutKeyboardFunc( Key
);
142 glutDisplayFunc( Display
);