update to SDL2
This commit is contained in:
parent
27487dd243
commit
bbfeeae732
6
Makefile
6
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)
|
||||
|
26
sdl_tmplt.c
26
sdl_tmplt.c
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user