Fix bug 2034: replace printf by SDL_Log in tests; update loopwave VS solution: copy missing dependency
2 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
17 #include "SDL_test_common.h"
25 #include "SDL_opengl.h"
27 /* Undefine this if you want a flat cube instead of a rainbow cube */
30 static SDLTest_CommonState *state;
31 static SDL_GLContext context;
33 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
38 /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
39 SDL_GL_DeleteContext(context);
41 SDLTest_CommonQuit(state);
48 static float color[8][3] = {
58 static float cube[8][3] = {
69 /* Do our drawing, too. */
70 glClearColor(0.0, 0.0, 0.0, 1.0);
71 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
100 glColor3fv(color[1]);
101 glVertex3fv(cube[1]);
103 glColor3fv(color[5]);
104 glVertex3fv(cube[5]);
105 glColor3fv(color[4]);
106 glVertex3fv(cube[4]);
107 glColor3fv(color[7]);
108 glVertex3fv(cube[7]);
109 glColor3fv(color[6]);
110 glVertex3fv(cube[6]);
112 glColor3fv(color[5]);
113 glVertex3fv(cube[5]);
114 glColor3fv(color[0]);
115 glVertex3fv(cube[0]);
116 glColor3fv(color[3]);
117 glVertex3fv(cube[3]);
118 glColor3fv(color[4]);
119 glVertex3fv(cube[4]);
121 glColor3fv(color[6]);
122 glVertex3fv(cube[6]);
123 glColor3fv(color[1]);
124 glVertex3fv(cube[1]);
125 glColor3fv(color[2]);
126 glVertex3fv(cube[2]);
127 glColor3fv(color[7]);
128 glVertex3fv(cube[7]);
129 #else /* flat cube */
130 glColor3f(1.0, 0.0, 0.0);
131 glVertex3fv(cube[0]);
132 glVertex3fv(cube[1]);
133 glVertex3fv(cube[2]);
134 glVertex3fv(cube[3]);
136 glColor3f(0.0, 1.0, 0.0);
137 glVertex3fv(cube[3]);
138 glVertex3fv(cube[4]);
139 glVertex3fv(cube[7]);
140 glVertex3fv(cube[2]);
142 glColor3f(0.0, 0.0, 1.0);
143 glVertex3fv(cube[0]);
144 glVertex3fv(cube[5]);
145 glVertex3fv(cube[6]);
146 glVertex3fv(cube[1]);
148 glColor3f(0.0, 1.0, 1.0);
149 glVertex3fv(cube[5]);
150 glVertex3fv(cube[4]);
151 glVertex3fv(cube[7]);
152 glVertex3fv(cube[6]);
154 glColor3f(1.0, 1.0, 0.0);
155 glVertex3fv(cube[5]);
156 glVertex3fv(cube[0]);
157 glVertex3fv(cube[3]);
158 glVertex3fv(cube[4]);
160 glColor3f(1.0, 0.0, 1.0);
161 glVertex3fv(cube[6]);
162 glVertex3fv(cube[1]);
163 glVertex3fv(cube[2]);
164 glVertex3fv(cube[7]);
165 #endif /* SHADED_CUBE */
169 glMatrixMode(GL_MODELVIEW);
170 glRotatef(5.0, 1.0, 1.0, 1.0);
174 main(int argc, char *argv[])
179 SDL_DisplayMode mode;
181 Uint32 then, now, frames;
184 /* Enable standard application logging */
185 SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
187 /* Initialize parameters */
191 /* Initialize test framework */
192 state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
196 for (i = 1; i < argc;) {
199 consumed = SDLTest_CommonArg(state, i);
201 if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
202 fsaa = atoi(argv[i+1]);
204 } else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
205 accel = atoi(argv[i+1]);
212 SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
213 SDLTest_CommonUsage(state));
219 /* Set OpenGL parameters */
220 state->window_flags |= SDL_WINDOW_OPENGL;
221 state->gl_red_size = 5;
222 state->gl_green_size = 5;
223 state->gl_blue_size = 5;
224 state->gl_depth_size = 16;
225 state->gl_double_buffer = 1;
227 state->gl_multisamplebuffers = 1;
228 state->gl_multisamplesamples = fsaa;
231 state->gl_accelerated = accel;
234 if (!SDLTest_CommonInit(state)) {
238 /* Create OpenGL context */
239 context = SDL_GL_CreateContext(state->windows[0]);
241 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
245 if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
246 /* try late-swap-tearing first. If not supported, try normal vsync. */
247 if (SDL_GL_SetSwapInterval(-1) == -1) {
248 SDL_GL_SetSwapInterval(1);
251 SDL_GL_SetSwapInterval(0); /* disable vsync. */
254 SDL_GetCurrentDisplayMode(0, &mode);
255 SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format));
256 SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
258 SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
259 SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
260 SDL_Log("Version : %s\n", glGetString(GL_VERSION));
261 SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
264 status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
266 SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
268 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
270 status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
272 SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
274 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
276 status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
278 SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
280 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
282 status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
284 SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
286 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
289 status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
291 SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
293 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
296 status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
298 SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
301 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
306 status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
308 SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
311 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
316 /* Set rendering settings */
317 glMatrixMode(GL_PROJECTION);
319 glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
320 glMatrixMode(GL_MODELVIEW);
322 glEnable(GL_DEPTH_TEST);
323 glDepthFunc(GL_LESS);
324 glShadeModel(GL_SMOOTH);
326 /* Main render loop */
328 then = SDL_GetTicks();
331 /* Check for events */
333 while (SDL_PollEvent(&event)) {
334 SDLTest_CommonEvent(state, &event, &done);
336 for (i = 0; i < state->num_windows; ++i) {
338 SDL_GL_MakeCurrent(state->windows[i], context);
339 SDL_GetWindowSize(state->windows[i], &w, &h);
340 glViewport(0, 0, w, h);
342 SDL_GL_SwapWindow(state->windows[i]);
346 /* Print out some timing information */
347 now = SDL_GetTicks();
349 SDL_Log("%2.2f frames per second\n",
350 ((double) frames * 1000) / (now - then));
356 #else /* HAVE_OPENGL */
359 main(int argc, char *argv[])
361 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
365 #endif /* HAVE_OPENGL */