4b6c412f9e8105db0a9c61c8217a9b0e42021b8d
[mesa.git] / progs / trivial / long-fixed-func.c
1 /**
2 * Enable as much fixed-function vertex processing state as possible
3 * to test fixed-function -> program code generation.
4 */
5
6
7
8 #include <GL/glew.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <GL/glut.h>
13
14
15 static void
16 Reshape(int width, int height)
17 {
18 glViewport(0, 0, (GLint)width, (GLint)height);
19 glMatrixMode(GL_PROJECTION);
20 glLoadIdentity();
21 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
22 glMatrixMode(GL_MODELVIEW);
23 }
24
25
26 static void
27 Draw(void)
28 {
29 glClear(GL_COLOR_BUFFER_BIT);
30
31 glBegin(GL_TRIANGLES);
32 glColor3f(.8,0,0);
33 glVertex3f(-0.9, -0.9, -30.0);
34 glColor3f(0,.9,0);
35 glVertex3f( 0.9, -0.9, -30.0);
36 glColor3f(0,0,.7);
37 glVertex3f( 0.0, 0.9, -30.0);
38 glEnd();
39
40 glFlush();
41
42 glutSwapBuffers();
43 }
44
45
46 static void
47 Init(void)
48 {
49 GLubyte tex[16][16][4];
50 GLfloat pos[4] = {5, 10, 3, 1.0};
51 int i, j;
52
53 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
54 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
55 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
56 fflush(stderr);
57
58 glClearColor(0.3, 0.1, 0.3, 0.0);
59
60 for (i = 0; i < 16; i++) {
61 for (j = 0; j < 16; j++) {
62 if ((i+j) & 1) {
63 tex[i][j][0] = 100;
64 tex[i][j][1] = 100;
65 tex[i][j][2] = 100;
66 tex[i][j][3] = 255;
67 }
68 else {
69 tex[i][j][0] = 200;
70 tex[i][j][1] = 200;
71 tex[i][j][2] = 200;
72 tex[i][j][3] = 255;
73 }
74 }
75 }
76
77
78 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
79 glFogi(GL_FOG_MODE, GL_LINEAR);
80 glEnable(GL_FOG);
81
82 glPointParameterfv(GL_DISTANCE_ATTENUATION_EXT, pos);
83
84 for (i = 0; i < 8; i++) {
85 GLuint texObj;
86
87 glEnable(GL_LIGHT0 + i);
88 glLightf(GL_LIGHT0 + i, GL_SPOT_EXPONENT, 3.5);
89 glLightf(GL_LIGHT0 + i, GL_SPOT_CUTOFF, 30.);
90 glLightf(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 3.);
91 glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 3.);
92 glLightf(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 3.);
93 glLightfv(GL_LIGHT0 + i, GL_POSITION, pos);
94
95 glActiveTexture(GL_TEXTURE0 + i);
96 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
97 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
98 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
99 glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
100 glEnable(GL_TEXTURE_GEN_S);
101 glEnable(GL_TEXTURE_GEN_T);
102 glEnable(GL_TEXTURE_GEN_R);
103 glEnable(GL_TEXTURE_GEN_Q);
104 glEnable(GL_TEXTURE_2D);
105
106 glMatrixMode(GL_TEXTURE);
107 glScalef(2.0, 1.0, 3.0);
108
109 glGenTextures(1, &texObj);
110 glBindTexture(GL_TEXTURE_2D, texObj);
111 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0,
112 GL_RGBA, GL_UNSIGNED_BYTE, tex);
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
115 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
116 }
117
118 glEnable(GL_LIGHTING);
119 glActiveTexture(GL_TEXTURE0);
120 glMatrixMode(GL_MODELVIEW);
121 }
122
123
124 static void
125 Key(unsigned char key, int x, int y)
126 {
127 if (key == 27) {
128 exit(0);
129 }
130 glutPostRedisplay();
131 }
132
133
134 int
135 main(int argc, char **argv)
136 {
137 GLenum type = GLUT_RGB | GLUT_DOUBLE;
138
139 glutInit(&argc, argv);
140 glutInitWindowPosition(0, 0);
141 glutInitWindowSize( 250, 250);
142 glutInitDisplayMode(type);
143 if (glutCreateWindow(*argv) == GL_FALSE) {
144 exit(1);
145 }
146 glewInit();
147 glutReshapeFunc(Reshape);
148 glutKeyboardFunc(Key);
149 glutDisplayFunc(Draw);
150 Init();
151 glutMainLoop();
152 return 0;
153 }