test/testgl2.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 24 Mar 2009 10:33:12 +0000
changeset 3099 82e60908fab1
parent 2328 91e601d9df8b
child 3139 7f684f249ec9
permissions -rw-r--r--
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches

Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.

Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.

As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?

And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
slouken@1914
     1
#include <stdlib.h>
slouken@1914
     2
#include <stdio.h>
slouken@1914
     3
#include <string.h>
slouken@1914
     4
#include <math.h>
slouken@1914
     5
slouken@1915
     6
#include "common.h"
slouken@1914
     7
slouken@1914
     8
#ifdef __MACOS__
slouken@1914
     9
#define HAVE_OPENGL
slouken@1914
    10
#endif
slouken@1914
    11
slouken@1914
    12
#ifdef HAVE_OPENGL
slouken@1914
    13
slouken@1914
    14
#include "SDL_opengl.h"
slouken@1914
    15
slouken@1914
    16
/* Undefine this if you want a flat cube instead of a rainbow cube */
slouken@1914
    17
#define SHADED_CUBE
slouken@1914
    18
slouken@1915
    19
static CommonState *state;
slouken@1915
    20
static SDL_GLContext context;
slouken@1914
    21
slouken@1915
    22
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
slouken@1915
    23
static void
slouken@1915
    24
quit(int rc)
slouken@1914
    25
{
slouken@1915
    26
    if (context) {
bob@2328
    27
        /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
slouken@1915
    28
        SDL_GL_DeleteContext(context);
slouken@1914
    29
    }
slouken@1915
    30
    CommonQuit(state);
slouken@1915
    31
    exit(rc);
slouken@1914
    32
}
slouken@1914
    33
slouken@1915
    34
static void
slouken@1915
    35
