From bbfeeae73222b568d532f551eebc75fd4ff1849d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 6 Jun 2014 22:49:51 -0400 Subject: [PATCH] update to SDL2 --- Makefile | 6 +++--- sdl_tmplt.c | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4556254..0c62398 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ FILE := sdl_tmplt TARGET := $(FILE) -CFLAGS := $(shell sdl-config --cflags) +CFLAGS := $(shell sdl2-config --cflags) ifdef WIN32 LIBS := -lopengl32 -lglu32 -lmingw32 CC := mingw32-gcc TARGET := $(TARGET).exe else -LIBS := -lGL -lGLU `sdl-config --libs` +LIBS := -lGL -lGLU `sdl2-config --libs` endif -LDFLAGS := $(LIBS) $(shell sdl-config --libs) +LDFLAGS := $(LIBS) $(shell sdl2-config --libs) all: $(TARGET) diff --git a/sdl_tmplt.c b/sdl_tmplt.c index 2d66214..904814d 100644 --- a/sdl_tmplt.c +++ b/sdl_tmplt.c @@ -1,5 +1,4 @@ - -#include +#include #include #include @@ -20,7 +19,7 @@ void init(void) glTranslatef(0.0, 0.0, -3.6); } -void display(void) +void display(SDL_Window * window) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); @@ -29,7 +28,7 @@ void display(void) glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.0, -1.0, 0.0); glEnd(); - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow(window); } int main(int argc, char *argv[]) @@ -42,18 +41,23 @@ int main(int argc, char *argv[]) atexit(SDL_Quit); - SDL_Surface *screen; - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_OPENGL))) + SDL_Window * window = SDL_CreateWindow(argv[0], + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + WIDTH, + HEIGHT, + SDL_WINDOW_OPENGL); + if (!window) { - printf("Failed to set video mode!\n"); + printf("Failed to create window!\n"); SDL_Quit(); return 2; } - SDL_WM_SetCaption(argv[0], argv[0]); + + SDL_GLContext gl_context = SDL_GL_CreateContext(window); init(); - display(); + display(window); SDL_Event event; while (SDL_WaitEvent(&event)) { @@ -63,6 +67,8 @@ int main(int argc, char *argv[]) { if (event.key.keysym.sym == SDLK_ESCAPE) break; + if (event.key.keysym.sym == SDLK_RETURN) + display(window); } } }