demos: add missing binaries to .gitignore
[mesa-demos.git] / src / tests / seccolor.c
blob1c549f4e4d9a7fe0b91170693336601f9137dbdb
1 /*
2 * Exercise GL_EXT_secondary_color
3 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <math.h>
9 #include <GL/glew.h>
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 )
19 GLfloat t;
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;
26 GLfloat g = t;
28 /* top row: untextured */
29 glColor3f(1, 0, 0);
30 glPushMatrix();
31 glTranslatef(x, 1.2, 0);
32 #if defined(GL_EXT_secondary_color)
33 glSecondaryColor3fEXT(0, g, 0);
34 #endif
35 glBegin(GL_POLYGON);
36 glVertex2f(-1, -1);
37 glVertex2f( 1, -1);
38 glVertex2f( 1, 1);
39 glVertex2f(-1, 1);
40 glEnd();
41 glPopMatrix();
43 /* bottom row: textured */
44 glColor3f(1, 1, 1);
45 glEnable(GL_TEXTURE_2D);
46 glPushMatrix();
47 glTranslatef(x, -1.2, 0);
48 #if defined(GL_EXT_secondary_color)
49 glSecondaryColor3fEXT(0, g, 0);
50 #endif
51 glBegin(GL_POLYGON);
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);
56 glEnd();
57 glPopMatrix();
58 glDisable(GL_TEXTURE_2D);
60 glutSwapBuffers();
64 static void Reshape( int width, int height )
66 GLfloat ar = (float) width / (float) height;
67 Width = width;
68 Height = height;
69 glViewport( 0, 0, width, height );
70 glMatrixMode( GL_PROJECTION );
71 glLoadIdentity();
72 glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
73 glMatrixMode( GL_MODELVIEW );
74 glLoadIdentity();
75 glTranslatef( 0.0, 0.0, -15.0 );
79 static void Key( unsigned char key, int x, int y )
81 (void) x;
82 (void) y;
83 switch (key) {
84 case 27:
85 exit(0);
86 break;
88 glutPostRedisplay();
92 static void Init( void )
94 GLubyte image[4*4][3];
95 GLint i;
96 if (!glutExtensionSupported("GL_EXT_secondary_color")) {
97 printf("Sorry, this program requires GL_EXT_secondary_color\n");
98 exit(1);
101 /* setup red texture with one back texel */
102 for (i = 0; i < 4*4; i++) {
103 if (i == 0) {
104 image[i][0] = 0;
105 image[i][1] = 0;
106 image[i][2] = 0;
108 else {
109 image[i][0] = 255;
110 image[i][1] = 0;
111 image[i][2] = 0;
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);
122 #endif
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]);
139 glewInit();
140 glutReshapeFunc( Reshape );
141 glutKeyboardFunc( Key );
142 glutDisplayFunc( Display );
143 Init();
144 glutMainLoop();
145 return 0;