Render()
slouken@1914
    36
{
slouken@1915
    37
    static float color[8][3] = {
slouken@1915
    38
        {1.0, 1.0, 0.0},
slouken@1915
    39
        {1.0, 0.0, 0.0},
slouken@1915
    40
        {0.0, 0.0, 0.0},
slouken@1915
    41
        {0.0, 1.0, 0.0},
slouken@1915
    42
        {0.0, 1.0, 1.0},
slouken@1915
    43
        {1.0, 1.0, 1.0},
slouken@1915
    44
        {1.0, 0.0, 1.0},
slouken@1915
    45
        {0.0, 0.0, 1.0}
slouken@1915
    46
    };
slouken@1915
    47
    static float cube[8][3] = {
slouken@1915
    48
        {0.5, 0.5, -0.5},
slouken@1915
    49
        {0.5, -0.5, -0.5},
slouken@1915
    50
        {-0.5, -0.5, -0.5},
slouken@1915
    51
        {-0.5, 0.5, -0.5},
slouken@1915
    52
        {-0.5, 0.5, 0.5},
slouken@1915
    53
        {0.5, 0.5, 0.5},
slouken@1915
    54
        {0.5, -0.5, 0.5},
slouken@1915
    55
        {-0.5, -0.5, 0.5}
slouken@1915
    56
    };
slouken@1914
    57
slouken@1915
    58
    /* Do our drawing, too. */
slouken@1915
    59
    glClearColor(0.0, 0.0, 0.0, 1.0);
slouken@1915
    60
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
slouken@1914
    61
slouken@1915
    62
    glBegin(GL_QUADS);
slouken@1915
    63
slouken@1915
    64
#ifdef SHADED_CUBE
slouken@1915
    65
    glColor3fv(color[0]);
slouken@1915
    66
    glVertex3fv(cube[0]);
slouken@1915
    67
    glColor3fv(color[1]);
slouken@1915
    68
    glVertex3fv(cube[1]);
slouken@1915
    69
    glColor3fv(color[2]);
slouken@1915
    70
    glVertex3fv(cube[2]);
slouken@1915
    71
    glColor3fv(color[3]);
slouken@1915
    72
    glVertex3fv(cube[3]);
slouken@1915
    73
slouken@1915
    74
    glColor3fv(color[3]);
slouken@1915
    75
    glVertex3fv(cube[3]);
slouken@1915
    76
    glColor3fv(color[4]);
slouken@1915
    77
    glVertex3fv(cube[4]);
slouken@1915
    78
    glColor3fv(color[7]);
slouken@1915
    79
    glVertex3fv(cube[7]);
slouken@1915
    80
    glColor3fv(color[2]);
slouken@1915
    81
    glVertex3fv(cube[2]);
slouken@1915
    82
slouken@1915
    83
    glColor3fv(color[0]);
slouken@1915
    84
    glVertex3fv(cube[0]);
slouken@1915
    85
    glColor3fv(color[5]);
slouken@1915
    86
    glVertex3fv(cube[5]);
slouken@1915
    87
    glColor3fv(color[6]);
slouken@1915
    88
    glVertex3fv(cube[6]);
slouken@1915
    89
    glColor3fv(color[1]);
slouken@1915
    90
    glVertex3fv(cube[1]);
slouken@1915
    91
slouken@1915
    92
    glColor3fv(color[5]);
slouken@1915
    93
    glVertex3fv(cube[5]);
slouken@1915
    94
    glColor3fv(color[4]);
slouken@1915
    95
    glVertex3fv(cube[4]);
slouken@1915
    96
    glColor3fv(color[7]);
slouken@1915
    97
    glVertex3fv(cube[7]);
slouken@1915
    98
    glColor3fv(color[6]);
slouken@1915
    99
    glVertex3fv(cube[6]);
slouken@1915
   100
slouken@1915
   101
    glColor3fv(color[5]);
slouken@1915
   102
    glVertex3fv(cube[5]);
slouken@1915
   103
    glColor3fv(color[0]);
slouken@1915
   104
    glVertex3fv(cube[0]);
slouken@1915
   105
    glColor3fv(color[3]);
slouken@1915
   106
    glVertex3fv(cube[3]);
slouken@1915
   107
    glColor3fv(color[4]);
slouken@1915
   108
    glVertex3fv(cube[4]);
slouken@1915
   109
slouken@1915
   110
    glColor3fv(color[6]);
slouken@1915
   111
    glVertex3fv(cube[6]);
slouken@1915
   112
    glColor3fv(color[1]);
slouken@1915
   113
    glVertex3fv(cube[1]);
slouken@1915
   114
    glColor3fv(color[2]);
slouken@1915
   115
    glVertex3fv(cube[2]);
slouken@1915
   116
    glColor3fv(color[7]);
slouken@1915
   117
    glVertex3fv(cube[7]);
slouken@1915
   118
#else /* flat cube */
slouken@1915
   119
    glColor3f(1.0, 0.0, 0.0);
slouken@1915
   120
    glVertex3fv(cube[0]);
slouken@1915
   121
    glVertex3fv(cube[1]);
slouken@1915
   122
    glVertex3fv(cube[2]);
slouken@1915
   123
    glVertex3fv(cube[3]);
slouken@1915
   124
slouken@1915
   125
    glColor3f(0.0, 1.0, 0.0);
slouken@1915
   126
    glVertex3fv(cube[3]);
slouken@1915
   127
    glVertex3fv(cube[4]);
slouken@1915
   128
    glVertex3fv(cube[7]);
slouken@1915
   129
    glVertex3fv(cube[2]);
slouken@1915
   130
slouken@1915
   131
    glColor3f(0.0, 0.0, 1.0);
slouken@1915
   132
    glVertex3fv(cube[0]);
slouken@1915
   133
    glVertex3fv(cube[5]);
slouken@1915
   134
    glVertex3fv(cube[6]);
slouken@1915
   135
    glVertex3fv(cube[1]);
slouken@1915
   136
slouken@1915
   137
    glColor3f(0.0, 1.0, 1.0);
slouken@1915
   138
    glVertex3fv(cube[5]);
slouken@1915
   139
    glVertex3fv(cube[4]);
slouken@1915
   140
    glVertex3fv(cube[7]);
slouken@1915
   141
    glVertex3fv(cube[6]);
slouken@1915
   142
slouken@1915
   143
    glColor3f(1.0, 1.0, 0.0);
slouken@1915
   144
    glVertex3fv(cube[5]);
slouken@1915
   145
    glVertex3fv(cube[0]);
slouken@1915
   146
    glVertex3fv(cube[3]);
slouken@1915
   147
    glVertex3fv(cube[4]);
slouken@1915
   148
slouken@1915
   149
    glColor3f(1.0, 0.0, 1.0);
slouken@1915
   150
    glVertex3fv(cube[6]);
slouken@1915
   151
    glVertex3fv(cube[1]);
slouken@1915
   152
    glVertex3fv(cube[2]);
slouken@1915
   153
    glVertex3fv(cube[7]);
slouken@1915
   154
#endif /* SHADED_CUBE */
slouken@1915
   155
slouken@1915
   156
    glEnd();
slouken@1915
   157
slouken@1915
   158
    glMatrixMode(GL_MODELVIEW);
slouken@1915
   159
    glRotatef(5.0, 1.0, 1.0, 1.0);
slouken@1914
   160
}
slouken@1914
   161
