test/testgl2.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 21 Mar 2015 08:01:43 +0100
changeset 9417 86483b23f44a
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Fixed confusing audio and touch events because of shared enumeration values.
slouken@5535
     1
/*
slouken@8149
     2
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
slouken@1914
    12
#include <stdlib.h>
slouken@1914
    13
#include <stdio.h>
slouken@1914
    14
#include <string.h>
slouken@1914
    15
#include <math.h>
slouken@1914
    16
slouken@6785
    17
#include "SDL_test_common.h"
slouken@1914
    18
slouken@1914
    19
#ifdef __MACOS__
slouken@1914
    20
#define HAVE_OPENGL
slouken@1914
    21
#endif
slouken@1914
    22
slouken@1914
    23
#ifdef HAVE_OPENGL
slouken@1914
    24
slouken@1914
    25
#include "SDL_opengl.h"
slouken@1914
    26
gabomdq@8062
    27
typedef struct GL_Context
gabomdq@8062
    28
{
gabomdq@8062
    29
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
gabomdq@8062
    30
#include "../src/render/opengl/SDL_glfuncs.h"
gabomdq@8062
    31
#undef SDL_PROC
gabomdq@8062
    32
} GL_Context;
gabomdq@8062
    33
gabomdq@8062
    34
slouken@1914
    35
/* Undefine this if you want a flat cube instead of a rainbow cube */
slouken@1914
    36
#define SHADED_CUBE
slouken@1914
    37
slouken@6785
    38
static SDLTest_CommonState *state;
slouken@1915
    39
static SDL_GLContext context;
gabomdq@8062
    40
static GL_Context ctx;
gabomdq@8062
    41
gabomdq@8062
    42
