test/testgles2.c
author Gabriel Jacobo <gabomdq@gmail.com>
Thu, 20 Feb 2014 16:12:11 -0300
changeset 8226 778fd6b223a6
parent 8149 681eb46b8ac4
child 8776 29aac8b813d9
permissions -rw-r--r--
Improve testgles2 exit behavior (useful on Android)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     1
/*
8149
681eb46b8ac4 Fixed bug 2374 - Update copyright for 2014...
Sam Lantinga <slouken@libsdl.org>
parents: 8027
diff changeset
     2
  Copyright (r) 1997-2014 Sam Lantinga <slouken@libsdl.org>
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     3
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     4
  This software is provided 'as-is', without any express or implied
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     5
  warranty.  In no event will the authors be held liable for any damages
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     6
  arising from the use of this software.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     7
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     8
  Permission is granted to anyone to use this software for any purpose,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
     9
  including commercial applications, and to alter it and redistribute it
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    10
  freely.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    11
*/
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    12
#include <stdlib.h>
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    13
#include <stdio.h>
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    14
#include <string.h>
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    15
#include <math.h>
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    16
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    17
#include "SDL_test_common.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    18
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    19
#if defined(__IPHONEOS__) || defined(__ANDROID__)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    20
#define HAVE_OPENGLES2
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    21
#endif
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    22
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    23
#ifdef HAVE_OPENGLES2
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    24
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    25
#include "SDL_opengles2.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    26
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    27
typedef struct GLES2_Context
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    28
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    29
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    30
#include "../src/render/opengles2/SDL_gles2funcs.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    31
#undef SDL_PROC
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    32
} GLES2_Context;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    33
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    34
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    35
static SDLTest_CommonState *state;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    36
static SDL_GLContext *context = NULL;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    37
static int depth = 16;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    38
static GLES2_Context ctx;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    39
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    40
static int LoadContext(GLES2_Context * data)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    41
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    42
#if SDL_VIDEO_DRIVER_UIKIT
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    43
#define __SDL_NOGETPROCADDR__
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    44
#elif SDL_VIDEO_DRIVER_ANDROID
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    45
#define __SDL_NOGETPROCADDR__
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    46
#elif SDL_VIDEO_DRIVER_PANDORA
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    47
#define __SDL_NOGETPROCADDR__
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    48
#endif
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    49
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    50
#if defined __SDL_NOGETPROCADDR__
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    51
#define SDL_PROC(ret,func,params) data->func=func;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    52
#else
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    53
#define SDL_PROC(ret,func,params) \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    54
    do { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    55
        data->func = SDL_GL_GetProcAddress(#func); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    56
        if ( ! data->func ) { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    57
            return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    58
        } \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    59
    } while ( 0 );
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    60
#endif /* _SDL_NOGETPROCADDR_ */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    61
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    62
#include "../src/render/opengles2/SDL_gles2funcs.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    63
#undef SDL_PROC
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    64
    return 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    65
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    66
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    67
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    68
static void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    69
quit(int rc)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    70
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    71
    int i;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    72
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    73
    if (context != NULL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    74
        for (i = 0; i < state->num_windows; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    75
            if (context[i]) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    76
                SDL_GL_DeleteContext(context[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    77
            }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    78
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    79
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    80
        SDL_free(context);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    81
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    82
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    83
    SDLTest_CommonQuit(state);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    84
    exit(rc);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    85
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    86
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    87
#define GL_CHECK(x) \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    88
        x; \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    89
        { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    90
          GLenum glError = ctx.glGetError(); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    91
          if(glError != GL_NO_ERROR) { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    92
            SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    93
            quit(1); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    94
          } \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    95
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    96
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    97
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    98
 * Simulates desktop's glRotatef. The matrix is returned in column-major 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    99
 * order. 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   100
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   101
static void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   102
rotate_matrix(double angle, double x, double y, double z, float *r)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   103
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   104
    double radians, c, s, c1, u[3], length;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   105
    int i, j;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   106
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   107
    radians = (angle * M_PI) / 180.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   108
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   109
    c = cos(radians);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   110
    s = sin(radians);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   111
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   112
    c1 = 1.0 - cos(radians);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   113
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   114
    length = sqrt(x * x + y * y + z * z);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   115
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   116
    u[0] = x / length;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   117
    u[1] = y / length;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   118
    u[2] = z / length;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   119
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   120
    for (i = 0; i < 16; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   121
        r[i] = 0.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   122
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   123
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   124
    r[15] = 1.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   125
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   126
    for (i = 0; i < 3; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   127
        r[i * 4 + (i + 1) % 3] = u[(i + 2) % 3] * s;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   128
        r[i * 4 + (i + 2) % 3] = -u[(i + 1) % 3] * s;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   129
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   130
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   131
    for (i = 0; i < 3; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   132
        for (j = 0; j < 3; j++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   133
            r[i * 4 + j] += c1 * u[i] * u[j] + (i == j ? c : 0.0);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   134
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   135
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   136
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   137
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   138
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   139
 * Simulates gluPerspectiveMatrix 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   140
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   141
static void 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   142
perspective_matrix(double fovy, double aspect, double znear, double zfar, float *r)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   143
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   144
    int i;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   145
    double f;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   146
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   147
    f = 1.0/tan(fovy * 0.5);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   148
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   149
    for (i = 0; i < 16; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   150
        r[i] = 0.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   151
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   152
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   153
    r[0] = f / aspect;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   154
    r[5] = f;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   155
    r[10] = (znear + zfar) / (znear - zfar);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   156
    r[11] = -1.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   157
    r[14] = (2.0 * znear * zfar) / (znear - zfar);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   158
    r[15] = 0.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   159
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   160
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   161
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   162
 * Multiplies lhs by rhs and writes out to r. All matrices are 4x4 and column
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   163
 * major. In-place multiplication is supported.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   164
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   165
static void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   166
multiply_matrix(float *lhs, float *rhs, float *r)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   167
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   168
	int i, j, k;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   169
    float tmp[16];
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   170
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   171
    for (i = 0; i < 4; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   172
        for (j = 0; j < 4; j++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   173
            tmp[j * 4 + i] = 0.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   174
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   175
            for (k = 0; k < 4; k++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   176
                tmp[j * 4 + i] += lhs[k * 4 + i] * rhs[j * 4 + k];
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   177
            }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   178
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   179
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   180
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   181
    for (i = 0; i < 16; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   182
        r[i] = tmp[i];
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   183
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   184
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   185
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   186
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   187
 * Create shader, load in source, compile, dump debug as necessary.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   188
 *
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   189
 * shader: Pointer to return created shader ID.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   190
 * source: Passed-in shader source code.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   191
 * shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   192
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   193
void 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   194
process_shader(GLuint *shader, const char * source, GLint shader_type)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   195
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   196
    GLint status = GL_FALSE;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   197
    const char *shaders[1] = { NULL };
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   198
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   199
    /* Create shader and load into GL. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   200
    *shader = GL_CHECK(ctx.glCreateShader(shader_type));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   201
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   202
    shaders[0] = source;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   203
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   204
    GL_CHECK(ctx.glShaderSource(*shader, 1, shaders, NULL));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   205
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   206
    /* Clean up shader source. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   207
    shaders[0] = NULL;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   208
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   209
    /* Try compiling the shader. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   210
    GL_CHECK(ctx.glCompileShader(*shader));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   211
    GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   212
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   213
    // Dump debug info (source and log) if compilation failed.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   214
    if(status != GL_TRUE) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   215
        SDL_Log("Shader compilation failed");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   216
        quit(-1);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   217
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   218
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   219
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   220
/* 3D data. Vertex range -0.5..0.5 in all axes.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   221
* Z -0.5 is near, 0.5 is far. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   222
const float _vertices[] =
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   223
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   224
    /* Front face. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   225
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   226
    -0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   227
    0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   228
    -0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   229
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   230
    -0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   231
    0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   232
    0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   233
    /* Left face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   234
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   235
    -0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   236
    -0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   237
    -0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   238
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   239
    -0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   240
    -0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   241
    -0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   242
    /* Top face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   243
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   244
    -0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   245
    0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   246
    -0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   247
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   248
    -0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   249
    0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   250
    0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   251
    /* Right face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   252
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   253
    0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   254
    0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   255
    0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   256
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   257
    0.5,  0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   258
    0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   259
    0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   260
    /* Back face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   261
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   262
    0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   263
    -0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   264
    0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   265
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   266
    0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   267
    -0.5,  0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   268
    -0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   269
    /* Bottom face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   270
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   271
    -0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   272
    0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   273
    -0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   274
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   275
    -0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   276
    0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   277
    0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   278
};
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   279
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   280
const float _colors[] =
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   281
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   282
    /* Front face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   283
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   284
    1.0, 0.0, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   285
    0.0, 0.0, 1.0, /* blue */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   286
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   287
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   288
    1.0, 0.0, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   289
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   290
    0.0, 0.0, 1.0, /* blue */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   291
    /* Left face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   292
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   293
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   294
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   295
    0.0, 1.0, 1.0, /* cyan */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   296
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   297
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   298
    1.0, 0.0, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   299
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   300
    /* Top face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   301
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   302
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   303
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   304
    1.0, 0.0, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   305
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   306
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   307
    0.0, 0.0, 0.0, /* black */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   308
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   309
    /* Right face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   310
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   311
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   312
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   313
    0.0, 0.0, 1.0, /* blue */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   314
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   315
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   316
    0.0, 0.0, 0.0, /* black */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   317
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   318
    /* Back face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   319
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   320
    0.0, 0.0, 0.0, /* black */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   321
    0.0, 1.0, 1.0, /* cyan */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   322
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   323
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   324
    0.0, 0.0, 0.0, /* black */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   325
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   326
    0.0, 1.0, 1.0, /* cyan */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   327
    /* Bottom face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   328
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   329
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   330
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   331
    0.0, 1.0, 1.0, /* cyan */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   332
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   333
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   334
    0.0, 0.0, 1.0, /* blue */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   335
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   336
};
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   337
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   338
const char* _shader_vert_src = 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   339
" attribute vec4 av4position; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   340
" attribute vec3 av3color; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   341
" uniform mat4 mvp; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   342
" varying vec3 vv3color; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   343
" void main() { "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   344
"    vv3color = av3color; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   345
"    gl_Position = mvp * av4position; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   346
" } ";
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   347
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   348
const char* _shader_frag_src = 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   349
" precision lowp float; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   350
" varying vec3 vv3color; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   351
" void main() { "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   352
"    gl_FragColor = vec4(vv3color, 1.0); "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   353
" } ";
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   354
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   355
typedef struct shader_data
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   356
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   357
    GLuint shader_program, shader_frag, shader_vert;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   358
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   359
    GLint attr_position;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   360
    GLint attr_color, attr_mvp;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   361
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   362
    int angle_x, angle_y, angle_z;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   363
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   364
} shader_data;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   365
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   366
static void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   367
Render(unsigned int width, unsigned int height, shader_data* data)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   368
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   369
    float matrix_rotate[16], matrix_modelview[16], matrix_perspective[16], matrix_mvp[16];
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   370
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   371
    /* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   372
    * Do some rotation with Euler angles. It is not a fixed axis as
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   373
    * quaterions would be, but the effect is cool. 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   374
    */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   375
    rotate_matrix(data->angle_x, 1.0, 0.0, 0.0, matrix_modelview);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   376
    rotate_matrix(data->angle_y, 0.0, 1.0, 0.0, matrix_rotate);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   377
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   378
    multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   379
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   380
    rotate_matrix(data->angle_z, 0.0, 1.0, 0.0, matrix_rotate);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   381
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   382
    multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   383
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   384
    /* Pull the camera back from the cube */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   385
    matrix_modelview[14] -= 2.5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   386
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   387
    perspective_matrix(45.0, (double)width/(double)height, 0.01, 100.0, matrix_perspective);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   388
    multiply_matrix(matrix_perspective, matrix_modelview, matrix_mvp);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   389
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   390
    GL_CHECK(ctx.glUniformMatrix4fv(data->attr_mvp, 1, GL_FALSE, matrix_mvp));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   391
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   392
    data->angle_x += 3;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   393
    data->angle_y += 2;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   394
    data->angle_z += 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   395
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   396
    if(data->angle_x >= 360) data->angle_x -= 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   397
    if(data->angle_x < 0) data->angle_x += 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   398
    if(data->angle_y >= 360) data->angle_y -= 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   399
    if(data->angle_y < 0) data->angle_y += 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   400
    if(data->angle_z >= 360) data->angle_z -= 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   401
    if(data->angle_z < 0) data->angle_z += 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   402
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   403
    GL_CHECK(ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   404
    GL_CHECK(ctx.glDrawArrays(GL_TRIANGLES, 0, 36));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   405
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   406
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   407
int
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   408
main(int argc, char *argv[])
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   409
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   410
    int fsaa, accel;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   411
    int value;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   412
    int i, done;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   413
    SDL_DisplayMode mode;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   414
    SDL_Event event;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   415
    Uint32 then, now, frames;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   416
    int status;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   417
    shader_data *datas, *data;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   418
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   419
    /* Initialize parameters */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   420
    fsaa = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   421
    accel = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   422
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   423
    /* Initialize test framework */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   424
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   425
    if (!state) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   426
        return 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   427
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   428
    for (i = 1; i < argc;) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   429
        int consumed;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   430
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   431
        consumed = SDLTest_CommonArg(state, i);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   432
        if (consumed == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   433
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   434
                ++fsaa;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   435
                consumed = 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   436
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   437
                ++accel;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   438
                consumed = 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   439
            } else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   440
                i++;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   441
                if (!argv[i]) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   442
                    consumed = -1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   443
                } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   444
                    depth = SDL_atoi(argv[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   445
                    consumed = 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   446
                }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   447
            } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   448
                consumed = -1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   449
            }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   450
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   451
        if (consumed < 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   452
            SDL_Log ("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   453
                    SDLTest_CommonUsage(state));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   454
            quit(1);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   455
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   456
        i += consumed;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   457
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   458
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   459
    /* Set OpenGL parameters */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   460
    state->window_flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   461
    state->gl_red_size = 5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   462
    state->gl_green_size = 5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   463
    state->gl_blue_size = 5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   464
    state->gl_depth_size = depth;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   465
    state->gl_major_version = 2;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   466
    state->gl_minor_version = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   467
    state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   468
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   469
    if (fsaa) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   470
        state->gl_multisamplebuffers=1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   471
        state->gl_multisamplesamples=fsaa;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   472
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   473
    if (accel) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   474
        state->gl_accelerated=1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   475
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   476
    if (!SDLTest_CommonInit(state)) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   477
        quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   478
        return 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   479
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   480
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   481
    context = SDL_calloc(state->num_windows, sizeof(context));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   482
    if (context == NULL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   483
        SDL_Log("Out of memory!\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   484
        quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   485
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   486
    
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   487
    /* Create OpenGL ES contexts */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   488
    for (i = 0; i < state->num_windows; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   489
        context[i] = SDL_GL_CreateContext(state->windows[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   490
        if (!context[i]) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   491
            SDL_Log("SDL_GL_CreateContext(): %s\n", SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   492
            quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   493
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   494
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   495
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   496
    /* Important: call this *after* creating the context */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   497
    if (LoadContext(&ctx) < 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   498
        SDL_Log("Could not load GLES2 functions\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   499
        quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   500
        return 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   501
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   502
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   503
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   504
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   505
    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   506
        SDL_GL_SetSwapInterval(1);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   507
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   508
        SDL_GL_SetSwapInterval(0);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   509
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   510
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   511
    SDL_GetCurrentDisplayMode(0, &mode);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   512
    SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   513
    SDL_Log("\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   514
    SDL_Log("Vendor     : %s\n", ctx.glGetString(GL_VENDOR));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   515
    SDL_Log("Renderer   : %s\n", ctx.glGetString(GL_RENDERER));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   516
    SDL_Log("Version    : %s\n", ctx.glGetString(GL_VERSION));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   517
    SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   518
    SDL_Log("\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   519
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   520
    status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   521
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   522
        SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   523
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   524
        SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   525
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   526
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   527
    status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   528
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   529
        SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   530
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   531
        SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   532
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   533
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   534
    status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   535
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   536
        SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   537
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   538
        SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   539
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   540
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   541
    status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   542
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   543
        SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   544
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   545
        SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   546
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   547
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   548
    if (fsaa) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   549
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   550
        if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   551
            SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   552
        } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   553
            SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   554
                    SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   555
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   556
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   557
        if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   558
            SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   559
                   value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   560
        } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   561
            SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   562
                    SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   563
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   564
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   565
    if (accel) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   566
        status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   567
        if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   568
            SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   569
        } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   570
            SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   571
                    SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   572
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   573
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   574
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   575
    datas = SDL_calloc(state->num_windows, sizeof(shader_data));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   576
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   577
    /* Set rendering settings for each context */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   578
    for (i = 0; i < state->num_windows; ++i) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   579
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   580
        status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   581
        if (status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   582
            SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   583
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   584
            /* Continue for next window */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   585
            continue;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   586
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   587
        ctx.glViewport(0, 0, state->window_w, state->window_h);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   588
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   589
        data = &datas[i];
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   590
        data->angle_x = 0; data->angle_y = 0; data->angle_z = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   591
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   592
        /* Shader Initialization */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   593
        process_shader(&data->shader_vert, _shader_vert_src, GL_VERTEX_SHADER);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   594
        process_shader(&data->shader_frag, _shader_frag_src, GL_FRAGMENT_SHADER);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   595
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   596
        /* Create shader_program (ready to attach shaders) */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   597
        data->shader_program = GL_CHECK(ctx.glCreateProgram());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   598
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   599
        /* Attach shaders and link shader_program */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   600
        GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   601
        GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   602
        GL_CHECK(ctx.glLinkProgram(data->shader_program));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   603
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   604
        /* Get attribute locations of non-fixed attributes like color and texture coordinates. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   605
        data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   606
        data->attr_color = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av3color"));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   607
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   608
        /* Get uniform locations */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   609
        data->attr_mvp = GL_CHECK(ctx.glGetUniformLocation(data->shader_program, "mvp"));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   610
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   611
        GL_CHECK(ctx.glUseProgram(data->shader_program));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   612
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   613
        /* Enable attributes for position, color and texture coordinates etc. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   614
        GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_position));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   615
        GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   616
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   617
        /* Populate attributes for position, color and texture coordinates etc. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   618
        GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, _vertices));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   619
        GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, _colors));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   620
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   621
        GL_CHECK(ctx.glEnable(GL_CULL_FACE));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   622
        GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   623
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   624
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   625
    /* Main render loop */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   626
    frames = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   627
    then = SDL_GetTicks();
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   628
    done = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   629
    while (!done) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   630
        /* Check for events */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   631
        ++frames;
8226
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   632
        while (SDL_PollEvent(&event) && !done) {
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   633
            switch (event.type) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   634
            case SDL_WINDOWEVENT:
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   635
                switch (event.window.event) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   636
                    case SDL_WINDOWEVENT_RESIZED:
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   637
                        for (i = 0; i < state->num_windows; ++i) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   638
                            if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   639
                                status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   640
                                if (status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   641
                                    SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   642
                                    break;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   643
                                }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   644
                                /* Change view port to the new window dimensions */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   645
                                ctx.glViewport(0, 0, event.window.data1, event.window.data2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   646
                                /* Update window content */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   647
                                Render(event.window.data1, event.window.data2, &datas[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   648
                                SDL_GL_SwapWindow(state->windows[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   649
                                break;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   650
                            }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   651
                        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   652
                        break;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   653
                }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   654
            }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   655
            SDLTest_CommonEvent(state, &event, &done);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   656
        }
8226
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   657
        if (!done) {
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   658
          for (i = 0; i < state->num_windows; ++i) {
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   659
              status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   660
              if (status) {
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   661
                  SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   662
8226
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   663
                  /* Continue for next window */
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   664
                  continue;
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   665
              }
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   666
              Render(state->window_w, state->window_h, &datas[i]);
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   667
              SDL_GL_SwapWindow(state->windows[i]);
778fd6b223a6 Improve testgles2 exit behavior (useful on Android)
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8149
diff changeset
   668
          }
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   669
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   670
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   671
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   672
    /* Print out some timing information */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   673
    now = SDL_GetTicks();
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   674
    if (now > then) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   675
        SDL_Log("%2.2f frames per second\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   676
               ((double) frames * 1000) / (now - then));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   677
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   678
#if !defined(__ANDROID__)    
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   679
    quit(0);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   680
#endif    
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   681
    return 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   682
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   683
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   684
#else /* HAVE_OPENGLES2 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   685
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   686
int
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   687
main(int argc, char *argv[])
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   688
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   689
    SDL_Log("No OpenGL ES support on this system\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   690
    return 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   691
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   692
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   693
#endif /* HAVE_OPENGLES2 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   694
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   695
/* vi: set ts=4 sw=4 expandtab: */