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