static int LoadContext(GL_Context * data)
gabomdq@8062
    43
{
gabomdq@8062
    44
#if SDL_VIDEO_DRIVER_UIKIT
gabomdq@8062
    45
#define __SDL_NOGETPROCADDR__
gabomdq@8062
    46
#elif SDL_VIDEO_DRIVER_ANDROID
gabomdq@8062
    47
#define __SDL_NOGETPROCADDR__
gabomdq@8062
    48
#elif SDL_VIDEO_DRIVER_PANDORA
gabomdq@8062
    49
#define __SDL_NOGETPROCADDR__
gabomdq@8062
    50
#endif
gabomdq@8062
    51
gabomdq@8062
    52
#if defined __SDL_NOGETPROCADDR__
gabomdq@8062
    53
#define SDL_PROC(ret,func,params) data->func=func;
gabomdq@8062
    54
#else
gabomdq@8062
    55
#define SDL_PROC(ret,func,params) \
gabomdq@8062
    56
    do { \
gabomdq@8062
    57
        data->func = SDL_GL_GetProcAddress(#func); \
gabomdq@8062
    58
        if ( ! data->func ) { \
gabomdq@8062
    59
            return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
gabomdq@8062
    60
        } \
gabomdq@8062
    61
    } while ( 0 );
gabomdq@8062
    62
#endif /* _SDL_NOGETPROCADDR_ */
gabomdq@8062
    63
gabomdq@8062
    64
#include "../src/render/opengl/SDL_glfuncs.h"
gabomdq@8062
    65
#undef SDL_PROC
gabomdq@8062
    66
    return 0;
gabomdq@8062
    67
}
gabomdq@8062
    68
slouken@1914
    69
slouken@1915
    70
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
slouken@1915
    71
static void
slouken@1915
    72
quit(int rc)
slouken@1914
    73
{
slouken@1915
    74
    if (context) {
bob@2328
    75
        /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
slouken@1915
    76
        SDL_GL_DeleteContext(context);
slouken@1914
    77
    }
slouken@6785
    78
    SDLTest_CommonQuit(state);
slouken@1915
    79
    exit(rc);
slouken@1914
    80
}
slouken@1914
    81
slouken@1915
    82
static void
slouken@1915
    83
Render()
slouken@1914
    84
{
slouken@1915
    85
    static float color[8][3] = {
slouken@1915
    86
        {1.0, 1.0, 0.0},
slouken@1915
    87
        {1.0, 0.0, 0.0},
slouken@1915
    88
        {0.0, 0.0, 0.0},
slouken@1915
    89
        {0.0, 1.0, 0.0},
slouken@1915
    90
        {0.0, 1.0, 1.0},
slouken@1915
    91
        {1.0, 1.0, 1.0},
slouken@1915
    92
        {1.0, 0.0, 1.0},
slouken@1915
    93
        {0.0, 0.0, 1.0}
slouken@1915
    94
    };
slouken@1915
    95
    static float cube[8][3] = {
slouken@1915
    96
        {0.5, 0.5, -0.5},
slouken@1915
    97
        {0.5, -0.5, -0.5},
slouken@1915
    98
        {-0.5, -0.5, -0.5},
slouken@1915
    99
        {-0.5, 0.5, -0.5},
slouken@1915
   100
        {-0.5, 0.5, 0.5},
slouken@1915
   101
        {0.5, 0.5, 0.5},
slouken@1915
   102
        {0.5, -0.5, 0.5},
slouken@1915
   103
        {-0.5, -0.5, 0.5}
slouken@1915
   104
    };
slouken@1914
   105
slouken@1915
   106
    /* Do our drawing, too. */
gabomdq@8062
   107
    ctx.glClearColor(0.0, 0.0, 0.0, 1.0);
gabomdq@8062
   108
    ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
slouken@1914
   109
gabomdq@8062
   110
    ctx.glBegin(GL_QUADS);
slouken@1915
   111
slouken@1915
   112
#ifdef SHADED_CUBE
gabomdq@8062
   113
    ctx.glColor3fv(color[0]);
gabomdq@8062
   114
    ctx.glVertex3fv(cube[0]);
gabomdq@8062
   115
    ctx.glColor3fv(color[1]);
gabomdq@8062
   116
    ctx.glVertex3fv(cube[1]);
gabomdq@8062
   117
    ctx.glColor3fv(color[2]);
gabomdq@8062
   118
    ctx.glVertex3fv(cube[2]);
gabomdq@8062
   119
    ctx.glColor3fv(color[3]);
gabomdq@8062
   120
    ctx.glVertex3fv(cube[3]);
slouken@1915
   121
gabomdq@8062
   122
    ctx.glColor3fv(color[3]);
gabomdq@8062
   123
    ctx.glVertex3fv(cube[3]);
gabomdq@8062
   124
    ctx.glColor3fv(color[4]);
gabomdq@8062
   125
    ctx.glVertex3fv(cube[4]);
gabomdq@8062
   126
    ctx.glColor3fv(color[7]);
gabomdq@8062
   127
    ctx.glVertex3fv(cube[7]);
gabomdq@8062
   128
    ctx.glColor3fv(color[2]);
gabomdq@8062
   129
    ctx.glVertex3fv(cube[2]);
slouken@1915
   130
gabomdq@8062
   131
    ctx.glColor3fv(color[0]);
gabomdq@8062
   132
    ctx.glVertex3fv(cube[0]);
gabomdq@8062
   133
    ctx.glColor3fv(color[5]);
gabomdq@8062
   134
    ctx.glVertex3fv(cube[5]);
gabomdq@8062
   135
    ctx.glColor3fv(color[6]);
gabomdq@8062
   136
    ctx.glVertex3fv(cube[6]);
gabomdq@8062
   137
    ctx.glColor3fv(color[1]);
gabomdq@8062
   138
    ctx.glVertex3fv(cube[1]);
slouken@1915
   139
gabomdq@8062
   140
    ctx.glColor3fv(color[5]);
gabomdq@8062
   141
    ctx.glVertex3fv(cube[5]);
gabomdq@8062
   142
    ctx.glColor3fv(color[4]);
gabomdq@8062
   143
    ctx.glVertex3fv(cube[4]);
gabomdq@8062
   144
    ctx.glColor3fv(color[7]);
gabomdq@8062
   145
    ctx.glVertex3fv(cube[7]);
gabomdq@8062
   146
    ctx.glColor3fv(color[6]);
gabomdq@8062
   147
    ctx.glVertex3fv(cube[6]);
slouken@1915
   148
gabomdq@8062
   149
    ctx.glColor3fv(color[5]);
gabomdq@8062
   150
    ctx.glVertex3fv(cube[5]);
gabomdq@8062
   151
    ctx.glColor3fv(color[0]);
gabomdq@8062
   152
    ctx.glVertex3fv(cube[0]);
gabomdq@8062
   153
    ctx.glColor3fv(color[3]);
gabomdq@8062
   154
    ctx.glVertex3fv(cube[3]);
gabomdq@8062
   155
    ctx.glColor3fv(color[4]);
gabomdq@8062
   156
    ctx.glVertex3fv(cube[4]);
slouken@1915
   157
gabomdq@8062
   158
    ctx.glColor3fv(color[6]);
gabomdq@8062
   159
    ctx.glVertex3fv(cube[6]);
gabomdq@8062
   160
    ctx.glColor3fv(color[1]);
gabomdq@8062
   161
    ctx.glVertex3fv(cube[1]);
gabomdq@8062
   162
    ctx.glColor3fv(color[2]);
gabomdq@8062
   163
    ctx.glVertex3fv(cube[2]);
gabomdq@8062
   164
    ctx.glColor3fv(color[7]);
gabomdq@8062
   165
    ctx.glVertex3fv(cube[7]);
slouken@1915
   166
#else /* flat cube */
gabomdq@8062
   167
    ctx.glColor3f(1.0, 0.0, 0.0);
gabomdq@8062
   168
    ctx.glVertex3fv(cube[0]);
gabomdq@8062
   169
    ctx.glVertex3fv(cube[1]);
gabomdq@8062
   170
    ctx.glVertex3fv(cube[2]);
gabomdq@8062
   171
    ctx.glVertex3fv(cube[3]);
slouken@1915
   172
gabomdq@8062
   173
    ctx.glColor3f(0.0, 1.0, 0.0);
gabomdq@8062
   174
    ctx.glVertex3fv(cube[3]);
gabomdq@8062
   175
    ctx.glVertex3fv(cube[4]);
gabomdq@8062
   176
    ctx.glVertex3fv(cube[7]);
gabomdq@8062
   177
    ctx.glVertex3fv(cube[2]);
slouken@1915
   178
gabomdq@8062
   179
    ctx.glColor3f(0.0, 0.0, 1.0);
gabomdq@8062
   180
    ctx.glVertex3fv(cube[0]);
gabomdq@8062
   181
    ctx.glVertex3fv(cube[5]);
gabomdq@8062
   182
    ctx.glVertex3fv(cube[6]);
gabomdq@8062
   183
    ctx.glVertex3fv(cube[1]);
slouken@1915
   184
gabomdq@8062
   185
    ctx.glColor3f(0.0, 1.0, 1.0);
gabomdq@8062
   186
    ctx.glVertex3fv(cube[5]);
gabomdq@8062
   187
    ctx.glVertex3fv(cube[4]);
gabomdq@8062
   188
    ctx.glVertex3fv(cube[7]);
gabomdq@8062
   189
    ctx.glVertex3fv(cube[6]);
slouken@1915
   190
gabomdq@8062
   191
    ctx.glColor3f(1.0, 1.0, 0.0);
gabomdq@8062
   192
    ctx.glVertex3fv(cube[5]);
gabomdq@8062
   193
    ctx.glVertex3fv(cube[0]);
gabomdq@8062
   194
    ctx.glVertex3fv(cube[3]);
gabomdq@8062
   195
    ctx.glVertex3fv(cube[4]);
slouken@1915
   196
gabomdq@8062
   197
    ctx.glColor3f(1.0, 0.0, 1.0);
gabomdq@8062
   198
    ctx.glVertex3fv(cube[6]);
gabomdq@8062
   199
    ctx.glVertex3fv(cube[1]);
gabomdq@8062
   200
    ctx.glVertex3fv(cube[2]);
gabomdq@8062
   201
    ctx.glVertex3fv(cube[7]);
slouken@1915
   202
#endif /* SHADED_CUBE */
slouken@1915
   203
gabomdq@8062
   204
    ctx.glEnd();
slouken@1915
   205
gabomdq@8062
   206
    ctx.glMatrixMode(GL_MODELVIEW);
gabomdq@8062
   207
    ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
slouken@1914
   208
}
slouken@1914
   209
slouken@1914
   210
int
slouken@1915
   211
main(int argc, char *argv[])
slouken@1914
   212
{
slouken@3571
   213
    int fsaa, accel;
slouken@1915
   214
    int value;
slouken@1915
   215
    int i, done;
slouken@1967
   216
    SDL_DisplayMode mode;
slouken@1915
   217
    SDL_Event event;
slouken@1915
   218
    Uint32 then, now, frames;
slouken@3099
   219
    int status;
urkle@7746
   220
    int dw, dh;
slouken@1914
   221
aschiffler@7639
   222
    /* Enable standard application logging */
aschiffler@7639
   223
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
aschiffler@7639
   224
slouken@1915
   225
    /* Initialize parameters */
slouken@1915
   226
    fsaa = 0;
slouken@3571
   227
    accel = -1;
slouken@1915
   228
slouken@1915
   229
    /* Initialize test framework */
slouken@6785
   230
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
slouken@1915
   231
    if (!state) {
slouken@1915
   232
        return 1;
slouken@1915
   233
    }
slouken@1915
   234
    for (i = 1; i < argc;) {
slouken@1915
   235
        int consumed;
slouken@1915
   236
slouken@6785
   237
        consumed = SDLTest_CommonArg(state, i);
slouken@1915
   238
        if (consumed == 0) {
urkle@7381
   239
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
urkle@7381
   240
                fsaa = atoi(argv[i+1]);
urkle@7381
   241
                consumed = 2;
slouken@3571
   242
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
slouken@3571
   243
                accel = atoi(argv[i+1]);
slouken@3571
   244
                consumed = 2;
slouken@1915
   245
            } else {
slouken@1915
   246
                consumed = -1;
slouken@1915
   247
            }
slouken@1914
   248
        }
slouken@1915
   249
        if (consumed < 0) {
aschiffler@7639
   250
            SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
slouken@6785
   251
                    SDLTest_CommonUsage(state));
slouken@1915
   252
            quit(1);
slouken@1914
   253
        }
slouken@1915
   254
        i += consumed;
slouken@1914
   255
    }
