test/testgles2.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Aug 2016 19:59:00 -0400
changeset 10266 c09f06c4e8c8
parent 9998 f67cf37e9cd4
permissions -rw-r--r--
emscripten: send fake mouse events for touches, like other targets do. (This really should be handled at the higher level and not in the individual targets, but this fixes the immediate bug.)
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
/*
9998
f67cf37e9cd4 Updated copyright to 2016
Sam Lantinga <slouken@libsdl.org>
parents: 9966
diff changeset
     2
  Copyright (r) 1997-2016 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
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
    17
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
    18
#include <emscripten/emscripten.h>
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
    19
#endif
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
    20
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    21
#include "SDL_test_common.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    22
9606
ec24a5add229 Fixed compiling test program with Emscripten.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9278
diff changeset
    23
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__)
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    24
#define HAVE_OPENGLES2
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    25
#endif
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
#ifdef HAVE_OPENGLES2
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
#include "SDL_opengles2.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    30
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    31
typedef struct GLES2_Context
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    32
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    33
#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
    34
#include "../src/render/opengles2/SDL_gles2funcs.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    35
#undef SDL_PROC
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    36
} GLES2_Context;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    37
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    38
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    39
static SDLTest_CommonState *state;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    40
static SDL_GLContext *context = NULL;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    41
static int depth = 16;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    42
static GLES2_Context ctx;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    43
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    44
static int LoadContext(GLES2_Context * data)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    45
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    46
#if SDL_VIDEO_DRIVER_UIKIT
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
#elif SDL_VIDEO_DRIVER_ANDROID
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    49
#define __SDL_NOGETPROCADDR__
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    50
#elif SDL_VIDEO_DRIVER_PANDORA
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    51
#define __SDL_NOGETPROCADDR__
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    52
#endif
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    53
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    54
#if defined __SDL_NOGETPROCADDR__
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    55
#define SDL_PROC(ret,func,params) data->func=func;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    56
#else
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    57
#define SDL_PROC(ret,func,params) \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    58
    do { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    59
        data->func = SDL_GL_GetProcAddress(#func); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    60
        if ( ! data->func ) { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    61
            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
    62
        } \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    63
    } while ( 0 );
9966
cae9c97fabbd Fixed a comment in two test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9922
diff changeset
    64
#endif /* __SDL_NOGETPROCADDR__ */
8021
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
#include "../src/render/opengles2/SDL_gles2funcs.h"
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    67
#undef SDL_PROC
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    68
    return 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    69
}
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
/* 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
    72
static void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    73
quit(int rc)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    74
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    75
    int i;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    76
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    77
    if (context != NULL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    78
        for (i = 0; i < state->num_windows; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    79
            if (context[i]) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    80
                SDL_GL_DeleteContext(context[i]);
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
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    84
        SDL_free(context);
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
    SDLTest_CommonQuit(state);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    88
    exit(rc);
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
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    91
#define GL_CHECK(x) \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    92
        x; \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    93
        { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    94
          GLenum glError = ctx.glGetError(); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    95
          if(glError != GL_NO_ERROR) { \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    96
            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
    97
            quit(1); \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    98
          } \
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
    99
        }
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
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   102
 * 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
   103
 * order. 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   104
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   105
static void
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   106
rotate_matrix(float angle, float x, float y, float z, float *r)
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   107
{
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   108
    float radians, c, s, c1, u[3], length;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   109
    int i, j;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   110
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   111
    radians = (float)(angle * M_PI) / 180.0f;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   112
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   113
    c = SDL_cosf(radians);
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   114
    s = SDL_sinf(radians);
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   115
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   116
    c1 = 1.0f - SDL_cosf(radians);
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   117
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   118
    length = (float)SDL_sqrt(x * x + y * y + z * z);
8021
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
    u[0] = x / length;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   121
    u[1] = y / length;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   122
    u[2] = z / length;
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
    for (i = 0; i < 16; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   125
        r[i] = 0.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   126
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   127
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   128
    r[15] = 1.0;
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
    for (i = 0; i < 3; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   131
        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
   132
        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
   133
    }
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
    for (i = 0; i < 3; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   136
        for (j = 0; j < 3; j++) {
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   137
            r[i * 4 + j] += c1 * u[i] * u[j] + (i == j ? c : 0.0f);
8021
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
    }
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
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   142
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   143
 * Simulates gluPerspectiveMatrix 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   144
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   145
static void 
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   146
perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   147
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   148
    int i;
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   149
    float f;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   150
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   151
    f = 1.0f/SDL_tanf(fovy * 0.5f);
8021
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
    for (i = 0; i < 16; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   154
        r[i] = 0.0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   155
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   156
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   157
    r[0] = f / aspect;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   158
    r[5] = f;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   159
    r[10] = (znear + zfar) / (znear - zfar);
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   160
    r[11] = -1.0f;
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   161
    r[14] = (2.0f * znear * zfar) / (znear - zfar);
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   162
    r[15] = 0.0f;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   163
}
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
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   166
 * 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
   167
 * major. In-place multiplication is supported.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   168
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   169
static void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   170
multiply_matrix(float *lhs, float *rhs, float *r)
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   171
{
9922
b066d5fd5fa7 Replaced tabs with spaces in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9619
diff changeset
   172
    int i, j, k;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   173
    float tmp[16];
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 (i = 0; i < 4; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   176
        for (j = 0; j < 4; j++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   177
            tmp[j * 4 + i] = 0.0;
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
            for (k = 0; k < 4; k++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   180
                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
   181
            }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   182
        }
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
    for (i = 0; i < 16; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   186
        r[i] = tmp[i];
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   187
    }
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
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   190
/* 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   191
 * 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
   192
 *
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   193
 * shader: Pointer to return created shader ID.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   194
 * source: Passed-in shader source code.
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   195
 * 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
   196
 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   197
void 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   198
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
   199
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   200
    GLint status = GL_FALSE;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   201
    const char *shaders[1] = { NULL };
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8776
diff changeset
   202
    char buffer[1024];
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8776
diff changeset
   203
    GLsizei length;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   204
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   205
    /* Create shader and load into GL. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   206
    *shader = GL_CHECK(ctx.glCreateShader(shader_type));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   207
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   208
    shaders[0] = source;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   209
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   210
    GL_CHECK(ctx.glShaderSource(*shader, 1, shaders, NULL));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   211
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   212
    /* Clean up shader source. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   213
    shaders[0] = NULL;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   214
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   215
    /* Try compiling the shader. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   216
    GL_CHECK(ctx.glCompileShader(*shader));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   217
    GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   218
8776
29aac8b813d9 Changed C++ style comments to fix pedantic warnings.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 8226
diff changeset
   219
    /* Dump debug info (source and log) if compilation failed. */
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   220
    if(status != GL_TRUE) {
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8776
diff changeset
   221
        ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8776
diff changeset
   222
        buffer[length] = '\0';
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8776
diff changeset
   223
        SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   224
        quit(-1);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   225
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   226
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   227
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   228
/* 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
   229
* Z -0.5 is near, 0.5 is far. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   230
const float _vertices[] =
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   231
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   232
    /* Front face. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   233
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   234
    -0.5,  0.5, -0.5,
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
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   238
    -0.5,  0.5, -0.5,
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
    /* Left face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   242
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   243
    -0.5,  0.5,  0.5,
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
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   247
    -0.5,  0.5,  0.5,
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
    /* Top face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   251
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   252
    -0.5,  0.5,  0.5,
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
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   256
    -0.5,  0.5,  0.5,
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
    /* Right face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   260
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   261
    0.5,  0.5, -0.5,
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
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   265
    0.5,  0.5, -0.5,
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
    /* Back face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   269
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   270
    0.5,  0.5,  0.5,
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
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   274
    0.5,  0.5,  0.5,
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
    /* Bottom face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   278
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   279
    -0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   280
    0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   281
    -0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   282
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   283
    -0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   284
    0.5, -0.5, -0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   285
    0.5, -0.5,  0.5,
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   286
};
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   287
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   288
const float _colors[] =
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   289
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   290
    /* Front face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   291
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   292
    1.0, 0.0, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   293
    0.0, 0.0, 1.0, /* blue */
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
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   296
    1.0, 0.0, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   297
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   298
    0.0, 0.0, 1.0, /* blue */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   299
    /* Left face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   300
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   301
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   302
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   303
    0.0, 1.0, 1.0, /* cyan */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   304
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   305
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   306
    1.0, 0.0, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   307
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   308
    /* Top face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   309
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   310
    1.0, 1.0, 1.0, /* white */
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, 0.0, /* red */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   313
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   314
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   315
    0.0, 0.0, 0.0, /* black */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   316
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   317
    /* Right face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   318
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   319
    1.0, 1.0, 0.0, /* yellow */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   320
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   321
    0.0, 0.0, 1.0, /* blue */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   322
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   323
    1.0, 1.0, 0.0, /* yellow */
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, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   326
    /* Back face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   327
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   328
    0.0, 0.0, 0.0, /* black */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   329
    0.0, 1.0, 1.0, /* cyan */
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
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   332
    0.0, 0.0, 0.0, /* black */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   333
    1.0, 1.0, 1.0, /* white */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   334
    0.0, 1.0, 1.0, /* cyan */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   335
    /* Bottom face */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   336
    /* Bottom left */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   337
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   338
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   339
    0.0, 1.0, 1.0, /* cyan */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   340
    /* Top right */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   341
    0.0, 1.0, 0.0, /* green */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   342
    0.0, 0.0, 1.0, /* blue */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   343
    1.0, 0.0, 1.0, /* magenta */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   344
};
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   345
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   346
const char* _shader_vert_src = 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   347
" attribute vec4 av4position; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   348
" attribute vec3 av3color; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   349
" uniform mat4 mvp; "
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
"    vv3color = av3color; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   353
"    gl_Position = mvp * av4position; "
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
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   356
const char* _shader_frag_src = 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   357
" precision lowp float; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   358
" varying vec3 vv3color; "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   359
" void main() { "
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   360
"    gl_FragColor = vec4(vv3color, 1.0); "
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
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   363
typedef struct shader_data
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   364
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   365
    GLuint shader_program, shader_frag, shader_vert;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   366
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   367
    GLint attr_position;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   368
    GLint attr_color, attr_mvp;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   369
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   370
    int angle_x, angle_y, angle_z;
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
} shader_data;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   373
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   374
static void
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   375
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
   376
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   377
    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
   378
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
    * 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
   381
    * quaterions would be, but the effect is cool. 
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   382
    */
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   383
    rotate_matrix((float)data->angle_x, 1.0f, 0.0f, 0.0f, matrix_modelview);
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   384
    rotate_matrix((float)data->angle_y, 0.0f, 1.0f, 0.0f, matrix_rotate);
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   385
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   386
    multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   387
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   388
    rotate_matrix((float)data->angle_z, 0.0f, 1.0f, 0.0f, matrix_rotate);
