Merge branch 'mesa_7_7_branch'
[mesa.git] / progs / trivial / tri-point-line-clipped.c
1 /**
2 * Test frustum/user clipping w/ glPolygonMode LINE/POINT.
3 *
4 * The bottom/left and bottom/right verts are outside the frustum and clipped.
5 * The top vertex is clipped by a user clipping plane.
6 *
7 * A filled gray reference triangle is shown underneath the points/lines.
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <GL/glut.h>
13
14
15 static int win;
16
17
18 static void
19 ColorTri(void)
20 {
21 glBegin(GL_TRIANGLES);
22 glColor3f(1, 0, 0); glVertex3f(-1.5, -0.8, 0.0);
23 glColor3f(0, 1, 0); glVertex3f( 1.5, -0.8, 0.0);
24 glColor3f(0, 0, 1); glVertex3f( 0.0, 0.9, 0.0);
25 glEnd();
26 }
27
28
29 static void
30 GrayTri(void)
31 {
32 glColor3f(0.3, 0.3, 0.3);
33 glBegin(GL_TRIANGLES);
34 glVertex3f(-1.5, -0.8, 0.0);
35 glVertex3f( 1.5, -0.8, 0.0);
36 glVertex3f( 0.0, 0.9, 0.0);
37 glEnd();
38 }
39
40
41 static void
42 Draw(void)
43 {
44 static const GLdouble plane[4] = { 0, -1.0, 0, 0.5 };
45
46 glClear(GL_COLOR_BUFFER_BIT);
47
48 glPointSize(13.0);
49 glLineWidth(5.0);
50
51 glClipPlane(GL_CLIP_PLANE0, plane);
52 glEnable(GL_CLIP_PLANE0);
53
54 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
55 GrayTri();
56
57 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
58 ColorTri();
59
60 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
61 ColorTri();
62
63 glutSwapBuffers();
64 }
65
66
67 static void Reshape(int width, int height)
68 {
69 glViewport(0, 0, (GLint)width, (GLint)height);
70 glMatrixMode(GL_PROJECTION);
71 glLoadIdentity();
72 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
73 glMatrixMode(GL_MODELVIEW);
74 }
75
76
77 static void
78 Key(unsigned char key, int x, int y)
79 {
80 if (key == 27) {
81 glutDestroyWindow(win);
82 exit(0);
83 }
84 else {
85 glutPostRedisplay();
86 }
87 }
88
89
90 static void
91 Init(void)
92 {
93 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
94 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
95 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
96 fflush(stderr);
97 }
98
99
100 int
101 main(int argc, char **argv)
102 {
103 glutInitWindowSize(300, 300);
104 glutInit(&argc, argv);
105 glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
106 win = glutCreateWindow(*argv);
107 if (!win) {
108 return 1;
109 }
110 Init();
111 glutReshapeFunc(Reshape);
112 glutKeyboardFunc(Key);
113 glutDisplayFunc(Draw);
114 glutMainLoop();
115 return 0;
116 }