slouken@1914
   256
slouken@1915
   257
    /* Set OpenGL parameters */
slouken@1915
   258
    state->window_flags |= SDL_WINDOW_OPENGL;
lestat@3408
   259
    state->gl_red_size = 5;
lestat@3408
   260
    state->gl_green_size = 5;
lestat@3408
   261
    state->gl_blue_size = 5;
lestat@3408
   262
    state->gl_depth_size = 16;
slouken@3418
   263
    state->gl_double_buffer = 1;
slouken@1914
   264
    if (fsaa) {
lestat@3408
   265
        state->gl_multisamplebuffers = 1;
lestat@3408
   266
        state->gl_multisamplesamples = fsaa;
slouken@1914
   267
    }
slouken@3571
   268
    if (accel >= 0) {
slouken@3571
   269
        state->gl_accelerated = accel;
slouken@3571
   270
    }
lestat@3408
   271
slouken@6785
   272
    if (!SDLTest_CommonInit(state)) {
slouken@1915
   273
        quit(2);
slouken@1914
   274
    }
slouken@1915
   275
slouken@1915
   276
    /* Create OpenGL context */
slouken@1915
   277
    context = SDL_GL_CreateContext(state->windows[0]);
slouken@1915
   278
    if (!context) {
aschiffler@7639
   279
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
slouken@1915
   280
        quit(2);
slouken@1915
   281
    }
