Merge commit 'origin/master' into gallium-0.2
[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 #define GL_GLEXT_PROTOTYPES
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
57 glClearColor(0.3, 0.1, 0.3, 0.0);
58
59 for (i = 0; i < 16; i++) {
60 for (j = 0; j < 16; j++) {
61 if ((i+j) & 1) {
62 tex[i][j][0] = 100;
63 tex[i][j][1] = 100;
64 tex[i][j][2] = 100;
65 tex[i][j][3] = 255;
66 }
67 else {
68 tex[i][j][0] = 200;
69 tex[i][j][1] = 200;
70 tex[i][j][2] = 200;
71 tex[i][j][3] = 255;
72 }
73 }
74 }
75
76
77 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
78 glFogi(GL_FOG_MODE, GL_LINEAR);
79 glEnable(GL_FOG);
80
81 glPointParameterfv(GL_DISTANCE_ATTENUATION_EXT, pos);
82
83 for (i = 0; i < 8; i++) {
84 GLuint texObj;
85
86 glEnable(GL_LIGHT0 + i);
87 glLightf(GL_LIGHT0 + i, GL_SPOT_EXPONENT, 3.5);
88 glLightf(GL_LIGHT0 + i, GL_SPOT_CUTOFF, 30.);
89 glLightf(GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 3.);
90 glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 3.);
91 glLightf(GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 3.);
92 glLightfv(GL_LIGHT0 + i, GL_POSITION, pos);
93
94 glActiveTexture(GL_TEXTURE0 + i);
95 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
96 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
97 glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
98 glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
99 glEnable(GL_TEXTURE_GEN_S);
100 glEnable(GL_TEXTURE_GEN_T);
101 glEnable(GL_TEXTURE_GEN_R);
102 glEnable(GL_TEXTURE_GEN_Q);
103 glEnable(GL_TEXTURE_2D);
104
105 glMatrixMode(GL_TEXTURE);
106 glScalef(2.0, 1.0, 3.0);
107
108 glGenTextures(1, &texObj);
109 glBindTexture(GL_TEXTURE_2D, texObj);
110 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0,
111 GL_RGBA, GL_UNSIGNED_BYTE, tex);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
114 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
115 }
116
117 glEnable(GL_LIGHTING);
118 glActiveTexture(GL_TEXTURE0);
119 glMatrixMode(GL_MODELVIEW);
120 }
121
122
123 static void
124 Key(unsigned char key, int x, int y)
125 {
126 if (key == 27) {
127 exit(0);
128 }
129 glutPostRedisplay();
130 }
131
132
133 int
134 main(int argc, char **argv)
135 {
136 GLenum type = GLUT_RGB | GLUT_DOUBLE;
137
138 glutInit(&argc, argv);
139 glutInitWindowPosition(0, 0);
140 glutInitWindowSize( 250, 250);
141 glutInitDisplayMode(type);
142 if (glutCreateWindow("tri-long-fixedfunc") == GL_FALSE) {
143 exit(1);
144 }
145 glutReshapeFunc(Reshape);
146 glutKeyboardFunc(Key);
147 glutDisplayFunc(Draw);
148 Init();
149 glutMainLoop();
150 return 0;
151 }