Merge commit 'origin/gallium-master-merge'
[mesa.git] / progs / trivial / tri-repeat.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 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <math.h>
29 #include <GL/glut.h>
30
31
32 #define CI_OFFSET_1 16
33 #define CI_OFFSET_2 32
34
35
36 static void Init(void)
37 {
38 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
39 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
40 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
41
42 glClearColor(0.3, 0.1, 0.3, 0.0);
43 }
44
45 static void Reshape(int width, int height)
46 {
47
48 glViewport(0, 0, (GLint)width, (GLint)height);
49
50 glMatrixMode(GL_PROJECTION);
51 glLoadIdentity();
52 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
53 glMatrixMode(GL_MODELVIEW);
54 }
55
56 static void Key(unsigned char key, int x, int y)
57 {
58 switch (key) {
59 case 27:
60 exit(0);
61 default:
62 glutPostRedisplay();
63 return;
64 }
65 }
66
67 static void Draw(void)
68 {
69 static float f = 0;
70 f += .1;
71 glClear(GL_COLOR_BUFFER_BIT);
72
73 glBegin(GL_TRIANGLES);
74 glColor3f((sin(f)+1)/2.0,0,0);
75 glVertex3f(-0.9, -0.9, -30.0);
76 glColor3f(0,(cos(f)+1)/2.0,0);
77 glVertex3f( 0.9, -0.9, -30.0);
78 glColor3f(0,0,.7);
79 glVertex3f( 0.0, 0.9, -30.0);
80 glEnd();
81
82 glutSwapBuffers();
83 glutPostRedisplay();
84 }
85
86 static GLenum Args(int argc, char **argv)
87 {
88 return GL_TRUE;
89 }
90
91 int main(int argc, char **argv)
92 {
93 GLenum type;
94
95 glutInit(&argc, argv);
96
97 if (Args(argc, argv) == GL_FALSE) {
98 exit(1);
99 }
100
101 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
102
103 type = GLUT_RGB | GLUT_ALPHA;
104 type |= GLUT_DOUBLE;
105 glutInitDisplayMode(type);
106
107 if (glutCreateWindow("First Tri") == GL_FALSE) {
108 exit(1);
109 }
110
111 Init();
112
113 glutReshapeFunc(Reshape);
114 glutKeyboardFunc(Key);
115 glutDisplayFunc(Draw);
116 glutMainLoop();
117 return 0;
118 }