test/testgl2.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2019 09:10:56 -0700
changeset 12928 3c4a4b1077cd
parent 12758 3c6a6dad3487
permissions -rw-r--r--
Fixed bug 4710 - audio/alsa: avoid configuring hardware parameters with only a single period

Anthony Pesch

The previous code first configured the period size using snd_pcm_hw_par-
ams_set_period_size_near. Then, it further narrowed the configuration
space by calling snd_pcm_hw_params_set_buffer_size_near using a buffer
size of 2 times the _requested_ period size in order to try and get a
configuration with only 2 periods. If the configured period size was
larger than the requested size, the second call could inadvertently
narrow the configuration space to contain only a single period.

Rather than fixing the call to snd_pcm_hw_params_set_buffer_size_near
to use a size of 2 times the configured period size, the code has been
changed to use snd_pcm_hw_params_set_periods_min in order to more
clearly explain the intent.
slouken@5535
     1
/*
slouken@12503
     2
  Copyright (C) 1997-2019 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 ) { \
philipp@10945
    59
            return SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \
gabomdq@8062
    60
        } \
gabomdq@8062
    61
    } while ( 0 );
philipp@9966
    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;
icculus@12478
   221
    int swap_interval = 0;
slouken@1914
   222
aschiffler@7639
   223
    /* Enable standard application logging */
aschiffler@7639
   224
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
aschiffler@7639
   225
slouken@1915
   226
    /* Initialize parameters */
slouken@1915
   227
    fsaa = 0;
slouken@3571
   228
    accel = -1;
slouken@1915
   229
slouken@1915
   230
    /* Initialize test framework */
slouken@6785
   231
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
slouken@1915
   232
    if (!state) {
slouken@1915
   233
        return 1;
slouken@1915
   234
    }
slouken@1915
   235
    for (i = 1; i < argc;) {
slouken@1915
   236
        int consumed;
slouken@1915
   237
slouken@6785
   238
        consumed = SDLTest_CommonArg(state, i);
slouken@1915
   239
        if (consumed == 0) {
urkle@7381
   240
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
urkle@7381
   241
                fsaa = atoi(argv[i+1]);
urkle@7381
   242
                consumed = 2;
slouken@3571
   243
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
slouken@3571
   244
                accel = atoi(argv[i+1]);
slouken@3571
   245
                consumed = 2;
slouken@1915
   246
            } else {
slouken@1915
   247
                consumed = -1;
slouken@1915
   248
            }
slouken@1914
   249
        }
slouken@1915
   250
        if (consumed < 0) {
icculus@12758
   251
            static const char *options[] = { "[--fsaa n]", "[--accel n]", NULL };
icculus@12758
   252
            SDLTest_CommonLogUsage(state, argv[0], options);
slouken@1915
   253
            quit(1);
slouken@1914
   254
        }
slouken@1915
   255
        i += consumed;
slouken@1914
   256
    }
slouken@1914
   257
slouken@1915
   258
    /* Set OpenGL parameters */
slouken@1915
   259
    state->window_flags |= SDL_WINDOW_OPENGL;
lestat@3408
   260
    state->gl_red_size = 5;
lestat@3408
   261
    state->gl_green_size = 5;
lestat@3408
   262
    state->gl_blue_size = 5;
lestat@3408
   263
    state->gl_depth_size = 16;
slouken@3418
   264
    state->gl_double_buffer = 1;
slouken@1914
   265
    if (fsaa) {
lestat@3408
   266
        state->gl_multisamplebuffers = 1;
lestat@3408
   267
        state->gl_multisamplesamples = fsaa;
slouken@1914
   268
    }
slouken@3571
   269
    if (accel >= 0) {
slouken@3571
   270
        state->gl_accelerated = accel;
slouken@3571
   271
    }
lestat@3408
   272
slouken@6785
   273
    if (!SDLTest_CommonInit(state)) {
slouken@1915
   274
        quit(2);
slouken@1914
   275
    }
slouken@1915
   276
slouken@1915
   277
    /* Create OpenGL context */
slouken@1915
   278
    context = SDL_GL_CreateContext(state->windows[0]);
