]> git.cworth.org Git - apitrace-tests/blob - apps/gl/tri.c
Add --exact, --no-deps, or --no-prune to trim tests as needed
[apitrace-tests] / apps / gl / tri.c
1 /*
2  * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that (i) the above copyright notices and this permission notice appear in
7  * all copies of the software and related documentation, and (ii) the name of
8  * Silicon Graphics may not be used in any advertising or
9  * publicity relating to the software without the specific, prior written
10  * permission of Silicon Graphics.
11  *
12  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13  * ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24
25
26 #ifdef _WIN32
27 #include <windows.h>
28 #endif
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33
34 #ifdef __APPLE__
35 #  include <GLUT/glut.h>
36 #else
37 #  include <GL/glut.h>
38 #endif
39
40
41 static GLboolean doubleBuffer = GL_TRUE;
42 static int win;
43
44
45 static void parseArgs(int argc, char** argv)
46 {
47    int i;
48
49    for (i = 1; i < argc; ++i) {
50       const char *arg = argv[i];
51       if (strcmp(arg, "-sb") == 0) {
52          doubleBuffer = GL_FALSE;
53       } else if (strcmp(arg, "-db") == 0) {
54          doubleBuffer = GL_TRUE;
55       } else {
56          fprintf(stderr, "error: unknown arg %s\n", arg);
57          exit(1);
58       }
59    }
60 }
61
62
63 static void
64 Init(void)
65 {
66    glClearColor(0.3f, 0.1f, 0.3f, 1.0f);
67 }
68
69
70 static void
71 Reshape(int width, int height)
72 {
73    glViewport(0, 0, width, height);
74    glMatrixMode(GL_PROJECTION);
75    glLoadIdentity();
76    glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
77    glMatrixMode(GL_MODELVIEW);
78 }
79
80
81 static void
82 Draw(void)
83 {
84    glClear(GL_COLOR_BUFFER_BIT); 
85
86    glBegin(GL_TRIANGLES);
87    glColor3f(.8, 0, 0); 
88    glVertex3f(-0.9, -0.9, -30.0);
89    glColor3f(0, .9, 0); 
90    glVertex3f( 0.9, -0.9, -30.0);
91    glColor3f(0, 0, .7); 
92    glVertex3f( 0.0,  0.9, -30.0);
93    glEnd();
94
95    glFlush();
96
97    if (doubleBuffer) {
98       glutSwapBuffers();
99    }
100
101    glutDestroyWindow(win);
102
103    exit(0);
104 }
105
106
107 int
108 main(int argc, char **argv)
109 {
110    GLenum type;
111
112    parseArgs(argc, argv);
113
114    glutInit(&argc, argv);
115
116    glutInitWindowSize(250, 250);
117
118    type = GLUT_RGB | GLUT_ALPHA;
119    type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
120    glutInitDisplayMode(type);
121
122    win = glutCreateWindow(*argv);
123    if (!win) {
124       exit(1);
125    }
126
127    Init();
128
129    glutReshapeFunc(Reshape);
130    glutDisplayFunc(Draw);
131    glutMainLoop();
132    return 0;
133 }