blob: 9c618d492f34a70fb9bc80a12dd2e770aa7d6237 [file] [log] [blame]
Keith Whitwelld04caf22008-11-05 11:31:57 +00001/*
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
36static 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
45static 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
56static 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
67static void Draw(void)
68{
69 static float f = 0;
70 while (1) {
71 f += .1;
72 glClearColor((sin(f)+1)/2.0,(cos(f)+1)/2.0,0.5,1);
73 glClear(GL_COLOR_BUFFER_BIT);
74 glutSwapBuffers();
Keith Whitwell59311fb2009-03-04 17:41:46 +000075
76 {
77 static GLint T0 = 0;
78 static GLint Frames = 0;
79 GLint t = glutGet(GLUT_ELAPSED_TIME);
80
81 Frames++;
82
83 if (t - T0 >= 5000) {
84 GLfloat seconds = (t - T0) / 1000.0;
85 GLfloat fps = Frames / seconds;
86 printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps);
87 fflush(stdout);
88 T0 = t;
89 Frames = 0;
90 }
91 }
92
Keith Whitwelld04caf22008-11-05 11:31:57 +000093 }
94 glutPostRedisplay();
95}
96
97static GLenum Args(int argc, char **argv)
98{
99 return GL_TRUE;
100}
101
102int main(int argc, char **argv)
103{
104 GLenum type;
105
106 glutInit(&argc, argv);
107
108 if (Args(argc, argv) == GL_FALSE) {
109 exit(1);
110 }
111
Keith Whitwell59311fb2009-03-04 17:41:46 +0000112 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
Keith Whitwelld04caf22008-11-05 11:31:57 +0000113
114 type = GLUT_RGB | GLUT_ALPHA;
115 type |= GLUT_DOUBLE;
116 glutInitDisplayMode(type);
117
Keith Whitwelldefd52f2009-02-18 18:20:50 +0000118 if (glutCreateWindow(*argv) == GL_FALSE) {
Keith Whitwelld04caf22008-11-05 11:31:57 +0000119 exit(1);
120 }
121
122 Init();
123
124 glutReshapeFunc(Reshape);
125 glutKeyboardFunc(Key);
126 glutDisplayFunc(Draw);
127 glutMainLoop();
128 return 0;
129}