slouken@1915
   279
    if (!context) {
aschiffler@7639
   280
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
slouken@1915
   281
        quit(2);
slouken@1915
   282
    }
gabomdq@8062
   283
    
gabomdq@8062
   284
    /* Important: call this *after* creating the context */
gabomdq@8062
   285
    if (LoadContext(&ctx) < 0) {
gabomdq@8062
   286
        SDL_Log("Could not load GL functions\n");
gabomdq@8062
   287
        quit(2);
gabomdq@8062
   288
        return 0;
gabomdq@8062
   289
    }
slouken@1915
   290
slouken@1965
   291
    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
icculus@6382
   292
        /* try late-swap-tearing first. If not supported, try normal vsync. */
icculus@12478
   293
        if (SDL_GL_SetSwapInterval(-1) == 0) {
icculus@12478
   294
            swap_interval = -1;
icculus@12478
   295
        } else {
icculus@6382
   296
            SDL_GL_SetSwapInterval(1);
icculus@12478
   297
            swap_interval = 1;
icculus@6382
   298
        }
slouken@1914
   299
    } else {
icculus@6382
   300
        SDL_GL_SetSwapInterval(0);  /* disable vsync. */
icculus@12478
   301
        swap_interval = 0;
slouken@1914
   302
    }
slouken@1914
   303
slouken@5244
   304
    SDL_GetCurrentDisplayMode(0, &mode);
aschiffler@7639
   305
    SDL_Log("Screen BPP    : %d\n", SDL_BITSPERPIXEL(mode.format));
aschiffler@7639
   306
    SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
urkle@7746
   307
    SDL_GetWindowSize(state->windows[0], &dw, &dh);
urkle@7746
   308
    SDL_Log("Window Size   : %d,%d\n", dw, dh);
urkle@7746
   309
    SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
urkle@7746
   310
    SDL_Log("Draw Size     : %d,%d\n", dw, dh);
aschiffler@7639
   311
    SDL_Log("\n");
gabomdq@8062
   312
    SDL_Log("Vendor        : %s\n", ctx.glGetString(GL_VENDOR));
gabomdq@8062
   313
    SDL_Log("Renderer      : %s\n", ctx.glGetString(GL_RENDERER));
gabomdq@8062
   314
    SDL_Log("Version       : %s\n", ctx.glGetString(GL_VERSION));
gabomdq@8062
   315
    SDL_Log("Extensions    : %s\n", ctx.glGetString(GL_EXTENSIONS));
aschiffler@7639
   316
    SDL_Log("\n");
slouken@1914
   317
slouken@3139
   318
    status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
slouken@3099
   319
    if (!status) {
aschiffler@7639
   320
        SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   321
    } else {
aschiffler@7639
   322
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
slouken@3099
   323
    }
slouken@3139
   324
    status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
slouken@3099
   325
    if (!status) {
aschiffler@7639
   326
        SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   327
    } else {
aschiffler@7639
   328
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
slouken@3099
   329
    }
slouken@3139
   330
    status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
slouken@3099
   331
    if (!status) {
aschiffler@7639
   332
        SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   333
    } else {
aschiffler@7639
   334
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
slouken@3099
   335
    }
slouken@3139
   336
    status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
slouken@3099
   337
    if (!status) {
aschiffler@7639
   338
        SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
slouken@3099
   339
    } else {
aschiffler@7639
   340
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
slouken@3099
   341
    }
slouken@1914
   342
    if (fsaa) {
slouken@3139
   343
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
slouken@3099
   344
        if (!status) {
aschiffler@7639
   345
            SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
slouken@3099
   346
        } else {
aschiffler@7639
   347
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
slouken@3139
   348
                   SDL_GetError());
slouken@3099
   349
        }
slouken@3139
   350
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
slouken@3099
   351
        if (!status) {
aschiffler@7639
   352
            SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
slouken@3139
   353
                   value);
slouken@3099
   354
        } else {
aschiffler@7639
   355
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
slouken@3139
   356
                   SDL_GetError());
slouken@3099
   357
        }
slouken@1914
   358
    }