gabomdq@8062
   282
    
gabomdq@8062
   283
    /* Important: call this *after* creating the context */
gabomdq@8062
   284
    if (LoadContext(&ctx) < 0) {
gabomdq@8062
   285
        SDL_Log("Could not load GL functions\n");
gabomdq@8062
   286
        quit(2);
gabomdq@8062
   287
        return 0;
gabomdq@8062
   288
    }
slouken@1915
   289
slouken@1965
   290
    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
icculus@6382
   291
        /* try late-swap-tearing first. If not supported, try normal vsync. */
icculus@6382
   292
        if (SDL_GL_SetSwapInterval(-1) == -1) {
icculus@6382
   293
            SDL_GL_SetSwapInterval(1);
icculus@6382
   294
        }
slouken@1914
   295
    } else {
icculus@6382
   296
        SDL_GL_SetSwapInterval(0);  /* disable vsync. */
slouken@1914
   297
    }
slouken@1914
   298
slouken@5244
   299
    SDL_GetCurrentDisplayMode(0, &mode);
aschiffler@7639
   300
    SDL_Log("Screen BPP    : %d\n", SDL_BITSPERPIXEL(mode.format));
aschiffler@7639
   301
    SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
urkle@7746
   302
    SDL_GetWindowSize(state->windows[0], &dw, &dh);
urkle@7746
   303
    SDL_Log("Window Size   : %d,%d\n", dw, dh);
urkle@7746
   304
    SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
urkle@7746
   305
    SDL_Log("Draw Size     : %d,%d\n", dw, dh);
aschiffler@7639
   306
    SDL_Log("\n");
gabomdq@8062
   307
    SDL_Log("Vendor        : %s\n", ctx.glGetString(GL_VENDOR));
gabomdq@8062
   308
    SDL_Log("Renderer      : %s\n", ctx.glGetString(GL_RENDERER));
gabomdq@8062
   309
    SDL_Log("Version       : %s\n", ctx.glGetString(GL_VERSION));
gabomdq@8062
   310
    SDL_Log("Extensions    : %s\n", ctx.glGetString(GL_EXTENSIONS));
aschiffler@7639
   311
    SDL_Log("\n");
slouken@1914
   312
slouken@3139
   313
    status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
slouken@3099
   314
    if (!status) {
aschiffler@7639
   315
        SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   316
    } else {
aschiffler@7639
   317
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
slouken@3099
   318
    }