slouken@1914
   162
int
slouken@1915
   163
main(int argc, char *argv[])
slouken@1914
   164
{
slouken@1915
   165
    int fsaa, accel;
slouken@1915
   166
    int value;
slouken@1915
   167
    int i, done;
slouken@1967
   168
    SDL_DisplayMode mode;
slouken@1915
   169
    SDL_Event event;
slouken@1915
   170
    Uint32 then, now, frames;
slouken@3099
   171
    int status;
slouken@1914
   172
slouken@1915
   173
    /* Initialize parameters */
slouken@1915
   174
    fsaa = 0;
slouken@1915
   175
    accel = 0;
slouken@1915
   176
slouken@1915
   177
    /* Initialize test framework */
slouken@1915
   178
    state = CommonCreateState(argv, SDL_INIT_VIDEO);
slouken@1915
   179
    if (!state) {
slouken@1915
   180
        return 1;
slouken@1915
   181
    }
slouken@1915
   182
    for (i = 1; i < argc;) {
slouken@1915
   183
        int consumed;
slouken@1915
   184
slouken@1915
   185
        consumed = CommonArg(state, i);
slouken@1915
   186
        if (consumed == 0) {
slouken@1915
   187
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
slouken@1915
   188
                ++fsaa;
slouken@1915
   189
                consumed = 1;
slouken@1915
   190
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
slouken@1915
   191
                ++accel;
slouken@1915
   192
                consumed = 1;
slouken@1915
   193
            } else {
slouken@1915
   194
                consumed = -1;
slouken@1915
   195
            }
slouken@1914
   196
        }
slouken@1915
   197
        if (consumed < 0) {
slouken@1985
   198
            fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]\n", argv[0],
slouken@1915
   199
                    CommonUsage(state));
slouken@1915
   200
            quit(1);
slouken@1914
   201
        }
slouken@1915
   202
        i += consumed;
slouken@1914
   203
    }
slouken@1914
   204
slouken@1915
   205
    /* Set OpenGL parameters */
slouken@1915
   206
    state->window_flags |= SDL_WINDOW_OPENGL;
slouken@1915
   207
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
slouken@1915
   208
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
slouken@1915
   209
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
slouken@1914
   210
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
slouken@1914
   211
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
slouken@1914
   212
    if (fsaa) {
slouken@1914
   213
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
slouken@1914
   214
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
slouken@1914
   215
    }
slouken@1914
   216
    if (accel) {
slouken@1914
   217
        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
slouken@1914
   218
    }
slouken@1915
   219
    if (!CommonInit(state)) {
slouken@1915
   220
        quit(2);
slouken@1914
   221
    }
slouken@1915
   222
slouken@1915
   223
    /* Create OpenGL context */
slouken@1915
   224
    context = SDL_GL_CreateContext(state->windows[0]);
slouken@1915
   225
    if (!context) {
slouken@1915
   226
        fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
slouken@1915
   227
        quit(2);
slouken@1915
   228
    }
slouken@1915
   229
slouken@1965
   230
    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
slouken@1914
   231
        SDL_GL_SetSwapInterval(1);
slouken@1914
   232
    } else {
slouken@1914
   233
        SDL_GL_SetSwapInterval(0);
slouken@1914
   234
    }
slouken@1914
   235
slouken@1967
   236
    SDL_GetCurrentDisplayMode(&mode);
slouken@1967
   237
    printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
slouken@1914
   238
    printf("\n");
slouken@1914
   239
    printf("Vendor     : %s\n", glGetString(GL_VENDOR));
slouken@1914
   240
    printf("Renderer   : %s\n", glGetString(GL_RENDERER));
slouken@1914
   241
    printf("Version    : %s\n", glGetString(GL_VERSION));
slouken@1914
   242
    printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
slouken@1914
   243
    printf("\n");
slouken@1914
   244
