test/testshader.c
changeset 5232 74bc160186a8
child 5236 c7be6ca3a0b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testshader.c	Tue Feb 08 22:11:16 2011 -0800
     1.3 @@ -0,0 +1,483 @@
     1.4 +/* This is a simple example of using GLSL shaders with SDL */
     1.5 +
     1.6 +#include "SDL.h"
     1.7 +
     1.8 +#ifdef HAVE_OPENGL
     1.9 +
    1.10 +#include "SDL_opengl.h"
    1.11 +
    1.12 +
    1.13 +static SDL_bool shaders_supported;
    1.14 +static int      current_shader = 0;
    1.15 +
    1.16 +enum {
    1.17 +    SHADER_COLOR,
    1.18 +    SHADER_TEXTURE,
    1.19 +    SHADER_TEXCOORDS,
    1.20 +    NUM_SHADERS
    1.21 +};
    1.22 +
    1.23 +typedef struct {
    1.24 +    GLuint program;
    1.25 +    GLuint vert_shader;
    1.26 +    GLuint frag_shader;
    1.27 +    const char *vert_source;
    1.28 +    const char *frag_source;
    1.29 +} ShaderData;
    1.30 +
    1.31 +static ShaderData shaders[NUM_SHADERS] = {
    1.32 +
    1.33 +    /* SHADER_COLOR */
    1.34 +    { 0, 0, 0,
    1.35 +        /* vertex shader */
    1.36 +"varying vec4 v_color;\n"
    1.37 +"\n"
    1.38 +"void main()\n"
    1.39 +"{\n"
    1.40 +"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
    1.41 +"    v_color = gl_Color;\n"
    1.42 +"}",
    1.43 +        /* fragment shader */
    1.44 +"varying vec4 v_color;\n"
    1.45 +"\n"
    1.46 +"void main()\n"
    1.47 +"{\n"
    1.48 +"    gl_FragColor = v_color;\n"
    1.49 +"}"
    1.50 +    },
    1.51 +
    1.52 +    /* SHADER_TEXTURE */
    1.53 +    { 0, 0, 0,
    1.54 +        /* vertex shader */
    1.55 +"varying vec4 v_color;\n"
    1.56 +"varying vec2 v_texCoord;\n"
    1.57 +"\n"
    1.58 +"void main()\n"
    1.59 +"{\n"
    1.60 +"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
    1.61 +"    v_color = gl_Color;\n"
    1.62 +"    v_texCoord = vec2(gl_MultiTexCoord0);\n"
    1.63 +"}",
    1.64 +        /* fragment shader */
    1.65 +"varying vec4 v_color;\n"
    1.66 +"varying vec2 v_texCoord;\n"
    1.67 +"uniform sampler2D tex0;\n"
    1.68 +"\n"
    1.69 +"void main()\n"
    1.70 +"{\n"
    1.71 +"    gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
    1.72 +"}"
    1.73 +    },
    1.74 +
    1.75 +    /* SHADER_TEXCOORDS */
    1.76 +    { 0, 0, 0,
    1.77 +        /* vertex shader */
    1.78 +"varying vec2 v_texCoord;\n"
    1.79 +"\n"
    1.80 +"void main()\n"
    1.81 +"{\n"
    1.82 +"    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
    1.83 +"    v_texCoord = vec2(gl_MultiTexCoord0);\n"
    1.84 +"}",
    1.85 +        /* fragment shader */
    1.86 +"varying vec2 v_texCoord;\n"
    1.87 +"\n"
    1.88 +"void main()\n"
    1.89 +"{\n"
    1.90 +"    vec4 color;\n"
    1.91 +"    vec2 delta;\n"
    1.92 +"    float dist;\n"
    1.93 +"\n"
    1.94 +"    delta = vec2(0.5, 0.5) - v_texCoord;\n"
    1.95 +"    dist = dot(delta, delta);\n"
    1.96 +"\n"
    1.97 +"    color.r = v_texCoord.x;\n"
    1.98 +"    color.g = v_texCoord.x * v_texCoord.y;\n"
    1.99 +"    color.b = v_texCoord.y;\n"
   1.100 +"    color.a = 1.0 - (dist * 4.0);\n"
   1.101 +"    gl_FragColor = color;\n"
   1.102 +"}"
   1.103 +    },
   1.104 +};
   1.105 +    
   1.106 +static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
   1.107 +static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
   1.108 +static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
   1.109 +static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
   1.110 +static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
   1.111 +static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
   1.112 +static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
   1.113 +static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
   1.114 +static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
   1.115 +static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
   1.116 +static PFNGLUNIFORM1IARBPROC glUniform1iARB;
   1.117 +static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
   1.118 +
   1.119 +static SDL_bool CompileShader(GLenum shader, const char *source)
   1.120 +{
   1.121 +    GLint status;
   1.122 +
   1.123 +    glShaderSourceARB(shader, 1, &source, NULL);
   1.124 +    glCompileShaderARB(shader);
   1.125 +    glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
   1.126 +    if (status == 0) {
   1.127 +        GLint length;
   1.128 +        char *info;
   1.129 +
   1.130 +        glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
   1.131 +        info = SDL_stack_alloc(char, length+1);
   1.132 +        glGetInfoLogARB(shader, length, NULL, info);
   1.133 +        fprintf(stderr, "Failed to compile shader:\n%s\n%s", source, info);
   1.134 +        SDL_stack_free(info);
   1.135 +
   1.136 +        return SDL_FALSE;
   1.137 +    } else {
   1.138 +        return SDL_TRUE;
   1.139 +    }
   1.140 +}
   1.141 +
   1.142 +static SDL_bool CompileShaderProgram(ShaderData *data)
   1.143 +{
   1.144 +    const int num_tmus_bound = 4;
   1.145 +    int i;
   1.146 +    GLint location;
   1.147 +
   1.148 +    glGetError();
   1.149 +
   1.150 +    /* Create one program object to rule them all */
   1.151 +    data->program = glCreateProgramObjectARB();
   1.152 +
   1.153 +    /* Create the vertex shader */
   1.154 +    data->vert_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
   1.155 +    if (!CompileShader(data->vert_shader, data->vert_source)) {
   1.156 +        return SDL_FALSE;
   1.157 +    }
   1.158 +
   1.159 +    /* Create the fragment shader */
   1.160 +    data->frag_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
   1.161 +    if (!CompileShader(data->frag_shader, data->frag_source)) {
   1.162 +        return SDL_FALSE;
   1.163 +    }
   1.164 +
   1.165 +    /* ... and in the darkness bind them */
   1.166 +    glAttachObjectARB(data->program, data->vert_shader);
   1.167 +    glAttachObjectARB(data->program, data->frag_shader);
   1.168 +    glLinkProgramARB(data->program);
   1.169 +
   1.170 +    /* Set up some uniform variables */
   1.171 +    glUseProgramObjectARB(data->program);
   1.172 +    for (i = 0; i < num_tmus_bound; ++i) {
   1.173 +        char tex_name[5];
   1.174 +        SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
   1.175 +        location = glGetUniformLocationARB(data->program, tex_name);
   1.176 +        if (location >= 0) {
   1.177 +            glUniform1iARB(location, i);
   1.178 +        }
   1.179 +    }
   1.180 +    glUseProgramObjectARB(0);
   1.181 + 
   1.182 +    return (glGetError() == GL_NO_ERROR);
   1.183 +}
   1.184 +
   1.185 +static void DestroyShaderProgram(ShaderData *data)
   1.186 +{
   1.187 +    glDeleteObjectARB(data->vert_shader);
   1.188 +    glDeleteObjectARB(data->frag_shader);
   1.189 +    glDeleteObjectARB(data->program);
   1.190 +}
   1.191 +
   1.192 +static SDL_bool InitShaders()
   1.193 +{
   1.194 +    int i;
   1.195 +
   1.196 +    /* Check for shader support */
   1.197 +    shaders_supported = SDL_FALSE;
   1.198 +    if (SDL_GL_ExtensionSupported("GL_ARB_shader_objects") &&
   1.199 +        SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
   1.200 +        SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
   1.201 +        SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
   1.202 +        glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB");
   1.203 +        glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB");
   1.204 +        glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB");
   1.205 +        glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB");
   1.206 +        glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
   1.207 +        glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB");
   1.208 +        glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
   1.209 +        glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB");
   1.210 +        glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB");
   1.211 +        glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB");
   1.212 +        glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB");
   1.213 +        glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB");
   1.214 +        if (glAttachObjectARB &&
   1.215 +            glCompileShaderARB &&
   1.216 +            glCreateProgramObjectARB &&
   1.217 +            glCreateShaderObjectARB &&
   1.218 +            glDeleteObjectARB &&
   1.219 +            glGetInfoLogARB &&
   1.220 +            glGetObjectParameterivARB &&
   1.221 +            glGetUniformLocationARB &&
   1.222 +            glLinkProgramARB &&
   1.223 +            glShaderSourceARB &&
   1.224 +            glUniform1iARB &&
   1.225 +            glUseProgramObjectARB) {
   1.226 +            shaders_supported = SDL_TRUE;
   1.227 +        }
   1.228 +    }
   1.229 +
   1.230 +    if (!shaders_supported) {
   1.231 +        return SDL_FALSE;
   1.232 +    }
   1.233 +
   1.234 +    /* Compile all the shaders */
   1.235 +    for (i = 0; i < NUM_SHADERS; ++i) {
   1.236 +        if (!CompileShaderProgram(&shaders[i])) {
   1.237 +            fprintf(stderr, "Unable to compile shader!\n");
   1.238 +            return SDL_FALSE;
   1.239 +        }
   1.240 +    }
   1.241 +
   1.242 +    /* We're done! */
   1.243 +    return SDL_TRUE;
   1.244 +}
   1.245 +
   1.246 +static void QuitShaders()
   1.247 +{
   1.248 +    int i;
   1.249 +
   1.250 +    for (i = 0; i < NUM_SHADERS; ++i) {
   1.251 +        DestroyShaderProgram(&shaders[i]);
   1.252 +    }
   1.253 +}
   1.254 +
   1.255 +/* Quick utility function for texture creation */
   1.256 +static int
   1.257 +power_of_two(int input)
   1.258 +{
   1.259 +    int value = 1;
   1.260 +
   1.261 +    while (value < input) {
   1.262 +        value <<= 1;
   1.263 +    }
   1.264 +    return value;
   1.265 +}
   1.266 +
   1.267 +GLuint
   1.268 +SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
   1.269 +{
   1.270 +    GLuint texture;
   1.271 +    int w, h;
   1.272 +    SDL_Surface *image;
   1.273 +    SDL_Rect area;
   1.274 +    Uint32 saved_flags;
   1.275 +    Uint8 saved_alpha;
   1.276 +
   1.277 +    /* Use the surface width and height expanded to powers of 2 */
   1.278 +    w = power_of_two(surface->w);
   1.279 +    h = power_of_two(surface->h);
   1.280 +    texcoord[0] = 0.0f;         /* Min X */
   1.281 +    texcoord[1] = 0.0f;         /* Min Y */
   1.282 +    texcoord[2] = (GLfloat) surface->w / w;     /* Max X */
   1.283 +    texcoord[3] = (GLfloat) surface->h / h;     /* Max Y */
   1.284 +
   1.285 +    image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
   1.286 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN     /* OpenGL RGBA masks */
   1.287 +                                 0x000000FF,
   1.288 +                                 0x0000FF00, 0x00FF0000, 0xFF000000
   1.289 +#else
   1.290 +                                 0xFF000000,
   1.291 +                                 0x00FF0000, 0x0000FF00, 0x000000FF
   1.292 +#endif
   1.293 +        );
   1.294 +    if (image == NULL) {
   1.295 +        return 0;
   1.296 +    }
   1.297 +
   1.298 +    /* Save the alpha blending attributes */
   1.299 +    saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   1.300 +    SDL_GetSurfaceAlphaMod(surface, &saved_alpha);
   1.301 +    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   1.302 +        SDL_SetAlpha(surface, 0, 0);
   1.303 +    }
   1.304 +
   1.305 +    /* Copy the surface into the GL texture image */
   1.306 +    area.x = 0;
   1.307 +    area.y = 0;
   1.308 +    area.w = surface->w;
   1.309 +    area.h = surface->h;
   1.310 +    SDL_BlitSurface(surface, &area, image, &area);
   1.311 +
   1.312 +    /* Restore the alpha blending attributes */
   1.313 +    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   1.314 +        SDL_SetAlpha(surface, saved_flags, saved_alpha);
   1.315 +    }
   1.316 +
   1.317 +    /* Create an OpenGL texture for the image */
   1.318 +    glGenTextures(1, &texture);
   1.319 +    glBindTexture(GL_TEXTURE_2D, texture);
   1.320 +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   1.321 +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   1.322 +    glTexImage2D(GL_TEXTURE_2D,
   1.323 +                 0,
   1.324 +                 GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
   1.325 +    SDL_FreeSurface(image);     /* No longer needed */
   1.326 +
   1.327 +    return texture;
   1.328 +}
   1.329 +
   1.330 +/* A general OpenGL initialization function.    Sets all of the initial parameters. */
   1.331 +void InitGL(int Width, int Height)                    // We call this right after our OpenGL window is created.
   1.332 +{
   1.333 +    GLdouble aspect;
   1.334 +
   1.335 +    glViewport(0, 0, Width, Height);
   1.336 +    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);        // This Will Clear The Background Color To Black
   1.337 +    glClearDepth(1.0);                // Enables Clearing Of The Depth Buffer
   1.338 +    glDepthFunc(GL_LESS);                // The Type Of Depth Test To Do
   1.339 +    glEnable(GL_DEPTH_TEST);            // Enables Depth Testing
   1.340 +    glShadeModel(GL_SMOOTH);            // Enables Smooth Color Shading
   1.341 +
   1.342 +    glMatrixMode(GL_PROJECTION);
   1.343 +    glLoadIdentity();                // Reset The Projection Matrix
   1.344 +
   1.345 +    aspect = (GLdouble)Width / Height;
   1.346 +    glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
   1.347 +
   1.348 +    glMatrixMode(GL_MODELVIEW);
   1.349 +}
   1.350 +
   1.351 +/* The main drawing function. */
   1.352 +void DrawGLScene(GLuint texture, GLfloat * texcoord)
   1.353 +{
   1.354 +    /* Texture coordinate lookup, to make it simple */
   1.355 +    enum {
   1.356 +        MINX,
   1.357 +        MINY,
   1.358 +        MAXX,
   1.359 +        MAXY
   1.360 +    };
   1.361 +
   1.362 +    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        // Clear The Screen And The Depth Buffer
   1.363 +    glLoadIdentity();                // Reset The View
   1.364 +
   1.365 +    glTranslatef(-1.5f,0.0f,0.0f);        // Move Left 1.5 Units
   1.366 +    
   1.367 +    // draw a triangle (in smooth coloring mode)
   1.368 +    glBegin(GL_POLYGON);                // start drawing a polygon
   1.369 +    glColor3f(1.0f,0.0f,0.0f);            // Set The Color To Red
   1.370 +    glVertex3f( 0.0f, 1.0f, 0.0f);        // Top
   1.371 +    glColor3f(0.0f,1.0f,0.0f);            // Set The Color To Green
   1.372 +    glVertex3f( 1.0f,-1.0f, 0.0f);        // Bottom Right
   1.373 +    glColor3f(0.0f,0.0f,1.0f);            // Set The Color To Blue
   1.374 +    glVertex3f(-1.0f,-1.0f, 0.0f);        // Bottom Left    
   1.375 +    glEnd();                    // we're done with the polygon (smooth color interpolation)    
   1.376 +
   1.377 +    glTranslatef(3.0f,0.0f,0.0f);         // Move Right 3 Units
   1.378 +
   1.379 +    // Enable blending
   1.380 +    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
   1.381 +    glEnable(GL_BLEND);
   1.382 +    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   1.383 +
   1.384 +    // draw a textured square (quadrilateral)
   1.385 +    glEnable(GL_TEXTURE_2D);
   1.386 +    glBindTexture(GL_TEXTURE_2D, texture);
   1.387 +    glColor3f(1.0f,1.0f,1.0f);
   1.388 +    if (shaders_supported) {
   1.389 +        glUseProgramObjectARB(shaders[current_shader].program);
   1.390 +    }
   1.391 +
   1.392 +    glBegin(GL_QUADS);                // start drawing a polygon (4 sided)
   1.393 +    glTexCoord2f(texcoord[MINX], texcoord[MINY]);
   1.394 +    glVertex3f(-1.0f, 1.0f, 0.0f);        // Top Left
   1.395 +    glTexCoord2f(texcoord[MAXX], texcoord[MINY]);
   1.396 +    glVertex3f( 1.0f, 1.0f, 0.0f);        // Top Right
   1.397 +    glTexCoord2f(texcoord[MAXX], texcoord[MAXY]);
   1.398 +    glVertex3f( 1.0f,-1.0f, 0.0f);        // Bottom Right
   1.399 +    glTexCoord2f(texcoord[MINX], texcoord[MAXY]);
   1.400 +    glVertex3f(-1.0f,-1.0f, 0.0f);        // Bottom Left    
   1.401 +    glEnd();                    // done with the polygon
   1.402 +
   1.403 +    if (shaders_supported) {
   1.404 +        glUseProgramObjectARB(0);
   1.405 +    }
   1.406 +    glDisable(GL_TEXTURE_2D);
   1.407 +
   1.408 +    // swap buffers to display, since we're double buffered.
   1.409 +    SDL_GL_SwapBuffers();
   1.410 +}
   1.411 +
   1.412 +int main(int argc, char **argv) 
   1.413 +{    
   1.414 +    int done;
   1.415 +    SDL_Surface *surface;
   1.416 +    GLuint texture;
   1.417 +    GLfloat texcoords[4];
   1.418 +
   1.419 +    /* Initialize SDL for video output */
   1.420 +    if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
   1.421 +        fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
   1.422 +        exit(1);
   1.423 +    }
   1.424 +
   1.425 +    /* Create a 640x480 OpenGL screen */
   1.426 +    if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL ) {
   1.427 +        fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
   1.428 +        SDL_Quit();
   1.429 +        exit(2);
   1.430 +    }
   1.431 +
   1.432 +    /* Set the title bar in environments that support it */
   1.433 +    SDL_WM_SetCaption("Shader Demo", NULL);
   1.434 +
   1.435 +    surface = SDL_LoadBMP("icon.bmp");
   1.436 +    if ( ! surface ) {
   1.437 +        fprintf(stderr, "Unable to load icon.bmp: %s\n", SDL_GetError());
   1.438 +        SDL_Quit();
   1.439 +        exit(3);
   1.440 +    }
   1.441 +    texture = SDL_GL_LoadTexture(surface, texcoords);
   1.442 +    SDL_FreeSurface(surface);
   1.443 +
   1.444 +    /* Loop, drawing and checking events */
   1.445 +    InitGL(640, 480);
   1.446 +    if (InitShaders()) {
   1.447 +        printf("Shaders supported, press SPACE to cycle them.\n");
   1.448 +    } else {
   1.449 +        printf("Shaders not supported!\n");
   1.450 +    }
   1.451 +    done = 0;
   1.452 +    while ( ! done ) {
   1.453 +        DrawGLScene(texture, texcoords);
   1.454 +
   1.455 +        /* This could go in a separate function */
   1.456 +        { SDL_Event event;
   1.457 +            while ( SDL_PollEvent(&event) ) {
   1.458 +                if ( event.type == SDL_QUIT ) {
   1.459 +                    done = 1;
   1.460 +                }
   1.461 +                if ( event.type == SDL_KEYDOWN ) {
   1.462 +                    if ( event.key.keysym.sym == SDLK_SPACE ) {
   1.463 +                        current_shader = (current_shader + 1) % NUM_SHADERS;
   1.464 +                    }
   1.465 +                    if ( event.key.keysym.sym == SDLK_ESCAPE ) {
   1.466 +                        done = 1;
   1.467 +                    }
   1.468 +                }
   1.469 +            }
   1.470 +        }
   1.471 +    }
   1.472 +    QuitShaders();
   1.473 +    SDL_Quit();
   1.474 +    return 1;
   1.475 +}
   1.476 +
   1.477 +#else /* HAVE_OPENGL */
   1.478 +
   1.479 +int
   1.480 +main(int argc, char *argv[])
   1.481 +{
   1.482 +    printf("No OpenGL support on this system\n");
   1.483 +    return 1;
   1.484 +}
   1.485 +
   1.486 +#endif /* HAVE_OPENGL */