8021
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
    multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
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
    /* Pull the camera back from the cube */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   393
    matrix_modelview[14] -= 2.5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   394
8841
b7f41b4a7929 Fixed compile warnings
Sam Lantinga <slouken@libsdl.org>
parents: 8833
diff changeset
   395
    perspective_matrix(45.0f, (float)width/height, 0.01f, 100.0f, matrix_perspective);
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   396
    multiply_matrix(matrix_perspective, matrix_modelview, matrix_mvp);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   397
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   398
    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
   399
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   400
    data->angle_x += 3;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   401
    data->angle_y += 2;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   402
    data->angle_z += 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   403
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   404
    if(data->angle_x >= 360) data->angle_x -= 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   405
    if(data->angle_x < 0) data->angle_x += 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   406
    if(data->angle_y >= 360) data->angle_y -= 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   407
    if(data->angle_y < 0) data->angle_y += 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   408
    if(data->angle_z >= 360) data->angle_z -= 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   409
    if(data->angle_z < 0) data->angle_z += 360;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   410
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   411
    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
   412
    GL_CHECK(ctx.glDrawArrays(GL_TRIANGLES, 0, 36));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   413
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   414
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   415
int done;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   416
Uint32 frames;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   417
shader_data *datas;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   418
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   419
void loop()
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   420
{
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   421
    SDL_Event event;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   422
    int i;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   423
    int status;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   424
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   425
    /* Check for events */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   426
    ++frames;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   427
    while (SDL_PollEvent(&event) && !done) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   428
        switch (event.type) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   429
        case SDL_WINDOWEVENT:
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   430
            switch (event.window.event) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   431
                case SDL_WINDOWEVENT_RESIZED:
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   432
                    for (i = 0; i < state->num_windows; ++i) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   433
                        if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   434
                            int w, h;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   435
                            status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   436
                            if (status) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   437
                                SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   438
                                break;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   439
                            }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   440
                            /* Change view port to the new window dimensions */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   441
                            SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   442
                            ctx.glViewport(0, 0, w, h);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   443
                            state->window_w = event.window.data1;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   444
                            state->window_h = event.window.data2;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   445
                            /* Update window content */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   446
                            Render(event.window.data1, event.window.data2, &datas[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   447
                            SDL_GL_SwapWindow(state->windows[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   448
                            break;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   449
                        }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   450
                    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   451
                    break;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   452
            }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   453
        }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   454
        SDLTest_CommonEvent(state, &event, &done);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   455
    }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   456
    if (!done) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   457
      for (i = 0; i < state->num_windows; ++i) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   458
          status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   459
          if (status) {
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   460
              SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   461
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   462
              /* Continue for next window */
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   463
              continue;
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   464
          }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   465
          Render(state->window_w, state->window_h, &datas[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   466
          SDL_GL_SwapWindow(state->windows[i]);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   467
      }
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   468
    }
