blob: a7c92ce20d17b0bd2ec2bb82ad6d9db592a61931 [file] [log] [blame]
Jakob Bornecrantz87bcb322009-03-18 17:15:40 +01001/*
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 <GL/glew.h>
29#include <GL/glut.h>
30
31
32#define CI_OFFSET_1 16
33#define CI_OFFSET_2 32
34
35#define SIZE 16
36GLenum doubleBuffer;
37GLint line = 0;
38
39static void MakeImage()
40{
41 GLubyte tex2d[SIZE][SIZE][3];
42 GLint s, t;
43
44 for (s = 0; s < SIZE; s++) {
45 for (t = 0; t < SIZE; t++) {
46 tex2d[s][t][0] = s*255/(SIZE-1);
47 tex2d[s][t][1] = t*255/(SIZE-1);
48 tex2d[s][t][2] = 0*255/(SIZE-1);
49 }
50 }
51
52 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
53 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
54 SIZE, SIZE,
55 0,
56 GL_RGB, GL_UNSIGNED_BYTE, tex2d);
57 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
58 glEnable(GL_TEXTURE_2D);
59}
60
61static void UpdateLine()
62{
63 GLubyte tex[SIZE][3];
64 GLint s, t;
65
66 t = line % SIZE;
67
68 for (s = 0; s < SIZE; s++) {
69 tex[s][0] = s*255/(SIZE-1);
70 tex[s][1] = t*255/(SIZE-1);
71 tex[s][2] = 255;
72 }
73
74 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
75 glTexSubImage2D(GL_TEXTURE_2D, 0,
76 0, t,
77 SIZE, 1,
78 GL_RGB, GL_UNSIGNED_BYTE, tex);
79 glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
80}
81
82static void Init(void)
83{
84 fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
85 fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
86 fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
87
88 glClearColor(0.0, 0.0, 1.0, 0.0);
89
90 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
91 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
92 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
93 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
94 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
95
96 MakeImage();
97 UpdateLine();
98 line++;
99}
100
101static void Reshape(int width, int height)
102{
103
104 glViewport(0, 0, (GLint)width, (GLint)height);
105
106 glMatrixMode(GL_PROJECTION);
107 glLoadIdentity();
108 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
109 glMatrixMode(GL_MODELVIEW);
110}
111
112static void Key(unsigned char key, int x, int y)
113{
114
115 switch (key) {
116 case 27:
117 exit(1);
118 default:
119 UpdateLine();
120 line++;
121 break;
122 }
123
124 glutPostRedisplay();
125}
126
127static void Draw(void)
128{
129 glClear(GL_COLOR_BUFFER_BIT);
130
131 glBegin(GL_QUADS);
132 glTexCoord2f(1,0);
133 glVertex3f( 0.9, -0.9, -30.0);
134 glTexCoord2f(1,1);
135 glVertex3f( 0.9, 0.9, -30.0);
136 glTexCoord2f(0,1);
137 glVertex3f(-0.9, 0.9, -30.0);
138 glTexCoord2f(0,0);
139 glVertex3f(-0.9, -0.9, -30.0);
140 glEnd();
141
142 glFlush();
143
144 if (doubleBuffer) {
145 glutSwapBuffers();
146 }
147}
148
149static GLenum Args(int argc, char **argv)
150{
151 GLint i;
152
153 doubleBuffer = GL_FALSE;
154
155 for (i = 1; i < argc; i++) {
156 if (strcmp(argv[i], "-sb") == 0) {
157 doubleBuffer = GL_FALSE;
158 } else if (strcmp(argv[i], "-db") == 0) {
159 doubleBuffer = GL_TRUE;
160 } else {
161 fprintf(stderr, "%s (Bad option).\n", argv[i]);
162 return GL_FALSE;
163 }
164 }
165 return GL_TRUE;
166}
167
168int main(int argc, char **argv)
169{
170 GLenum type;
171
172 glutInit(&argc, argv);
173
174 if (Args(argc, argv) == GL_FALSE) {
175 exit(1);
176 }
177
178 glutInitWindowPosition(0, 0);
179 glutInitWindowSize(250, 250);
180
181 type = GLUT_RGB | GLUT_ALPHA;
182 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
183 glutInitDisplayMode(type);
184
185 if (glutCreateWindow(*argv) == GL_FALSE) {
186 exit(1);
187 }
188
189 glewInit();
190
191 Init();
192
193 glutReshapeFunc(Reshape);
194 glutKeyboardFunc(Key);
195 glutDisplayFunc(Draw);
196 glutMainLoop();
197 return 0;
198}