2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
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.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
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
29 #include "glut_wrap.h"
36 char *texFileName
= 0;
39 float *minFilter
, *magFilter
, *sWrapMode
, *tWrapMode
;
40 float decal
[] = {GL_DECAL
};
41 float modulate
[] = {GL_MODULATE
};
42 float repeat
[] = {GL_REPEAT
};
43 float clamp
[] = {GL_CLAMP
};
44 float nr
[] = {GL_NEAREST
};
45 float ln
[] = {GL_LINEAR
};
46 float nr_mipmap_nr
[] = {GL_NEAREST_MIPMAP_NEAREST
};
47 float nr_mipmap_ln
[] = {GL_NEAREST_MIPMAP_LINEAR
};
48 float ln_mipmap_nr
[] = {GL_LINEAR_MIPMAP_NEAREST
};
49 float ln_mipmap_ln
[] = {GL_LINEAR_MIPMAP_LINEAR
};
50 GLint sphereMap
[] = {GL_SPHERE_MAP
};
52 GLenum doSphere
= GL_FALSE
;
53 float xRotation
= 0.0, yRotation
= 0.0, zTranslate
= -3.125;
142 static float n
[6][3] = {
162 static float t
[6][4][2] = {
249 static void BuildCube(void)
253 glNewList(cube
, GL_COMPILE
);
254 for (i
= 0; i
< 6; i
++) {
256 glNormal3fv(n
[i
]); glTexCoord2fv(t
[i
][0]); glVertex3fv(c
[i
][0]);
257 glNormal3fv(n
[i
]); glTexCoord2fv(t
[i
][1]); glVertex3fv(c
[i
][1]);
258 glNormal3fv(n
[i
]); glTexCoord2fv(t
[i
][2]); glVertex3fv(c
[i
][2]);
259 glNormal3fv(n
[i
]); glTexCoord2fv(t
[i
][3]); glVertex3fv(c
[i
][3]);
265 static void BuildLists(void)
268 cube
= glGenLists(1);
272 static void Init(void)
275 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
276 gluBuild2DMipmaps(GL_TEXTURE_2D
, 3, image
->sizeX
, image
->sizeY
,
277 GL_RGB
, GL_UNSIGNED_BYTE
, image
->data
);
278 glTexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, decal
);
279 glEnable(GL_TEXTURE_2D
);
282 glCullFace(GL_FRONT
);
283 glEnable(GL_CULL_FACE
);
287 glClearColor(0.0, 0.0, 0.0, 0.0);
295 static void Reshape(int width
, int height
)
298 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
300 glMatrixMode(GL_PROJECTION
);
302 gluPerspective(145.0, 1.0, 0.01, 1000);
303 glMatrixMode(GL_MODELVIEW
);
306 static void Key2(int key
, int x
, int y
)
329 static void Key(unsigned char key
, int x
, int y
)
344 doSphere
= !doSphere
;
346 glTexGeniv(GL_S
, GL_TEXTURE_GEN_MODE
, sphereMap
);
347 glTexGeniv(GL_T
, GL_TEXTURE_GEN_MODE
, sphereMap
);
348 glEnable(GL_TEXTURE_GEN_S
);
349 glEnable(GL_TEXTURE_GEN_T
);
351 glDisable(GL_TEXTURE_GEN_S
);
352 glDisable(GL_TEXTURE_GEN_T
);
369 minFilter
= nr_mipmap_nr
;
372 minFilter
= nr_mipmap_ln
;
375 minFilter
= ln_mipmap_nr
;
378 minFilter
= ln_mipmap_ln
;
387 static void Draw(void)
390 glClear(GL_COLOR_BUFFER_BIT
);
392 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, sWrapMode
);
393 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, tWrapMode
);
394 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, magFilter
);
395 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, minFilter
);
399 glTranslatef(0.0, 0.0, zTranslate
);
400 glRotatef(xRotation
, 1, 0, 0);
401 glRotatef(yRotation
, 0, 1, 0);
413 static GLenum
Args(int argc
, char **argv
)
417 doubleBuffer
= GL_FALSE
;
419 for (i
= 1; i
< argc
; i
++) {
420 if (strcmp(argv
[i
], "-sb") == 0) {
421 doubleBuffer
= GL_FALSE
;
422 } else if (strcmp(argv
[i
], "-db") == 0) {
423 doubleBuffer
= GL_TRUE
;
424 } else if (strcmp(argv
[i
], "-f") == 0) {
425 if (i
+1 >= argc
|| argv
[i
+1][0] == '-') {
426 printf("-f (No file name).\n");
429 texFileName
= argv
[++i
];
432 printf("%s (Bad option).\n", argv
[i
]);
439 int main(int argc
, char **argv
)
443 glutInit(&argc
, argv
);
445 if (Args(argc
, argv
) == GL_FALSE
) {
449 if (texFileName
== 0) {
450 printf("No image file.\n");
454 image
= LoadPPM(texFileName
);
456 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
459 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
460 glutInitDisplayMode(type
);
462 if (glutCreateWindow("Texture Test") == GL_FALSE
) {
468 glutReshapeFunc(Reshape
);
469 glutKeyboardFunc(Key
);
470 glutSpecialFunc(Key2
);
471 glutDisplayFunc(Draw
);