From b8f1e4dd7554099ab485b1e10d8929d28763586c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 27 Jun 2013 11:44:07 -0700 Subject: [PATCH] Updated testshader for the SDL 2.0 API --- test/testshader.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/test/testshader.c b/test/testshader.c index c555335d2..2418dbe3f 100644 --- a/test/testshader.c +++ b/test/testshader.c @@ -11,15 +11,6 @@ */ /* This is a simple example of using GLSL shaders with SDL */ -#if 1 /* FIXME: Rework this using the 2.0 API */ -#include - -int main(int argc, char *argv[]) -{ - printf("FIXME\n"); - return 0; -} -#else #include "SDL.h" #ifdef HAVE_OPENGL @@ -315,11 +306,8 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord) } /* Save the alpha blending attributes */ - saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); SDL_GetSurfaceAlphaMod(surface, &saved_alpha); - if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { - SDL_SetAlpha(surface, 0, 0); - } + SDL_SetSurfaceAlphaMod(surface, SDL_ALPHA_OPAQUE); /* Copy the surface into the GL texture image */ area.x = 0; @@ -329,9 +317,7 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord) SDL_BlitSurface(surface, &area, image, &area); /* Restore the alpha blending attributes */ - if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { - SDL_SetAlpha(surface, saved_flags, saved_alpha); - } + SDL_SetSurfaceAlphaMod(surface, saved_alpha); /* Create an OpenGL texture for the image */ glGenTextures(1, &texture); @@ -368,7 +354,7 @@ void InitGL(int Width, int Height) // We call this right afte } /* The main drawing function. */ -void DrawGLScene(GLuint texture, GLfloat * texcoord) +void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord) { /* Texture coordinate lookup, to make it simple */ enum { @@ -425,12 +411,13 @@ void DrawGLScene(GLuint texture, GLfloat * texcoord) glDisable(GL_TEXTURE_2D); // swap buffers to display, since we're double buffered. - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow(window); } int main(int argc, char **argv) { int done; + SDL_Window *window; SDL_Surface *surface; GLuint texture; GLfloat texcoords[4]; @@ -442,14 +429,18 @@ int main(int argc, char **argv) } /* Create a 640x480 OpenGL screen */ - if ( SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL ) { - fprintf(stderr, "Unable to create OpenGL screen: %s\n", SDL_GetError()); + window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL ); + if ( !window ) { + fprintf(stderr, "Unable to create OpenGL window: %s\n", SDL_GetError()); SDL_Quit(); exit(2); } - /* Set the title bar in environments that support it */ - SDL_WM_SetCaption("Shader Demo", NULL); + if ( !SDL_GL_CreateContext(window)) { + fprintf(stderr, "Unable to create OpenGL context: %s\n", SDL_GetError()); + SDL_Quit(); + exit(2); + } surface = SDL_LoadBMP("icon.bmp"); if ( ! surface ) { @@ -469,7 +460,7 @@ int main(int argc, char **argv) } done = 0; while ( ! done ) { - DrawGLScene(texture, texcoords); + DrawGLScene(window, texture, texcoords); /* This could go in a separate function */ { SDL_Event event; @@ -503,6 +494,5 @@ main(int argc, char *argv[]) } #endif /* HAVE_OPENGL */ -#endif /* vi: set ts=4 sw=4 expandtab: */