test/testshader.c
changeset 7323 590e596a8efc
parent 7191 75360622e65f
child 7324 0b4494cd6412
     1.1 --- a/test/testshader.c	Thu Jun 27 11:27:19 2013 -0700
     1.2 +++ b/test/testshader.c	Thu Jun 27 11:44:07 2013 -0700
     1.3 @@ -11,15 +11,6 @@
     1.4  */
     1.5  /* This is a simple example of using GLSL shaders with SDL */
     1.6  
     1.7 -#if 1 /* FIXME: Rework this using the 2.0 API */
     1.8 -#include <stdio.h>
     1.9 -
    1.10 -int main(int argc, char *argv[])
    1.11 -{
    1.12 -    printf("FIXME\n");
    1.13 -    return 0;
    1.14 -}
    1.15 -#else
    1.16  #include "SDL.h"
    1.17  
    1.18  #ifdef HAVE_OPENGL
    1.19 @@ -315,11 +306,8 @@
    1.20      }
    1.21  
    1.22      /* Save the alpha blending attributes */
    1.23 -    saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
    1.24      SDL_GetSurfaceAlphaMod(surface, &saved_alpha);
    1.25 -    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
    1.26 -        SDL_SetAlpha(surface, 0, 0);
    1.27 -    }
    1.28 +    SDL_SetSurfaceAlphaMod(surface, SDL_ALPHA_OPAQUE);
    1.29  
    1.30      /* Copy the surface into the GL texture image */
    1.31      area.x = 0;
    1.32 @@ -329,9 +317,7 @@
    1.33      SDL_BlitSurface(surface, &area, image, &area);
    1.34  
    1.35      /* Restore the alpha blending attributes */
    1.36 -    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
    1.37 -        SDL_SetAlpha(surface, saved_flags, saved_alpha);
    1.38 -    }
    1.39 +    SDL_SetSurfaceAlphaMod(surface, saved_alpha);
    1.40  
    1.41      /* Create an OpenGL texture for the image */
    1.42      glGenTextures(1, &texture);
    1.43 @@ -368,7 +354,7 @@
    1.44  }
    1.45  
    1.46  /* The main drawing function. */
    1.47 -void DrawGLScene(GLuint texture, GLfloat * texcoord)
    1.48 +void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord)
    1.49  {
    1.50      /* Texture coordinate lookup, to make it simple */
    1.51      enum {
    1.52 @@ -425,12 +411,13 @@
    1.53      glDisable(GL_TEXTURE_2D);
    1.54  
    1.55      // swap buffers to display, since we're double buffered.
    1.56 -    SDL_GL_SwapBuffers();
    1.57 +    SDL_GL_SwapWindow(window);
    1.58  }
    1.59  
    1.60  int main(int argc, char **argv)
    1.61  {
    1.62      int done;
    1.63 +    SDL_Window *window;
    1.64      SDL_Surface *surface;
    1.65      GLuint texture;
    1.66      GLfloat texcoords[4];
    1.67 @@ -442,14 +429,18 @@
    1.68      }
    1.69  
    1.70      /* Create a 640x480 OpenGL screen */
    1.71 -    if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL ) {
    1.72 -        fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError());
    1.73 +    window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
    1.74 +    if ( !window ) {
    1.75 +        fprintf(stderr, "Unable to create OpenGL window: %s\n", SDL_GetError());
    1.76          SDL_Quit();
    1.77          exit(2);
    1.78      }
    1.79  
    1.80 -    /* Set the title bar in environments that support it */
    1.81 -    SDL_WM_SetCaption("Shader Demo", NULL);
    1.82 +    if ( !SDL_GL_CreateContext(window)) {
    1.83 +        fprintf(stderr, "Unable to create OpenGL context: %s\n", SDL_GetError());
    1.84 +        SDL_Quit();
    1.85 +        exit(2);
    1.86 +    }
    1.87  
    1.88      surface = SDL_LoadBMP("icon.bmp");
    1.89      if ( ! surface ) {
    1.90 @@ -469,7 +460,7 @@
    1.91      }
    1.92      done = 0;
    1.93      while ( ! done ) {
    1.94 -        DrawGLScene(texture, texcoords);
    1.95 +        DrawGLScene(window, texture, texcoords);
    1.96  
    1.97          /* This could go in a separate function */
    1.98          { SDL_Event event;
    1.99 @@ -503,6 +494,5 @@
   1.100  }
   1.101  
   1.102  #endif /* HAVE_OPENGL */
   1.103 -#endif
   1.104  
   1.105  /* vi: set ts=4 sw=4 expandtab: */