Mercurial > sdl-ios-xcode
comparison test/testgles.c @ 3139:7f684f249ec9
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 23 May 2009 22:41:08 +0000 |
parents | e6c21c14ce3a |
children | c18c03927a77 |
comparison
equal
deleted
inserted
replaced
3125:d71d8ceda8b3 | 3139:7f684f249ec9 |
---|---|
12 #ifdef HAVE_OPENGLES | 12 #ifdef HAVE_OPENGLES |
13 | 13 |
14 #include "SDL_opengles.h" | 14 #include "SDL_opengles.h" |
15 | 15 |
16 static CommonState *state; | 16 static CommonState *state; |
17 static SDL_GLContext *context=NULL; | 17 static SDL_GLContext *context = NULL; |
18 | 18 |
19 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 19 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
20 static void | 20 static void |
21 quit(int rc) | 21 quit(int rc) |
22 { | 22 { |
23 int i; | 23 int i; |
24 | 24 |
25 if (context!=NULL) | 25 if (context != NULL) { |
26 { | 26 for (i = 0; i < state->num_windows; i++) { |
27 for (i=0; i<state->num_windows; i++) | |
28 { | |
29 if (context[i]) { | 27 if (context[i]) { |
30 SDL_GL_DeleteContext(context[i]); | 28 SDL_GL_DeleteContext(context[i]); |
31 } | 29 } |
32 } | 30 } |
33 | 31 |
147 } | 145 } |
148 if (!CommonInit(state)) { | 146 if (!CommonInit(state)) { |
149 quit(2); | 147 quit(2); |
150 } | 148 } |
151 | 149 |
152 context=SDL_calloc(state->num_windows, sizeof(SDL_GLContext)); | 150 context = SDL_calloc(state->num_windows, sizeof(SDL_GLContext)); |
153 if (context==NULL) | 151 if (context == NULL) { |
154 { | 152 fprintf(stderr, "Out of memory!\n"); |
155 fprintf(stderr, "Out of memory!\n"); | 153 quit(2); |
156 quit(2); | |
157 } | 154 } |
158 | 155 |
159 /* Create OpenGL ES contexts */ | 156 /* Create OpenGL ES contexts */ |
160 for (i=0; i<state->num_windows; i++) | 157 for (i = 0; i < state->num_windows; i++) { |
161 { | |
162 context[i] = SDL_GL_CreateContext(state->windows[i]); | 158 context[i] = SDL_GL_CreateContext(state->windows[i]); |
163 if (!context[i]) { | 159 if (!context[i]) { |
164 fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); | 160 fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); |
165 quit(2); | 161 quit(2); |
166 } | 162 } |
179 printf("Renderer : %s\n", glGetString(GL_RENDERER)); | 175 printf("Renderer : %s\n", glGetString(GL_RENDERER)); |
180 printf("Version : %s\n", glGetString(GL_VERSION)); | 176 printf("Version : %s\n", glGetString(GL_VERSION)); |
181 printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); | 177 printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); |
182 printf("\n"); | 178 printf("\n"); |
183 | 179 |
184 status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); | 180 status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); |
185 if (!status) { | 181 if (!status) { |
186 printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); | 182 printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); |
187 } else { | 183 } else { |
188 fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); | 184 fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", |
189 } | 185 SDL_GetError()); |
190 status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); | 186 } |
187 status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); | |
191 if (!status) { | 188 if (!status) { |
192 printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); | 189 printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); |
193 } else { | 190 } else { |
194 fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); | 191 fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", |
195 } | 192 SDL_GetError()); |
196 status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); | 193 } |
194 status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); | |
197 if (!status) { | 195 if (!status) { |
198 printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); | 196 printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); |
199 } else { | 197 } else { |
200 fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); | 198 fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", |
201 } | 199 SDL_GetError()); |
202 status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); | 200 } |
201 status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); | |
203 if (!status) { | 202 if (!status) { |
204 printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); | 203 printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); |
205 } else { | 204 } else { |
206 fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); | 205 fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", |
206 SDL_GetError()); | |
207 } | 207 } |
208 if (fsaa) { | 208 if (fsaa) { |
209 status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); | 209 status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); |
210 if (!status) { | 210 if (!status) { |
211 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); | 211 printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); |
212 } else { | 212 } else { |
213 fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); | 213 fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", |
214 } | 214 SDL_GetError()); |
215 status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); | 215 } |
216 status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); | |
216 if (!status) { | 217 if (!status) { |
217 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); | 218 printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, |
219 value); | |
218 } else { | 220 } else { |
219 fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); | 221 fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", |
222 SDL_GetError()); | |
220 } | 223 } |
221 } | 224 } |
222 if (accel) { | 225 if (accel) { |
223 status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); | 226 status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); |
224 if (!status) | 227 if (!status) { |
225 { | |
226 printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); | 228 printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); |
227 } else { | 229 } else { |
228 fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); | 230 fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", |
231 SDL_GetError()); | |
229 } | 232 } |
230 } | 233 } |
231 | 234 |
232 /* Set rendering settings for each context */ | 235 /* Set rendering settings for each context */ |
233 for (i = 0; i < state->num_windows; ++i) { | 236 for (i = 0; i < state->num_windows; ++i) { |
234 status=SDL_GL_MakeCurrent(state->windows[i], context[i]); | 237 status = SDL_GL_MakeCurrent(state->windows[i], context[i]); |
235 if (status) | 238 if (status) { |
236 { | |
237 printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); | 239 printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); |
238 | 240 |
239 /* Continue for next window */ | 241 /* Continue for next window */ |
240 continue; | 242 continue; |
241 } | 243 } |
260 while (SDL_PollEvent(&event)) { | 262 while (SDL_PollEvent(&event)) { |
261 CommonEvent(state, &event, &done); | 263 CommonEvent(state, &event, &done); |
262 } | 264 } |
263 for (i = 0; i < state->num_windows; ++i) { | 265 for (i = 0; i < state->num_windows; ++i) { |
264 int w, h; | 266 int w, h; |
265 status=SDL_GL_MakeCurrent(state->windows[i], context[i]); | 267 status = SDL_GL_MakeCurrent(state->windows[i], context[i]); |
266 if (status) | 268 if (status) { |
267 { | 269 printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); |
268 printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); | 270 |
269 | 271 /* Continue for next window */ |
270 /* Continue for next window */ | 272 continue; |
271 continue; | |
272 } | 273 } |
273 SDL_GetWindowSize(state->windows[i], &w, &h); | 274 SDL_GetWindowSize(state->windows[i], &w, &h); |
274 glViewport(0, 0, w, h); | 275 glViewport(0, 0, w, h); |
275 Render(); | 276 Render(); |
276 SDL_GL_SwapWindow(state->windows[i]); | 277 SDL_GL_SwapWindow(state->windows[i]); |