slouken@3139
   319
    status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
slouken@3099
   320
    if (!status) {
aschiffler@7639
   321
        SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   322
    } else {
aschiffler@7639
   323
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
slouken@3099
   324
    }
slouken@3139
   325
    status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
slouken@3099
   326
    if (!status) {
aschiffler@7639
   327
        SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   328
    } else {
aschiffler@7639
   329
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
slouken@3099
   330
    }
slouken@3139
   331
    status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
slouken@3099
   332
    if (!status) {
aschiffler@7639
   333
        SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
slouken@3099
   334
    } else {
aschiffler@7639
   335
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
slouken@3099
   336
    }
slouken@1914
   337
    if (fsaa) {
slouken@3139
   338
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
slouken@3099
   339
        if (!status) {
aschiffler@7639
   340
            SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
slouken@3099
   341
        } else {
aschiffler@7639
   342
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
slouken@3139
   343
                   SDL_GetError());
slouken@3099
   344
        }
slouken@3139
   345
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
slouken@3099
   346
        if (!status) {
aschiffler@7639
   347
            SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
slouken@3139
   348
                   value);
slouken@3099
   349
        } else {
aschiffler@7639
   350
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
slouken@3139
   351
                   SDL_GetError());
slouken@3099
   352
        }
slouken@1914
   353
    }
slouken@3571
   354
    if (accel >= 0) {
slouken@3571
   355
        status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
slouken@3571
   356
        if (!status) {
aschiffler@7639
   357
            SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
slouken@3571
   358
                   value);
slouken@3571
   359
        } else {
aschiffler@7639
   360
			SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
slouken@3571
   361
                   SDL_GetError());
slouken@3571
   362
        }
slouken@1914
   363
    }
slouken@1915
   364
slouken@1915
   365
    /* Set rendering settings */
gabomdq@8062
   366
    ctx.glMatrixMode(GL_PROJECTION);
gabomdq@8062
   367
    ctx.glLoadIdentity();
gabomdq@8062
   368
    ctx.glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
gabomdq@8062
   369
    ctx.glMatrixMode(GL_MODELVIEW);
gabomdq@8062
   370
    ctx.glLoadIdentity();
gabomdq@8062
   371
    ctx.glEnable(GL_DEPTH_TEST);
gabomdq@8062
   372
    ctx.glDepthFunc(GL_LESS);
gabomdq@8062
   373
    ctx.glShadeModel(GL_SMOOTH);
urkle@7746
   374
    
slouken@1915
   375
    /* Main render loop */
slouken@1915
   376
    frames = 0;
slouken@1915
   377
    then = SDL_GetTicks();
slouken@1915
   378
    done = 0;
slouken@1915
   379
    while (!done) {
slouken@1915
   380
        /* Check for events */
slouken@1915
   381
        ++frames;
slouken@1915
   382
        while (SDL_PollEvent(&event)) {
slouken@6785
   383
            SDLTest_CommonEvent(state, &event, &done);
slouken@1915
   384
        }
slouken@1915
   385
        for (i = 0; i < state->num_windows; ++i) {
slouken@1915
   386
            int w, h;
slouken@7787
   387
            if (state->windows[i] == NULL)
slouken@7787
   388
                continue;
slouken@1915
   389
            SDL_GL_MakeCurrent(state->windows[i], context);
urkle@7746
   390
            SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
gabomdq@8062
   391
            ctx.glViewport(0, 0, w, h);
slouken@1915
   392
            Render();
slouken@1915
   393
            SDL_GL_SwapWindow(state->windows[i]);
slouken@1915
   394
        }
slouken@1914
   395
    }
slouken@1914
   396
slouken@1915
   397
    /* Print out some timing information */
slouken@1915
   398
    now = SDL_GetTicks();
slouken@1915
   399
    if (now > then) {
aschiffler@7639
   400
        SDL_Log("%2.2f frames per second\n",
slouken@1915
   401
               ((double) frames * 1000) / (now - then));
slouken@1914
   402
    }
slouken@1915
   403
    quit(0);
slouken@2232
   404
    return 0;
slouken@1914
   405
}
slouken@1914
   406
slouken@1914
   407
#else /* HAVE_OPENGL */
slouken@1914
   408
slouken@1914
   409
int
slouken@1914
   410
main(int argc, char *argv[])
slouken@1914
   411
{
aschiffler@7639
   412
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
slouken@1914
   413
    return 1;
slouken@1914
   414
}
slouken@1914
   415
slouken@1914
   416
#endif /* HAVE_OPENGL */