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