slouken@3571
   359
    if (accel >= 0) {
slouken@3571
   360
        status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
slouken@3571
   361
        if (!status) {
aschiffler@7639
   362
            SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
slouken@3571
   363
                   value);
slouken@3571
   364
        } else {
philipp@9922
   365
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
slouken@3571
   366
                   SDL_GetError());
slouken@3571
   367
        }
slouken@1914
   368
    }
slouken@1915
   369
slouken@1915
   370
    /* Set rendering settings */
gabomdq@8062
   371
    ctx.glMatrixMode(GL_PROJECTION);
gabomdq@8062
   372
    ctx.glLoadIdentity();
gabomdq@8062
   373
    ctx.glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
gabomdq@8062
   374
    ctx.glMatrixMode(GL_MODELVIEW);
gabomdq@8062
   375
    ctx.glLoadIdentity();
gabomdq@8062
   376
    ctx.glEnable(GL_DEPTH_TEST);
gabomdq@8062
   377
    ctx.glDepthFunc(GL_LESS);
gabomdq@8062
   378
    ctx.glShadeModel(GL_SMOOTH);
urkle@7746
   379
    
slouken@1915
   380
    /* Main render loop */
slouken@1915
   381
    frames = 0;
slouken@1915
   382
    then = SDL_GetTicks();
slouken@1915
   383
    done = 0;
slouken@1915
   384
    while (!done) {
icculus@12478
   385
        SDL_bool update_swap_interval = SDL_FALSE;
icculus@12478
   386
slouken@1915
   387
        /* Check for events */
slouken@1915
   388
        ++frames;
slouken@1915
   389
        while (SDL_PollEvent(&event)) {
slouken@6785
   390
            SDLTest_CommonEvent(state, &event, &done);
icculus@12478
   391
            if (event.type == SDL_KEYDOWN) {
icculus@12478
   392
                if (event.key.keysym.sym == SDLK_o) {
icculus@12478
   393
                    swap_interval--;
icculus@12478
   394
                    update_swap_interval = SDL_TRUE;
icculus@12478
   395
                } else if (event.key.keysym.sym == SDLK_p) {
icculus@12478
   396
                    swap_interval++;
icculus@12478
   397
                    update_swap_interval = SDL_TRUE;
icculus@12478
   398
                }
icculus@12478
   399
            }
slouken@1915
   400
        }
icculus@12478
   401
icculus@12478
   402
        if (update_swap_interval) {
icculus@12478
   403
            SDL_Log("Swap interval to be set to %d\n", swap_interval);
icculus@12478
   404
        }
icculus@12478
   405
slouken@1915
   406
        for (i = 0; i < state->num_windows; ++i) {
slouken@1915
   407
            int w, h;
slouken@7787
   408
            if (state->windows[i] == NULL)
slouken@7787
   409
                continue;
slouken@1915
   410
            SDL_GL_MakeCurrent(state->windows[i], context);
icculus@12478
   411
            if (update_swap_interval) {
icculus@12478
   412
                SDL_GL_SetSwapInterval(swap_interval);
icculus@12478
   413
            }
urkle@7746
   414
            SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
gabomdq@8062
   415
            ctx.glViewport(0, 0, w, h);
slouken@1915
   416
            Render();
slouken@1915
   417
            SDL_GL_SwapWindow(state->windows[i]);
slouken@1915
   418
        }
slouken@1914
   419
    }
slouken@1914
   420
slouken@1915
   421
    /* Print out some timing information */
slouken@1915
   422
    now = SDL_GetTicks();
slouken@1915
   423
    if (now > then) {
aschiffler@7639
   424
        SDL_Log("%2.2f frames per second\n",
slouken@1915
   425
               ((double) frames * 1000) / (now - then));
slouken@1914
   426
    }
slouken@1915
   427
    quit(0);
slouken@2232
   428
    return 0;
slouken@1914
   429
}
slouken@1914
   430
slouken@1914
   431
#else /* HAVE_OPENGL */
slouken@1914
   432
slouken@1914
   433
int
slouken@1914
   434
main(int argc, char *argv[])
slouken@1914
   435
{
aschiffler@7639
   436
    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
slouken@1914
   437
    return 1;
slouken@1914
   438
}
slouken@1914
   439
slouken@1914
   440
#endif /* HAVE_OPENGL */