test/testgles.c
author Mike Gorchak <lestat@i.com.ua>
Tue, 28 Apr 2009 04:38:51 +0000
changeset 3110 e6c21c14ce3a
parent 3099 82e60908fab1
child 3139 7f684f249ec9
permissions -rw-r--r--
Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
#include <stdlib.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
#include <stdio.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
#include <string.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
#include <math.h>
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
#include "common.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
#ifdef __IPHONEOS__
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
#define HAVE_OPENGLES
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
#endif
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
#ifdef HAVE_OPENGLES
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
#include "SDL_opengles.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
static CommonState *state;
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    17
static SDL_GLContext *context=NULL;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
static void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
quit(int rc)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
{
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    23
    int i;
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    24
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    25
    if (context!=NULL)
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    26
    {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    27
        for (i=0; i<state->num_windows; i++)
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    28
        {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    29
            if (context[i]) {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    30
                SDL_GL_DeleteContext(context[i]);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    31
            }
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    32
        }
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    33
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    34
        SDL_free(context);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
    }
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
    36
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
    CommonQuit(state);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
    exit(rc);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
static void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
Render()
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
{
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
    static GLubyte color[8][4] = { {255, 0, 0, 0},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
    {255, 0, 0, 255},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
    {0, 255, 0, 255},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
    {0, 255, 0, 255},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
    {0, 255, 0, 255},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
    {255, 255, 255, 255},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
    {255, 0, 255, 255},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
    {0, 0, 255, 255}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
    };
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
    static GLfloat cube[8][3] = { {0.5, 0.5, -0.5},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
    {0.5f, -0.5f, -0.5f},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
    {-0.5f, -0.5f, -0.5f},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
    {-0.5f, 0.5f, -0.5f},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    {-0.5f, 0.5f, 0.5f},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
    {0.5f, 0.5f, 0.5f},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
    {0.5f, -0.5f, 0.5f},
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
    {-0.5f, -0.5f, 0.5f}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
    };
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
    static GLubyte indices[36] = { 0, 3, 4,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
        4, 5, 0,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
        0, 5, 6,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
        6, 1, 0,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
        6, 7, 2,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
        2, 1, 6,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
        7, 4, 3,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
        3, 2, 7,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
        5, 4, 7,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
        7, 6, 5,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
        2, 3, 1,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
        3, 0, 1
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    };
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
    /* Do our drawing, too. */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    glClearColor(0.0, 0.0, 0.0, 1.0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
    /* Draw the cube */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, color);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
    glEnableClientState(GL_COLOR_ARRAY);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    glVertexPointer(3, GL_FLOAT, 0, cube);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    glEnableClientState(GL_VERTEX_ARRAY);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    glMatrixMode(GL_MODELVIEW);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    glRotatef(5.0, 1.0, 1.0, 1.0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
main(int argc, char *argv[])
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
{
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
    int fsaa, accel;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
    int value;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
    int i, done;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
    SDL_DisplayMode mode;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
    SDL_Event event;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    Uint32 then, now, frames;
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   101
    int status;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
    /* Initialize parameters */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
    fsaa = 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
    accel = 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    /* Initialize test framework */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
    state = CommonCreateState(argv, SDL_INIT_VIDEO);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
    if (!state) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
        return 1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
    for (i = 1; i < argc;) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
        int consumed;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
        consumed = CommonArg(state, i);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
        if (consumed == 0) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
                ++fsaa;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
                consumed = 1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
                ++accel;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
                consumed = 1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
            } else {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
                consumed = -1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
            }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
        }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
        if (consumed < 0) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
            fprintf(stderr, "Usage: %s %s [--fsaa] [--accel]\n", argv[0],
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
                    CommonUsage(state));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
            quit(1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
        }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
        i += consumed;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
    /* Set OpenGL parameters */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
    state->window_flags |= SDL_WINDOW_OPENGL;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
    if (fsaa) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    if (accel) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
    if (!CommonInit(state)) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
        quit(2);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   152
    context=SDL_calloc(state->num_windows, sizeof(SDL_GLContext));
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   153
    if (context==NULL)
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   154
    {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   155
       fprintf(stderr, "Out of memory!\n");
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   156
       quit(2);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   157
    }
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   158
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   159
    /* Create OpenGL ES contexts */
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   160
    for (i=0; i<state->num_windows; i++)
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   161
    {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   162
        context[i] = SDL_GL_CreateContext(state->windows[i]);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   163
        if (!context[i]) {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   164
            fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   165
            quit(2);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   166
        }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
        SDL_GL_SetSwapInterval(1);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
    } else {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
        SDL_GL_SetSwapInterval(0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
    SDL_GetCurrentDisplayMode(&mode);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    printf("\n");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
    printf("Vendor     : %s\n", glGetString(GL_VENDOR));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
    printf("Renderer   : %s\n", glGetString(GL_RENDERER));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
    printf("Version    : %s\n", glGetString(GL_VERSION));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
    printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
    printf("\n");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   184
    status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   185
    if (!status) {
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   186
        printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   187
    } else {
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   188
        fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   189
    }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   190
    status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   191
    if (!status) {
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   192
        printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   193
    } else {
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   194
        fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   195
    }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   196
    status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   197
    if (!status) {
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   198
        printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   199
    } else {
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   200
        fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   201
    }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   202
    status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   203
    if (!status) {
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   204
        printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   205
    } else {
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   206
        fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   207
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    if (fsaa) {
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   209
        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   210
        if (!status) {
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   211
            printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   212
        } else {
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   213
            fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   214
        }
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   215
        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   216
        if (!status) {
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   217
            printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   218
        } else {
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   219
            fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   220
        }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
    if (accel) {
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   223
        status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   224
        if (!status)
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   225
        {
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   226
            printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   227
        } else {
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   228
            fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
3099
82e60908fab1 Date: Mon, 23 Mar 2009 09:17:24 +0200
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
   229
        }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   232
    /* Set rendering settings for each context */
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   233
    for (i = 0; i < state->num_windows; ++i) {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   234
        status=SDL_GL_MakeCurrent(state->windows[i], context[i]);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   235
        if (status)
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   236
        {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   237
            printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   238
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   239
            /* Continue for next window */
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   240
            continue;
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   241
        }
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   242
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   243
        glMatrixMode(GL_PROJECTION);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   244
        glLoadIdentity();
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   245
        glOrthof(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   246
        glMatrixMode(GL_MODELVIEW);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   247
        glLoadIdentity();
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   248
        glEnable(GL_DEPTH_TEST);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   249
        glDepthFunc(GL_LESS);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   250
        glShadeModel(GL_SMOOTH);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   251
    }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
    /* Main render loop */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
    frames = 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
    then = SDL_GetTicks();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
    done = 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
    while (!done) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
        /* Check for events */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
        ++frames;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
        while (SDL_PollEvent(&event)) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
            CommonEvent(state, &event, &done);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
        }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
        for (i = 0; i < state->num_windows; ++i) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
            int w, h;
3110
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   265
            status=SDL_GL_MakeCurrent(state->windows[i], context[i]);
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   266
            if (status)
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   267
            {
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   268
               printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   269
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   270
               /* Continue for next window */
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   271
               continue;
e6c21c14ce3a Added OpenGL ES context creation for the each window which has been created (for --windows=N option).
Mike Gorchak <lestat@i.com.ua>
parents: 3099
diff changeset
   272
            }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
            SDL_GetWindowSize(state->windows[i], &w, &h);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
            glViewport(0, 0, w, h);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
            Render();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
            SDL_GL_SwapWindow(state->windows[i]);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
        }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
    /* Print out some timing information */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
    now = SDL_GetTicks();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
    if (now > then) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
        printf("%2.2f frames per second\n",
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
               ((double) frames * 1000) / (now - then));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
    }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
    quit(0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
    return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
#else /* HAVE_OPENGLES */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
main(int argc, char *argv[])
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
{
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
    printf("No OpenGL ES support on this system\n");
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
    return 1;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
}
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
#endif /* HAVE_OPENGLES */