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
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)

View File

@ -1,5 +1,4 @@
#include <SDL/SDL.h>
#include <SDL2/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
@ -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);
}
}
}