blob: 517d584e21210f16843a7eda252c4f15fe3f0c29 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +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 <GL/glut.h>
29
30
31#define OPENGL_WIDTH 24
32#define OPENGL_HEIGHT 13
33
34
35GLenum rgb, doubleBuffer, windType;
36
37float boxA[3] = {
38 0, 0, 0
39};
40float boxB[3] = {
41 -100, 0, 0
42};
43float boxC[3] = {
44 100, 0, 0
45};
46float boxD[3] = {
47 0, 95, 0
48};
49float boxE[3] = {
50 0, -105, 0
51};
52GLubyte OpenGL_bits1[] = {
53 0x00, 0x03, 0x00,
54 0x7f, 0xfb, 0xff,
55 0x7f, 0xfb, 0xff,
56 0x00, 0x03, 0x00,
57 0x3e, 0x8f, 0xb7,
58 0x63, 0xdb, 0xb0,
59 0x63, 0xdb, 0xb7,
60 0x63, 0xdb, 0xb6,
61 0x63, 0x8f, 0xf3,
62 0x63, 0x00, 0x00,
63 0x63, 0x00, 0x00,
64 0x63, 0x00, 0x00,
65 0x3e, 0x00, 0x00,
66};
67GLubyte OpenGL_bits2[] = {
68 0x00, 0x00, 0x00,
69 0xff, 0xff, 0x01,
70 0xff, 0xff, 0x01,
71 0x00, 0x00, 0x00,
72 0xf9, 0xfc, 0x01,
73 0x8d, 0x0d, 0x00,
74 0x8d, 0x0d, 0x00,
75 0x8d, 0x0d, 0x00,
76 0xcc, 0x0d, 0x00,
77 0x0c, 0x4c, 0x0a,
78 0x0c, 0x4c, 0x0e,
79 0x8c, 0xed, 0x0e,
80 0xf8, 0x0c, 0x00,
81};
82GLubyte logo_bits[] = {
83 0x00, 0x66, 0x66,
84 0xff, 0x66, 0x66,
85 0x00, 0x00, 0x00,
86 0xff, 0x3c, 0x3c,
87 0x00, 0x42, 0x40,
88 0xff, 0x42, 0x40,
89 0x00, 0x41, 0x40,
90 0xff, 0x21, 0x20,
91 0x00, 0x2f, 0x20,
92 0xff, 0x20, 0x20,
93 0x00, 0x10, 0x90,
94 0xff, 0x10, 0x90,
95 0x00, 0x0f, 0x10,
96 0xff, 0x00, 0x00,
97 0x00, 0x66, 0x66,
98 0xff, 0x66, 0x66,
99};
100
101#include "tkmap.c"
102
103static void Init(void)
104{
105
106 glClearColor(0.0, 0.0, 0.0, 0.0);
107 glClearIndex(0.0);
108}
109
110static void Reshape(int width, int height)
111{
112
113 glViewport(0, 0, (GLint)width, (GLint)height);
114
115 glMatrixMode(GL_PROJECTION);
116 glLoadIdentity();
117 gluOrtho2D(-175, 175, -175, 175);
118 glMatrixMode(GL_MODELVIEW);
119}
120
121static void Key(unsigned char key, int x, int y)
122{
123
124 switch (key) {
125 case 27:
126 exit(1);
127 }
128}
129
130static void Draw(void)
131{
132 float mapI[2], mapIA[2], mapIR[2];
133
134 glClear(GL_COLOR_BUFFER_BIT);
135
136 mapI[0] = 0.0;
137 mapI[1] = 1.0;
138 mapIR[0] = 0.0;
139 mapIR[1] = 0.0;
140 mapIA[0] = 1.0;
141 mapIA[1] = 1.0;
142
143 glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, mapIR);
144 glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, mapI);
145 glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, mapI);
146 glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, mapIA);
147 glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
148
149 SetColor(COLOR_WHITE);
150 glRasterPos3fv(boxA);
151 glPixelStorei(GL_UNPACK_ROW_LENGTH, 24);
152 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 8);
153 glPixelStorei(GL_UNPACK_SKIP_ROWS, 2);
154 glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
155 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
156 glBitmap(16, 12, 8.0, 0.0, 0.0, 0.0, logo_bits);
157
158 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
159 glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
160 glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
161 glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
162 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
163
164 SetColor(COLOR_WHITE);
165 glRasterPos3fv(boxB);
166 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
167 OpenGL_bits1);
168 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
169 OpenGL_bits2);
170
171 SetColor(COLOR_YELLOW);
172 glRasterPos3fv(boxC);
173 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
174 OpenGL_bits1);
175 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
176 OpenGL_bits2);
177
178 SetColor(COLOR_CYAN);
179 glRasterPos3fv(boxD);
180 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
181 OpenGL_bits1);
182 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
183 OpenGL_bits2);
184
185 SetColor(COLOR_RED);
186 glRasterPos3fv(boxE);
187 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
188 OpenGL_bits1);
189 glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
190 OpenGL_bits2);
191
192 glFlush();
193
194 if (doubleBuffer) {
195 glutSwapBuffers();
196 }
197}
198
199static GLenum Args(int argc, char **argv)
200{
201 GLint i;
202
203 rgb = GL_TRUE;
204 doubleBuffer = GL_FALSE;
205
206 for (i = 1; i < argc; i++) {
207 if (strcmp(argv[i], "-ci") == 0) {
208 rgb = GL_FALSE;
209 } else if (strcmp(argv[i], "-rgb") == 0) {
210 rgb = GL_TRUE;
211 } else if (strcmp(argv[i], "-sb") == 0) {
212 doubleBuffer = GL_FALSE;
213 } else if (strcmp(argv[i], "-db") == 0) {
214 doubleBuffer = GL_TRUE;
215 } else {
216 printf("%s (Bad option).\n", argv[i]);
217 return GL_FALSE;
218 }
219 }
220 return GL_TRUE;
221}
222
223int main(int argc, char **argv)
224{
225 glutInit(&argc, argv);
226
227 if (Args(argc, argv) == GL_FALSE) {
228 exit(1);
229 }
230
231 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
232
233 windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
234 windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
235 glutInitDisplayMode(windType);
236
237 if (glutCreateWindow("Bitmap Test") == GL_FALSE) {
238 exit(1);
239 }
240
241 InitMap();
242
243 Init();
244
245 glutReshapeFunc(Reshape);
246 glutKeyboardFunc(Key);
247 glutDisplayFunc(Draw);
248 glutMainLoop();
249 return 0;
250}