14
#include <SDL3/SDL_test_common.h>
15
#include <SDL3/SDL_main.h>
17
#if defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_ANDROID)
23
#include <SDL3/SDL_opengles.h>
25
static SDLTest_CommonState *state;
26
static SDL_GLContext *context = NULL;
36
for (i = 0; i < state->num_windows; i++) {
38
SDL_GL_DestroyContext(context[i]);
45
SDLTest_CommonQuit(state);
55
static GLubyte color[8][4] = { { 255, 0, 0, 0 },
60
{ 255, 255, 255, 255 },
63
static GLfloat cube[8][3] = { { 0.5, 0.5, -0.5 },
64
{ 0.5f, -0.5f, -0.5f },
65
{ -0.5f, -0.5f, -0.5f },
66
{ -0.5f, 0.5f, -0.5f },
67
{ -0.5f, 0.5f, 0.5f },
69
{ 0.5f, -0.5f, 0.5f },
70
{ -0.5f, -0.5f, 0.5f } };
71
static GLubyte indices[36] = { 0, 3, 4,
85
glClearColor(0.0, 0.0, 0.0, 1.0);
86
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
89
glColorPointer(4, GL_UNSIGNED_BYTE, 0, color);
90
glEnableClientState(GL_COLOR_ARRAY);
91
glVertexPointer(3, GL_FLOAT, 0, cube);
92
glEnableClientState(GL_VERTEX_ARRAY);
93
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
95
glMatrixMode(GL_MODELVIEW);
96
glRotatef(5.0, 1.0, 1.0, 1.0);
99
int main(int argc, char *argv[])
104
const SDL_DisplayMode *mode;
106
Uint32 then, now, frames;
114
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
120
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
122
for (i = 1; i < argc;) {
125
consumed = SDLTest_CommonArg(state, i);
127
if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
130
} else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
133
} else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
139
depth = (int)SDL_strtol(argv[i], &endptr, 0);
140
if (endptr != argv[i] && *endptr == '\0') {
151
static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
152
SDLTest_CommonLogUsage(state, argv[0], options);
159
state->window_flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
160
state->gl_red_size = 5;
161
state->gl_green_size = 5;
162
state->gl_blue_size = 5;
163
state->gl_depth_size = depth;
164
state->gl_major_version = 1;
165
state->gl_minor_version = 1;
166
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
168
state->gl_multisamplebuffers = 1;
169
state->gl_multisamplesamples = fsaa;
172
state->gl_accelerated = 1;
174
if (!SDLTest_CommonInit(state)) {
178
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(*context));
180
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
185
for (i = 0; i < state->num_windows; i++) {
186
context[i] = SDL_GL_CreateContext(state->windows[i]);
188
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
193
SDL_GL_SetSwapInterval(state->render_vsync);
195
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
197
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode->format));
200
SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
201
SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
202
SDL_Log("Version : %s\n", glGetString(GL_VERSION));
203
SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
206
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
208
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
210
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n",
213
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
215
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
217
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
220
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
222
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
224
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
227
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
229
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
231
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
235
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
237
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
239
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
242
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
244
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
247
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
252
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
254
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
256
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
262
for (i = 0; i < state->num_windows; ++i) {
265
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
267
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
273
aspectAdjust = (4.0f / 3.0f) / ((float)state->window_w / state->window_h);
274
glViewport(0, 0, state->window_w, state->window_h);
275
glMatrixMode(GL_PROJECTION);
277
glOrthof(-2.0, 2.0, -2.0 * aspectAdjust, 2.0 * aspectAdjust, -20.0, 20.0);
278
glMatrixMode(GL_MODELVIEW);
280
glEnable(GL_DEPTH_TEST);
281
glDepthFunc(GL_LESS);
282
glShadeModel(GL_SMOOTH);
287
then = SDL_GetTicks();
292
while (SDL_PollEvent(&event)) {
293
if (event.type == SDL_EVENT_WINDOW_RESIZED) {
294
for (i = 0; i < state->num_windows; ++i) {
295
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
296
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
298
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
302
glViewport(0, 0, event.window.data1, event.window.data2);
305
SDL_GL_SwapWindow(state->windows[i]);
310
SDLTest_CommonEvent(state, &event, &done);
312
for (i = 0; i < state->num_windows; ++i) {
313
if (state->windows[i] == NULL) {
316
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
318
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
324
SDL_GL_SwapWindow(state->windows[i]);
329
now = SDL_GetTicks();
331
SDL_Log("%2.2f frames per second\n",
332
((double)frames * 1000) / (now - then));
334
#ifndef SDL_PLATFORM_ANDROID
342
int main(int argc, char *argv[])
344
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL ES support on this system\n");