slouken@3099
   245
    status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
slouken@3099
   246
    if (!status) {
slouken@3099
   247
        printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   248
    } else {
slouken@3099
   249
        printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
slouken@3099
   250
    }
slouken@3099
   251
    status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
slouken@3099
   252
    if (!status) {
slouken@3099
   253
        printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   254
    } else {
slouken@3099
   255
        printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
slouken@3099
   256
    }
slouken@3099
   257
    status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
slouken@3099
   258
    if (!status) {
slouken@3099
   259
        printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
slouken@3099
   260
    } else {
slouken@3099
   261
        printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
slouken@3099
   262
    }
slouken@3099
   263
    status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
slouken@3099
   264
    if (!status) {
slouken@3099
   265
        printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
slouken@3099
   266
    } else {
slouken@3099
   267
        printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
slouken@3099
   268
    }
slouken@1914
   269
    if (fsaa) {
slouken@3099
   270
        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
slouken@3099
   271
        if (!status) {
slouken@3099
   272
            printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
slouken@3099
   273
        } else {
slouken@3099
   274
            printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
slouken@3099
   275
        }
slouken@3099
   276
        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
slouken@3099
   277
        if (!status) {
slouken@3099
   278
            printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value);
slouken@3099
   279
        } else {
slouken@3099
   280
            printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
slouken@3099
   281
        }
slouken@1914
   282
    }
slouken@1914
   283
    if (accel) {
slouken@3099
   284
        status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
slouken@3099
   285
        if (!status)
slouken@3099
   286
        {
slouken@3099
   287
            printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
slouken@3099
   288
        } else {
slouken@3099
   289
            printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
slouken@3099
   290
        }
slouken@1914
   291
    }
slouken@1915
   292
slouken@1915
   293
    /* Set rendering settings */
slouken@1915
   294
    glMatrixMode(GL_PROJECTION);
slouken@1915
   295
    glLoadIdentity();
slouken@1915
   296
    glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
slouken@1915
   297
    glMatrixMode(GL_MODELVIEW);
slouken@1915
   298
    glLoadIdentity();
slouken@1915
   299
    glEnable(GL_DEPTH_TEST);
slouken@1915
   300
    glDepthFunc(GL_LESS);
slouken@1915
   301
    glShadeModel(GL_SMOOTH);
slouken@1915
   302
slouken@1915
   303
    /* Main render loop */
slouken@1915
   304
    frames = 0;
slouken@1915
   305
    then = SDL_GetTicks();
slouken@1915
   306
    done = 0;
slouken@1915
   307
    while (!done) {
slouken@1915
   308
        /* Check for events */
slouken@1915
   309
        ++frames;
slouken@1915
   310
        while (SDL_PollEvent(&event)) {
slouken@1915
   311
            CommonEvent(state, &event, &done);
slouken@1915
   312
        }
slouken@1915
   313
        for (i = 0; i < state->num_windows; ++i) {
slouken@1915
   314
            int w, h;
slouken@1915
   315
            SDL_GL_MakeCurrent(state->windows[i], context);
slouken@1915
   316
            SDL_GetWindowSize(state->windows[i], &w, &h);
slouken@1915
   317
            glViewport(0, 0, w, h);
slouken@1915
   318
            Render();
slouken@1915
   319
            SDL_GL_SwapWindow(state->windows[i]);
slouken@1915
   320
        }
slouken@1914
   321
    }
slouken@1914
   322
slouken@1915
   323
    /* Print out some timing information */
slouken@1915
   324
    now = SDL_GetTicks();
slouken@1915
   325
    if (now > then) {
slouken@1915
   326
        printf("%2.2f frames per second\n",
slouken@1915
   327
               ((double) frames * 1000) / (now - then));
slouken@1914
   328
    }
slouken@1915
   329
    quit(0);
slouken@2232
   330
    return 0;
slouken@1914
   331
}
slouken@1914
   332
slouken@1914
   333
#else /* HAVE_OPENGL */
slouken@1914
   334
slouken@1914
   335
int
slouken@1914
   336
main(int argc, char *argv[])
slouken@1914
   337
{
slouken@1914
   338
    printf("No OpenGL support on this system\n");
slouken@1914
   339
    return 1;
slouken@1914
   340
}
slouken@1914
   341
slouken@1914
   342
#endif /* HAVE_OPENGL */