graphics

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit f1fbb67946ba1476a3cf66a2edd475ba1c297129
parent 48091fcb094dd2bb396f4d6c8c70c8c73e90946d
Author: Brian Swetland <swetland@frotz.net>
Date:   Fri, 14 Jun 2013 18:07:27 -0700

Shift to SDL2.0

Diffstat:
Mcommon/glapp.cc | 27++++++++++++++++++++++-----
Mcommon/glapp.h | 2++
Mhello/Makefile | 11++++++-----
3 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/common/glapp.cc b/common/glapp.cc @@ -133,12 +133,29 @@ int App::start(void) { SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); /* enable vsync */ - SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, _vsync); + //SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, _vsync); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, _vsync); - if (SDL_SetVideoMode(width, height, 32, - SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL) == NULL) - die("sdl cannot set mode"); + win = SDL_CreateWindow("Application", + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + width, height, SDL_WINDOW_OPENGL /* | SDL_WINDOW_RESIZABLE */); + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + + glcontext = SDL_GL_CreateContext(win); + +#if FALLBACK_TO_GL32 + if (!glcontext) { + fprintf(stderr, "oops?\n"); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + glcontext = SDL_GL_CreateContext(win); + /* query needed extensions, etc */ + } +#endif + + SDL_GL_SetSwapInterval(_vsync); gl_map_functions(); @@ -156,7 +173,7 @@ int App::start(void) { render(); if (_vsync) { - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow(win); } else { glFlush(); } diff --git a/common/glapp.h b/common/glapp.h @@ -199,6 +199,8 @@ protected: private: int _vsync; + SDL_Window *win; + SDL_GLContext glcontext; }; App *createApp(void); diff --git a/hello/Makefile b/hello/Makefile @@ -1,10 +1,10 @@ -SDLCFG := sdl-config +SDLCFG := /work/sdl2/bin/sdl2-config SDLFLAGS := $(shell $(SDLCFG) --cflags) -SDLLIBS := $(shell $(SDLCFG) --libs) +SDLLIBS := $(shell $(SDLCFG) --static-libs) -CFLAGS := $(SDLFLAGS) -DWITH_SDL2=0 -Wall -g -O2 +CFLAGS := $(SDLFLAGS) -Wall -g -O2 CFLAGS += -ffunction-sections -fdata-sections CFLAGS += -std=c++0x CFLAGS += -I../common @@ -15,7 +15,7 @@ LFLAGS += -Wl,-gc-sections CXXFLAGS := $(CFLAGS) GLLIB := /usr/lib/nvidia-experimental-310/libGL.so.310.14 -#LIBS := $(SDLLIBS) -lGL -lm -lpng +#GLLIB := -lGL LIBS := $(SDLLIBS) $(GLLIB) -lm -lpng LIBOBJS := ../common/loadfile.o @@ -26,10 +26,11 @@ LIBOBJS += ../common/simplexnoise.o LIBOBJS += ../common/matrix.o LIBOBJS += ../common/textgrid.o LIBOBJS += ../common/glapp.o +LIBOBJS += ../common/io.o OBJS := hello.o -all: hello test +all: hello hello: $(OBJS) $(LIBOBJS) $(CXX) $(LFLAGS) -o hello $(OBJS) $(LIBOBJS) $(LIBS)