annotate test/testgl.c @ 234:1af4be6a73cd

Modified the logo texture load to accept any width/height image
author Sam Lantinga <slouken@libsdl.org>
date Tue, 06 Nov 2001 01:48:36 +0000
parents 5b42a7f5fab3
children cf4944faad96
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
3 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4 #include <math.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 #include "SDL.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 #ifdef HAVE_OPENGL
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
9
214
0e5d6dd77bda Added platform independent OpenGL header - SDL_opengl.h
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
10 #include "SDL_opengl.h"
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
12 /* Undefine this if you want a flat cube instead of a rainbow cube */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 #define SHADED_CUBE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
15 /* Define this to be the name of the logo image to use with -logo */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
16 #define LOGO_FILE "icon.bmp"
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
17
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
18 /* The SDL_OPENGLBLIT interface is deprecated.
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
19 The code is still available for benchmark purposes though.
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
20 */
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
21 static SDL_bool USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
23 /**********************************************************************/
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
24
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 void HotKey_ToggleFullScreen(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 SDL_Surface *screen;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 screen = SDL_GetVideoSurface();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 if ( SDL_WM_ToggleFullScreen(screen) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 printf("Toggled fullscreen mode - now %s\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 printf("Unable to toggle fullscreen mode\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 void HotKey_ToggleGrab(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 SDL_GrabMode mode;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 printf("Ctrl-G: toggling input grab!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 if ( mode == SDL_GRAB_ON ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 printf("Grab was on\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 printf("Grab was off\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 mode = SDL_WM_GrabInput(!mode);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 if ( mode == SDL_GRAB_ON ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
51 printf("Grab is now on\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 printf("Grab is now off\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
54 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 void HotKey_Iconify(void)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 printf("Ctrl-Z: iconifying window!\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 SDL_WM_IconifyWindow();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 int HandleEvent(SDL_Event *event)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 int done;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 done = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 switch( event->type ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 case SDL_ACTIVEEVENT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 /* See what happened */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 printf( "app %s ", event->active.gain ? "gained" : "lost" );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 if ( event->active.state & SDL_APPACTIVE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 printf( "active " );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
74 } else if ( event->active.state & SDL_APPMOUSEFOCUS ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 printf( "mouse " );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 } else if ( event->active.state & SDL_APPINPUTFOCUS ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 printf( "input " );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 printf( "focus\n" );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 case SDL_KEYDOWN:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84 if ( event->key.keysym.sym == SDLK_ESCAPE ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
85 done = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
86 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 if ( (event->key.keysym.sym == SDLK_g) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
88 (event->key.keysym.mod & KMOD_CTRL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
89 HotKey_ToggleGrab();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
91 if ( (event->key.keysym.sym == SDLK_z) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92 (event->key.keysym.mod & KMOD_CTRL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 HotKey_Iconify();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 if ( (event->key.keysym.sym == SDLK_RETURN) &&
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 (event->key.keysym.mod & KMOD_ALT) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 HotKey_ToggleFullScreen();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 printf("key '%s' pressed\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 SDL_GetKeyName(event->key.keysym.sym));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
102 case SDL_QUIT:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
103 done = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
104 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
105 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 return(done);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
109 void SDL_GL_Enter2DMode()
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
110 {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
111 SDL_Surface *screen = SDL_GetVideoSurface();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
112
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
113 /* Note, there may be other things you need to change,
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
114 depending on how you have your OpenGL state set up.
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
115 */
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
116 glPushAttrib(GL_ENABLE_BIT);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
117 glDisable(GL_DEPTH_TEST);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
118 glDisable(GL_CULL_FACE);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
119 glEnable(GL_TEXTURE_2D);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
120
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
121 glViewport(0, 0, screen->w, screen->h);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
122
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
123 glMatrixMode(GL_PROJECTION);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
124 glPushMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
125 glLoadIdentity();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
126
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
127 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
128
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
129 glMatrixMode(GL_MODELVIEW);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
130 glPushMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
131 glLoadIdentity();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
132
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
133 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
134 }
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
135
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
136 void SDL_GL_Leave2DMode()
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
137 {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
138 glMatrixMode(GL_MODELVIEW);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
139 glPopMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
140
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
141 glMatrixMode(GL_PROJECTION);
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
142 glPopMatrix();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
143
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
144 glPopAttrib();
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
145 }
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
146
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
147 /* Quick utility function for texture creation */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
148 static int power_of_two(int input)
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
149 {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
150 int value = 1;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
151
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
152 while ( value < input ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
153 value <<= 1;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
154 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
155 return value;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
156 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
157
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
158 GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
159 {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
160 GLuint texture;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
161 int w, h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
162 SDL_Surface *image;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
163 SDL_Rect area;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
164 Uint32 saved_flags;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
165 Uint8 saved_alpha;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
166
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
167 /* Use the surface width and height expanded to powers of 2 */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
168 w = power_of_two(surface->w);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
169 h = power_of_two(surface->h);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
170 texcoord[0] = 0.0f; /* Min X */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
171 texcoord[1] = 0.0f; /* Min Y */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
172 texcoord[2] = (GLfloat)surface->w / w; /* Max X */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
173 texcoord[3] = (GLfloat)surface->h / h; /* Max Y */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
174
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
175 image = SDL_CreateRGBSurface(
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
176 SDL_SWSURFACE,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
177 w, h,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
178 32,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
179 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
180 0x000000FF,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
181 0x0000FF00,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
182 0x00FF0000,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
183 0xFF000000
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
184 #else
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
185 0xFF000000,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
186 0x00FF0000,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
187 0x0000FF00,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
188 0x000000FF
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
189 #endif
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
190 );
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
191 if ( image == NULL ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
192 return 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
193 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
194
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
195 /* Save the alpha blending attributes */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
196 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
197 saved_alpha = surface->format->alpha;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
198 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
199 SDL_SetAlpha(surface, 0, 0);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
200 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
201
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
202 /* Copy the surface into the GL texture image */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
203 area.x = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
204 area.y = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
205 area.w = surface->w;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
206 area.h = surface->h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
207 SDL_BlitSurface(surface, &area, image, &area);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
208
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
209 /* Restore the alpha blending attributes */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
210 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
211 SDL_SetAlpha(surface, saved_flags, saved_alpha);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
212 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
213
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
214 /* Create an OpenGL texture for the image */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
215 glGenTextures(1, &texture);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
216 glBindTexture(GL_TEXTURE_2D, texture);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
217 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
218 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
219 glTexImage2D(GL_TEXTURE_2D,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
220 0,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
221 GL_RGBA,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
222 w, h,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
223 0,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
224 GL_RGBA,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
225 GL_UNSIGNED_BYTE,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
226 image->pixels);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
227 SDL_FreeSurface(image); /* No longer needed */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
228
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
229 return texture;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
230 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
231
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
232 void DrawLogoTexture(void)
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
233 {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
234 static GLuint texture;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
235 static GLfloat texMinX, texMinY;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
236 static GLfloat texMaxX, texMaxY;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
237 static int x = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
238 static int y = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
239 static int w, h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
240 static int delta_x = 1;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
241 static int delta_y = 1;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
242 static Uint32 last_moved = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
243
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
244 SDL_Surface *screen = SDL_GetVideoSurface();
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
245
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
246 if ( ! texture ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
247 SDL_Surface *image;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
248 GLfloat texcoord[4];
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
249
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
250 /* Load the image (could use SDL_image library here) */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
251 image = SDL_LoadBMP(LOGO_FILE);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
252 if ( image == NULL ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
253 return;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
254 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
255 w = image->w;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
256 h = image->h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
257
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
258 /* Convert the image into an OpenGL texture */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
259 texture = SDL_GL_LoadTexture(image, texcoord);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
260
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
261 /* Make texture coordinates easy to understand */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
262 texMinX = texcoord[0];
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
263 texMinY = texcoord[1];
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
264 texMaxX = texcoord[2];
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
265 texMaxY = texcoord[3];
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
266
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
267 /* We don't need the original image anymore */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
268 SDL_FreeSurface(image);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
269
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
270 /* Make sure that the texture conversion is okay */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
271 if ( ! texture ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
272 return;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
273 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
274 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
275
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
276 /* Move the image around */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
277 x += delta_x;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
278 if ( x < 0 ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
279 x = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
280 delta_x = -delta_x;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
281 } else
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
282 if ( (x+w) > screen->w ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
283 x = screen->w-w;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
284 delta_x = -delta_x;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
285 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
286 y += delta_y;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
287 if ( y < 0 ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
288 y = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
289 delta_y = -delta_y;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
290 } else
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
291 if ( (y+h) > screen->h ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
292 y = screen->h-h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
293 delta_y = -delta_y;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
294 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
295
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
296 /* Show the image on the screen */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
297 SDL_GL_Enter2DMode();
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
298 glBindTexture(GL_TEXTURE_2D, texture);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
299 glBegin(GL_TRIANGLE_STRIP);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
300 glTexCoord2f(texMinX, texMinY); glVertex2i(x, y );
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
301 glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y );
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
302 glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
303 glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
304 glEnd();
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
305 SDL_GL_Leave2DMode();
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
306 }
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
307
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
308 /* This code is deprecated, but available for speed comparisons */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
309 void DrawLogoBlit(void)
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 static SDL_Surface *image = NULL;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
312 static GLuint texture;
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
313 static GLfloat texMinX, texMinY;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
314 static GLfloat texMaxX, texMaxY;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
315 static int x = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
316 static int y = 0;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
317 static int w, h;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318 static int delta_x = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 static int delta_y = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
320 static Uint32 last_moved = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 SDL_Rect dst;
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
323 SDL_Surface *screen = SDL_GetVideoSurface();
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 if ( image == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326 SDL_Surface *temp;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
328 /* Load the image (could use SDL_image library here) */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
329 temp = SDL_LoadBMP(LOGO_FILE);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 if ( temp == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
331 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 }
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
333 w = temp->w;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
334 h = temp->h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
335
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
336 /* Convert the image into the screen format */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
337 image = SDL_CreateRGBSurface(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
338 SDL_SWSURFACE,
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
339 w, h,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
340 screen->format->BitsPerPixel,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
341 screen->format->Rmask,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
342 screen->format->Gmask,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
343 screen->format->Bmask,
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
344 screen->format->Amask);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
345 if ( image ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 SDL_BlitSurface(temp, NULL, image, NULL);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
348 SDL_FreeSurface(temp);
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
349
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
350 /* Make sure that the texture conversion is okay */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
351 if ( ! image ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
352 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
353 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
356 /* Move the image around
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 Note that we do not clear the old position. This is because we
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 perform a glClear() which clears the framebuffer and then only
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 update the new area.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 Note that you can also achieve interesting effects by modifying
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 the screen surface alpha channel. It's set to 255 by default..
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 */
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
363 x += delta_x;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
364 if ( x < 0 ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
365 x = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
366 delta_x = -delta_x;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
367 } else
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
368 if ( (x+w) > screen->w ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
369 x = screen->w-w;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
370 delta_x = -delta_x;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 }
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
372 y += delta_y;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
373 if ( y < 0 ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
374 y = 0;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
375 delta_y = -delta_y;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
376 } else
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
377 if ( (y+h) > screen->h ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
378 y = screen->h-h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
379 delta_y = -delta_y;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
380 }
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
381 dst.x = x;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
382 dst.y = y;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
383 dst.w = w;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
384 dst.h = h;
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
385 SDL_BlitSurface(image, NULL, screen, &dst);
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
386
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
387 /* Show the image on the screen */
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
388 SDL_UpdateRects(screen, 1, &dst);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
391 int RunGLTest( int argc, char* argv[],
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 int logo, int slowly, int bpp, float gamma )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 int i;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 int rgb_size[3];
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396 int w = 640;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 int h = 480;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 int done = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399 int frames;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
400 Uint32 start_time, this_time;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 float color[8][3]= {{ 1.0, 1.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
402 { 1.0, 0.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403 { 0.0, 0.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 { 0.0, 1.0, 0.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 { 0.0, 1.0, 1.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406 { 1.0, 1.0, 1.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 { 1.0, 0.0, 1.0},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 { 0.0, 0.0, 1.0}};
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 float cube[8][3]= {{ 0.5, 0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 { 0.5, -0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 {-0.5, -0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 {-0.5, 0.5, -0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413 {-0.5, 0.5, 0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
414 { 0.5, 0.5, 0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
415 { 0.5, -0.5, 0.5},
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
416 {-0.5, -0.5, 0.5}};
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
417 Uint32 video_flags;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
418 int value;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
419
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
420 if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
421 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
422 exit( 1 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
423 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
424
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
425 /* See if we should detect the display depth */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
426 if ( bpp == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
427 if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428 bpp = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
429 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
430 bpp = 16; /* More doesn't seem to work */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
431 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
432 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
433
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434 /* Set the flags we want to use for setting the video mode */
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
435 if ( logo && USE_DEPRECATED_OPENGLBLIT ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
436 video_flags = SDL_OPENGLBLIT;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
437 } else {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
438 video_flags = SDL_OPENGL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
439 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
440 for ( i=1; argv[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
441 if ( strcmp(argv[1], "-fullscreen") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
442 video_flags |= SDL_FULLSCREEN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
443 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
444 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
445
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
446 /* Initialize the display */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
447 switch (bpp) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
448 case 8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449 rgb_size[0] = 2;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
450 rgb_size[1] = 3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
451 rgb_size[2] = 3;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
452 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
453 case 15:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
454 case 16:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
455 rgb_size[0] = 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
456 rgb_size[1] = 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
457 rgb_size[2] = 5;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
458 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
460 rgb_size[0] = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
461 rgb_size[1] = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
462 rgb_size[2] = 8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
463 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
464 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
465 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
466 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
467 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
468 SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
469 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
470 if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
471 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
472 SDL_Quit();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
473 exit(1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
474 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
475
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
476 printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
477 printf("\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
478 printf( "Vendor : %s\n", glGetString( GL_VENDOR ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
479 printf( "Renderer : %s\n", glGetString( GL_RENDERER ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
480 printf( "Version : %s\n", glGetString( GL_VERSION ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
481 printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
482 printf("\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
483
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
484 SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
485 printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
486 SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
487 printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488 SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
489 printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
490 SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
491 printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
492 SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
493 printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
494
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
495 /* Set the window manager title bar */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
496 SDL_WM_SetCaption( "SDL GL test", "testgl" );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
497
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
498 /* Set the gamma for the window */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
499 if ( gamma != 0.0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
500 SDL_SetGamma(gamma, gamma, gamma);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
501 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
502
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
503 glViewport( 0, 0, w, h );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
504 glMatrixMode( GL_PROJECTION );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
505 glLoadIdentity( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
506
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
507 glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
508
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
509 glMatrixMode( GL_MODELVIEW );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
510 glLoadIdentity( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
511
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
512 glEnable(GL_DEPTH_TEST);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
513
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
514 glDepthFunc(GL_LESS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
515
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
516 glShadeModel(GL_SMOOTH);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
517
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
518 /* Loop until done. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
519 start_time = SDL_GetTicks();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
520 frames = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
521 while( !done ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
522 GLenum gl_error;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
523 char* sdl_error;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
524 SDL_Event event;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
525
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
526 /* Do our drawing, too. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
527 glClearColor( 0.0, 0.0, 0.0, 1.0 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
528 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
529
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
530 glBegin( GL_QUADS );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
531
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
532 #ifdef SHADED_CUBE
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
533 glColor3fv(color[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
534 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
535 glColor3fv(color[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
536 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
537 glColor3fv(color[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
538 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
539 glColor3fv(color[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
540 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
541
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
542 glColor3fv(color[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
543 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
544 glColor3fv(color[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
545 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
546 glColor3fv(color[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
547 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
548 glColor3fv(color[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
549 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
550
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
551 glColor3fv(color[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
552 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
553 glColor3fv(color[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
554 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
555 glColor3fv(color[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
556 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
557 glColor3fv(color[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
558 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
559
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
560 glColor3fv(color[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
561 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
562 glColor3fv(color[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
563 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
564 glColor3fv(color[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
565 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
566 glColor3fv(color[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
567 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
568
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
569 glColor3fv(color[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
570 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
571 glColor3fv(color[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
572 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
573 glColor3fv(color[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
574 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
575 glColor3fv(color[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
576 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
577
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
578 glColor3fv(color[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
579 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
580 glColor3fv(color[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
581 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
582 glColor3fv(color[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
583 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
584 glColor3fv(color[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
585 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
586 #else // flat cube
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
587 glColor3f(1.0, 0.0, 0.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
588 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
589 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
590 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
591 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
592
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
593 glColor3f(0.0, 1.0, 0.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
594 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
595 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
596 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
597 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
598
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
599 glColor3f(0.0, 0.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
600 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
601 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
602 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
603 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
604
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
605 glColor3f(0.0, 1.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
606 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
607 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
608 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
609 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
610
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
611 glColor3f(1.0, 1.0, 0.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
612 glVertex3fv(cube[5]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
613 glVertex3fv(cube[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
614 glVertex3fv(cube[3]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
615 glVertex3fv(cube[4]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
616
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
617 glColor3f(1.0, 0.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
618 glVertex3fv(cube[6]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
619 glVertex3fv(cube[1]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
620 glVertex3fv(cube[2]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
621 glVertex3fv(cube[7]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
622 #endif /* SHADED_CUBE */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
623
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
624 glEnd( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
625
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
626 glMatrixMode(GL_MODELVIEW);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
627 glRotatef(5.0, 1.0, 1.0, 1.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
628
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
629 /* Draw 2D logo onto the 3D display */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
630 if ( logo ) {
234
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
631 if ( USE_DEPRECATED_OPENGLBLIT ) {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
632 DrawLogoBlit();
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
633 } else {
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
634 DrawLogoTexture();
1af4be6a73cd Modified the logo texture load to accept any width/height image
Sam Lantinga <slouken@libsdl.org>
parents: 233
diff changeset
635 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
636 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
637
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
638 SDL_GL_SwapBuffers( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
639
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
640 /* Check for error conditions. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
641 gl_error = glGetError( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
642
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
643 if( gl_error != GL_NO_ERROR ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
644 fprintf( stderr, "testgl: OpenGL error: %d\n", gl_error );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
645 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
646
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
647 sdl_error = SDL_GetError( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
648
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
649 if( sdl_error[0] != '\0' ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
650 fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
651 SDL_ClearError();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
652 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
653
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
654 /* Allow the user to see what's happening */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
655 if ( slowly ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
656 SDL_Delay( 20 );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
657 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
658
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
659 /* Check if there's a pending event. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
660 while( SDL_PollEvent( &event ) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
661 done = HandleEvent(&event);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
662 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
663 ++frames;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
664 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
665
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
666 /* Print out the frames per second */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
667 this_time = SDL_GetTicks();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
668 if ( this_time != start_time ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
669 printf("%2.2f FPS\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
670 ((float)frames/(this_time-start_time))*1000.0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
671 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
672
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
673 /* Destroy our GL context, etc. */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
674 SDL_Quit( );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
675 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
676 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
677
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
678 int main(int argc, char *argv[])
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
679 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
680 int i, logo;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
681 int numtests;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
682 int bpp = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
683 int slowly;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
684 float gamma = 0.0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
685
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
686 logo = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
687 slowly = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
688 numtests = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
689 for ( i=1; argv[i]; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
690 if ( strcmp(argv[i], "-twice") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
691 ++numtests;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
692 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
693 if ( strcmp(argv[i], "-logo") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
694 logo = 1;
233
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
695 USE_DEPRECATED_OPENGLBLIT = SDL_FALSE;
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
696 }
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
697 if ( strcmp(argv[i], "-logoblit") == 0 ) {
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
698 logo = 1;
5b42a7f5fab3 SDL_OPENGLBLIT is deprecated, show the "right way" of doing things
Sam Lantinga <slouken@libsdl.org>
parents: 221
diff changeset
699 USE_DEPRECATED_OPENGLBLIT = SDL_TRUE;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
700 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
701 if ( strcmp(argv[i], "-slow") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
702 slowly = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
703 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
704 if ( strcmp(argv[i], "-bpp") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
705 bpp = atoi(argv[++i]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
706 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
707 if ( strcmp(argv[i], "-gamma") == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
708 gamma = (float)atof(argv[++i]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
709 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
710 if ( strncmp(argv[i], "-h", 2) == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
711 printf(
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
712 "Usage: %s [-twice] [-logo] [-slow] [-bpp n] [-gamma n]\n",
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
713 argv[0]);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
714 exit(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
715 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
716 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
717 for ( i=0; i<numtests; ++i ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
718 RunGLTest(argc, argv, logo, slowly, bpp, gamma);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
719 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
720 return 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
721 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
722
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
723 #else /* HAVE_OPENGL */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
724
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
725 int main(int argc, char *argv[])
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
726 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
727 printf("No OpenGL support on this system\n");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
728 return 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
729 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
730
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
731 #endif /* HAVE_OPENGL */