Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Updated testshader for the SDL 2.0 API
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jun 27, 2013
1 parent 44e52e5 commit b8f1e4d
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions test/testshader.c
Expand Up @@ -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 <stdio.h>

int main(int argc, char *argv[])
{
printf("FIXME\n");
return 0;
}
#else
#include "SDL.h"

#ifdef HAVE_OPENGL
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
Expand All @@ -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 ) {
Expand All @@ -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;
Expand Down Expand Up @@ -503,6 +494,5 @@ main(int argc, char *argv[])
}

#endif /* HAVE_OPENGL */
#endif

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit b8f1e4d

Please sign in to comment.