update to SDL2

This commit is contained in:
Josh Holtrop 2014-06-06 22:49:51 -04:00
parent 27487dd243
commit bbfeeae732
2 changed files with 19 additions and 13 deletions

View File

@ -1,15 +1,15 @@
FILE := sdl_tmplt FILE := sdl_tmplt
TARGET := $(FILE) TARGET := $(FILE)
CFLAGS := $(shell sdl-config --cflags) CFLAGS := $(shell sdl2-config --cflags)
ifdef WIN32 ifdef WIN32
LIBS := -lopengl32 -lglu32 -lmingw32 LIBS := -lopengl32 -lglu32 -lmingw32
CC := mingw32-gcc CC := mingw32-gcc
TARGET := $(TARGET).exe TARGET := $(TARGET).exe
else else
LIBS := -lGL -lGLU `sdl-config --libs` LIBS := -lGL -lGLU `sdl2-config --libs`
endif endif
LDFLAGS := $(LIBS) $(shell sdl-config --libs) LDFLAGS := $(LIBS) $(shell sdl2-config --libs)
all: $(TARGET) all: $(TARGET)

View File

@ -1,5 +1,4 @@
#include <SDL2/SDL.h>
#include <SDL/SDL.h>
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
@ -20,7 +19,7 @@ void init(void)
glTranslatef(0.0, 0.0, -3.6); glTranslatef(0.0, 0.0, -3.6);
} }
void display(void) void display(SDL_Window * window)
{ {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -29,7 +28,7 @@ void display(void)
glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.0, 1.0, 0.0);
glVertex3f(0.0, -1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
glEnd(); glEnd();
SDL_GL_SwapBuffers(); SDL_GL_SwapWindow(window);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -42,18 +41,23 @@ int main(int argc, char *argv[])
atexit(SDL_Quit); atexit(SDL_Quit);
SDL_Surface *screen; SDL_Window * window = SDL_CreateWindow(argv[0],
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_WINDOWPOS_UNDEFINED,
if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, 16, SDL_OPENGL))) 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(); SDL_Quit();
return 2; return 2;
} }
SDL_WM_SetCaption(argv[0], argv[0]);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
init(); init();
display(); display(window);
SDL_Event event; SDL_Event event;
while (SDL_WaitEvent(&event)) while (SDL_WaitEvent(&event))
{ {
@ -63,6 +67,8 @@ int main(int argc, char *argv[])
{ {
if (event.key.keysym.sym == SDLK_ESCAPE) if (event.key.keysym.sym == SDLK_ESCAPE)
break; break;
if (event.key.keysym.sym == SDLK_RETURN)
display(window);
} }
} }
} }