ARB prog parser: fix parameter binding type
[mesa.git] / progs / trivial / pgon-mode.c
1 /**
2 * Test glPolygonMode.
3 * A tri-strip w/ two tris is drawn so that the first tri is front-facing
4 * but the second tri is back-facing.
5 * Set glPolygonMode differently for the front/back faces
6 *
7 */
8
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <math.h>
13 #include <GL/glut.h>
14
15 static int Win;
16 static GLfloat Zrot = 0;
17 static GLboolean FrontFillBackUnfilled = GL_TRUE;
18 static GLboolean Lines = GL_TRUE;
19
20
21 static void
22 Draw(void)
23 {
24 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
25
26 if (FrontFillBackUnfilled) {
27 if (Lines) {
28 printf("FrontMode = FILL, BackMode = LINE\n");
29 glPolygonMode(GL_BACK, GL_LINE);
30 }
31 else {
32 printf("FrontMode = FILL, BackMode = POINT\n");
33 glPolygonMode(GL_BACK, GL_POINT);
34 }
35 glPolygonMode(GL_FRONT, GL_FILL);
36 }
37 else {
38 if (Lines) {
39 printf("FrontMode = LINE, BackMode = FILL\n");
40 glPolygonMode(GL_FRONT, GL_LINE);
41 }
42 else {
43 printf("FrontMode = POINT, BackMode = FILL\n");
44 glPolygonMode(GL_FRONT, GL_POINT);
45 }
46 glPolygonMode(GL_BACK, GL_FILL);
47 }
48
49 glPushMatrix();
50 glRotatef(Zrot, 0, 0, 1);
51
52 glBegin(GL_TRIANGLE_STRIP);
53 glVertex2f(-1, 0);
54 glVertex2f( 1, 0);
55 glVertex2f(0, 1);
56 glVertex2f(0, -1);
57 glEnd();
58
59 glPopMatrix();
60
61 glutSwapBuffers();
62 }
63
64
65 static void
66 Reshape(int width, int height)
67 {
68 glViewport(0, 0, width, height);
69 glMatrixMode(GL_PROJECTION);
70 glLoadIdentity();
71 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
72 glMatrixMode(GL_MODELVIEW);
73 glLoadIdentity();
74 glTranslatef(0.0, 0.0, -15.0);
75 }
76
77
78 static void
79 Key(unsigned char key, int x, int y)
80 {
81 const GLfloat step = 3.0;
82 (void) x;
83 (void) y;
84 switch (key) {
85 case 'p':
86 FrontFillBackUnfilled = !FrontFillBackUnfilled;
87 break;
88 case 'l':
89 Lines = !Lines;
90 break;
91 case 'z':
92 Zrot -= step;
93 break;
94 case 'Z':
95 Zrot += step;
96 break;
97 case 27:
98 glutDestroyWindow(Win);
99 exit(0);
100 break;
101 }
102 glutPostRedisplay();
103 }
104
105
106 static void
107 Init(void)
108 {
109 printf("GL_RENDERER = %s\n", (char*) glGetString(GL_RENDERER));
110
111 glLineWidth(3.0);
112 glPointSize(3.0);
113
114 glColor4f(1, 1, 1, 0.8);
115 glEnable(GL_BLEND);
116 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
117
118 printf("Press 'p' to toggle polygon mode\n");
119 }
120
121
122 int
123 main(int argc, char *argv[])
124 {
125 glutInit(&argc, argv);
126 glutInitWindowPosition(0, 0);
127 glutInitWindowSize(400, 400);
128 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
129 Win = glutCreateWindow(argv[0]);
130 glutReshapeFunc(Reshape);
131 glutKeyboardFunc(Key);
132 glutDisplayFunc(Draw);
133 Init();
134 glutMainLoop();
135 return 0;
136 }