9607
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9606
diff changeset
   469
#ifdef __EMSCRIPTEN__
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9606
diff changeset
   470
    else {
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9606
diff changeset
   471
        emscripten_cancel_main_loop();
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9606
diff changeset
   472
    }
7746ab058d12 Added missing loop cancel for Emscripten in test programs.
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 9606
diff changeset
   473
#endif
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   474
}
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   475
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   476
int
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   477
main(int argc, char *argv[])
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   478
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   479
    int fsaa, accel;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   480
    int value;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   481
    int i;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   482
    SDL_DisplayMode mode;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   483
    Uint32 then, now;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   484
    int status;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   485
    shader_data *data;
8021
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
    /* Initialize parameters */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   488
    fsaa = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   489
    accel = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   490
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   491
    /* Initialize test framework */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   492
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   493
    if (!state) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   494
        return 1;
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
    for (i = 1; i < argc;) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   497
        int consumed;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   498
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   499
        consumed = SDLTest_CommonArg(state, i);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   500
        if (consumed == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   501
            if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   502
                ++fsaa;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   503
                consumed = 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   504
            } else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   505
                ++accel;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   506
                consumed = 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   507
            } else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   508
                i++;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   509
                if (!argv[i]) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   510
                    consumed = -1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   511
                } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   512
                    depth = SDL_atoi(argv[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   513
                    consumed = 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   514
                }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   515
            } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   516
                consumed = -1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   517
            }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   518
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   519
        if (consumed < 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   520
            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
   521
                    SDLTest_CommonUsage(state));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   522
            quit(1);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   523
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   524
        i += consumed;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   525
    }
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
    /* Set OpenGL parameters */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   528
    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
   529
    state->gl_red_size = 5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   530
    state->gl_green_size = 5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   531
    state->gl_blue_size = 5;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   532
    state->gl_depth_size = depth;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   533
    state->gl_major_version = 2;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   534
    state->gl_minor_version = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   535
    state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   536
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   537
    if (fsaa) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   538
        state->gl_multisamplebuffers=1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   539
        state->gl_multisamplesamples=fsaa;
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
    if (accel) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   542
        state->gl_accelerated=1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   543
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   544
    if (!SDLTest_CommonInit(state)) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   545
        quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   546
        return 0;
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
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   549
    context = SDL_calloc(state->num_windows, sizeof(context));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   550
    if (context == NULL) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   551
        SDL_Log("Out of memory!\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   552
        quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   553
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   554
    
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   555
    /* Create OpenGL ES contexts */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   556
    for (i = 0; i < state->num_windows; i++) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   557
        context[i] = SDL_GL_CreateContext(state->windows[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   558
        if (!context[i]) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   559
            SDL_Log("SDL_GL_CreateContext(): %s\n", SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   560
            quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   561
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   562
    }
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
    /* Important: call this *after* creating the context */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   565
    if (LoadContext(&ctx) < 0) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   566
        SDL_Log("Could not load GLES2 functions\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   567
        quit(2);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   568
        return 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   569
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   570
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   571
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
    if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   574
        SDL_GL_SetSwapInterval(1);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   575
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   576
        SDL_GL_SetSwapInterval(0);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   577
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   578
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   579
    SDL_GetCurrentDisplayMode(0, &mode);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   580
    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
   581
    SDL_Log("\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   582
    SDL_Log("Vendor     : %s\n", ctx.glGetString(GL_VENDOR));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   583
    SDL_Log("Renderer   : %s\n", ctx.glGetString(GL_RENDERER));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   584
    SDL_Log("Version    : %s\n", ctx.glGetString(GL_VERSION));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   585
    SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   586
    SDL_Log("\n");
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   587
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   588
    status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   589
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   590
        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
   591
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   592
        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
   593
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   594
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   595
    status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   596
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   597
        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
   598
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   599
        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
   600
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   601
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   602
    status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   603
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   604
        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
   605
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   606
        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
   607
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   608
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   609
    status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   610
    if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   611
        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
   612
    } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   613
        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
   614
                SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   615
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   616
    if (fsaa) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   617
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   618
        if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   619
            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
   620
        } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   621
            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
   622
                    SDL_GetError());
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
        status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   625
        if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   626
            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
   627
                   value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   628
        } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   629
            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
   630
                    SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   631
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   632
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   633
    if (accel) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   634
        status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   635
        if (!status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   636
            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
   637
        } else {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   638
            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
   639
                    SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   640
        }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   641
    }
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   642
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   643
    datas = SDL_calloc(state->num_windows, sizeof(shader_data));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   644
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   645
    /* Set rendering settings for each context */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   646
    for (i = 0; i < state->num_windows; ++i) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   647
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   648
        int w, h;
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   649
        status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   650
        if (status) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   651
            SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   652
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   653
            /* Continue for next window */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   654
            continue;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   655
        }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   656
        SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   657
        ctx.glViewport(0, 0, w, h);
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   658
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   659
        data = &datas[i];
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   660
        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
   661
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   662
        /* Shader Initialization */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   663
        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
   664
        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
   665
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   666
        /* Create shader_program (ready to attach shaders) */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   667
        data->shader_program = GL_CHECK(ctx.glCreateProgram());
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   668
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   669
        /* Attach shaders and link shader_program */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   670
        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
   671
        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
   672
        GL_CHECK(ctx.glLinkProgram(data->shader_program));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   673
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   674
        /* 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
   675
        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
   676
        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
   677
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   678
        /* Get uniform locations */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   679
        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
   680
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   681
        GL_CHECK(ctx.glUseProgram(data->shader_program));
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
        /* Enable attributes for position, color and texture coordinates etc. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   684
        GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_position));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   685
        GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   686
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   687
        /* Populate attributes for position, color and texture coordinates etc. */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   688
        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
   689
        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
   690
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   691
        GL_CHECK(ctx.glEnable(GL_CULL_FACE));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   692
        GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   693
    }
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
    /* Main render loop */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   696
    frames = 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   697
    then = SDL_GetTicks();
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   698
    done = 0;
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   699
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   700
#ifdef __EMSCRIPTEN__
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   701
    emscripten_set_main_loop(loop, 0, 1);
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   702
#else
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   703
    while (!done) {
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   704
        loop();
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   705
    }
9278
8900afb78a19 Initial merge of Emscripten port!
Ryan C. Gordon <icculus@icculus.org>
parents: 8841
diff changeset
   706
#endif
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   707
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   708
    /* Print out some timing information */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   709
    now = SDL_GetTicks();
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   710
    if (now > then) {
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   711
        SDL_Log("%2.2f frames per second\n",
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   712
               ((double) frames * 1000) / (now - then));
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   713
    }
8833
ae720d61d14d Chrome's Native Client backend implementation
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8776
diff changeset
   714
#if !defined(__ANDROID__) && !defined(__NACL__)  
8021
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   715
    quit(0);
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   716
#endif    
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   717
    return 0;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   718
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   719
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   720
#else /* HAVE_OPENGLES2 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   721
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   722
int
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   723
main(int argc, char *argv[])
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   724
{
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   725
    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
   726
    return 1;
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   727
}
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   728
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   729
#endif /* HAVE_OPENGLES2 */
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   730
f96e12e0ade9 OpenGL ES support for Windows
Gabriel Jacobo <gabomdq@gmail.com>
parents: 8014
diff changeset
   731
/* vi: set ts=4 sw=4 expandtab: */