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