# HG changeset patch # User John Tsiombikas # Date 1309064173 -10800 # Node ID 0697fbd075b6dc14179708362ffa662f41c4b730 # Parent 12ce0cef7ebf34a7d40856ea56cfa3c2fee7f206 added fallback SDL module diff -r 12ce0cef7ebf -r 0697fbd075b6 Makefile.in --- a/Makefile.in Sun Jun 26 02:30:37 2011 +0300 +++ b/Makefile.in Sun Jun 26 07:56:13 2011 +0300 @@ -23,7 +23,7 @@ AR = ar CC = gcc -CFLAGS = -pedantic -Wall -g -fPIC -Iinclude -Isrc +CFLAGS = -pedantic -Wall -g -fPIC -Iinclude -Isrc $(CFLAGS_extra) LDFLAGS = $(wsys_libs) .PHONY: all @@ -35,6 +35,9 @@ $(lib_so): $(obj) $(CC) $(sharedopt_$(sys)) -o $@ $(obj) $(LDFLAGS) +%.o: %.m + $(CC) $(CFLAGS) -c -o $@ $< + -include $(dep) %.d: %.c diff -r 12ce0cef7ebf -r 0697fbd075b6 src/wsys_cocoa.m --- a/src/wsys_cocoa.m Sun Jun 26 02:30:37 2011 +0300 +++ b/src/wsys_cocoa.m Sun Jun 26 07:56:13 2011 +0300 @@ -1,6 +1,5 @@ /* SimplyGL window system module for Cocoa */ /* mac-framework: -framework Cocoa */ -/* link-with: `gnustep-config --gui-libs` */ #include "config.h" @@ -449,4 +448,6 @@ attr[i++] = 0; } +#else +int sgl_wsys_cocoa_silence_the_fucking_empty_file_warnings; #endif /* USE_WSYS_MODULE_COCOA */ diff -r 12ce0cef7ebf -r 0697fbd075b6 src/wsys_glut.c --- a/src/wsys_glut.c Sun Jun 26 02:30:37 2011 +0300 +++ b/src/wsys_glut.c Sun Jun 26 07:56:13 2011 +0300 @@ -63,7 +63,7 @@ static struct wsys_module ws = { - "glut", 1, + "glut", 5, init, shutdown, set_vidmode, diff -r 12ce0cef7ebf -r 0697fbd075b6 src/wsys_sdl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wsys_sdl.c Sun Jun 26 07:56:13 2011 +0300 @@ -0,0 +1,277 @@ +/* SimplyGL window system module for SDL */ +/* link-with: `sdl-config --libs` */ + +#include "config.h" + +#ifdef USE_WSYS_MODULE_SDL + +#include +#include "sgl.h" +#include "wsys.h" + + + +static int init(void); +static void shutdown(void); + +/* video mode switching */ +static int set_vidmode(int xsz, int ysz); +static int get_vidmode(int *xsz, int *ysz); + +/* create/destroy windows */ +static int create_window(int xsz, int ysz, unsigned int flags); +static void close_window(int wid); + +/* window management */ +static int set_active(int wid); +static int set_title(const char *str); +static void redisplay(void); +static void swap_buffers(void); + +static int get_modifiers(void); + +/* event handling and friends */ +static void set_event(int idx, int enable); +static int process_events(void); +static int handle_event(SDL_Event *ev); + + +static struct wsys_module ws = { + "sdl", 6, + init, + shutdown, + set_vidmode, + get_vidmode, + create_window, + close_window, + set_active, + set_title, + redisplay, + swap_buffers, + get_modifiers, + set_event, + process_events, + 0 +}; + +static int must_redisplay = 1; +static int win_width, win_height; +static unsigned int sdl_flags; + + +void sgl_register_sdl(void) +{ + sgl_register_module(&ws); +} + + +static int init(void) +{ + return SDL_Init(SDL_INIT_VIDEO); +} + +static void shutdown(void) +{ + SDL_Quit(); +} + +/* video mode switching */ +static int set_vidmode(int xsz, int ysz) +{ + return 0; /* TODO */ +} + +static int get_vidmode(int *xsz, int *ysz) +{ + return 0; /* TODO */ +} + +/* create/destroy windows */ +static int create_window(int xsz, int ysz, unsigned int flags) +{ + void (*func)(); + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + + if(flags & SGL_DOUBLE) { + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + } + if(flags & SGL_DEPTH) { + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + } + if(flags & SGL_STENCIL) { + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + } + if(flags & SGL_STEREO) { + SDL_GL_SetAttribute(SDL_GL_STEREO, 1); + } + if(flags & SGL_MULTISAMPLE) { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); + } + + sdl_flags = SDL_OPENGL | SDL_RESIZABLE; + + if(!SDL_SetVideoMode(xsz, ysz, 32, sdl_flags)) { + return -1; + } + win_width = xsz; + win_height = ysz; + set_title("OpenGL/SDL"); + + if((func = sgl_get_callback(SGL_CREATE))) { + func(0); + } + if((func = sgl_get_callback(SGL_RESHAPE))) { + func(xsz, ysz); + } + + return 0; +} + +static void close_window(int wid) +{ + SDL_Quit(); +} + +/* window management */ +static int set_active(int wid) +{ + return 0; /* only one window is supported in SDL */ +} + +static int set_title(const char *str) +{ + SDL_WM_SetCaption(str, str); + return 0; +} + +static void redisplay(void) +{ + must_redisplay = 1; +} + +static void swap_buffers(void) +{ + SDL_GL_SwapBuffers(); +} + +static int get_modifiers(void) +{ + int mod = 0; + SDLMod sdlmod = SDL_GetModState(); + + if(sdlmod & (KMOD_LSHIFT | KMOD_RSHIFT)) { + mod |= SGL_MOD_SHIFT; + } + if(sdlmod & (KMOD_LCTRL | KMOD_RCTRL)) { + mod |= SGL_MOD_CONTROL; + } + if(sdlmod & (KMOD_LALT | KMOD_RALT)) { + mod |= SGL_MOD_ALT; + } + return mod; +} + +/* event handling and friends */ +static void set_event(int idx, int enable) +{ + /* no need to do anything for SDL */ +} + +static int process_events(void) +{ + int got_event; + SDL_Event ev; + sgl_idle_callback_t idle = sgl_get_callback(SGL_IDLE); + sgl_display_callback_t disp = sgl_get_callback(SGL_DISPLAY); + + if(must_redisplay && disp) { + disp(); + must_redisplay = 0; + } + + if(idle) { + got_event = SDL_PollEvent(&ev); + } else { + if(!SDL_WaitEvent(&ev)) { + return -1; + } + got_event = 1; + } + + if(got_event) { + do { + if(handle_event(&ev) == -1) { + return -1; + } + } while(SDL_PollEvent(&ev)); + } + + if(idle) { + idle(); + } + + return 0; +} + +static int handle_event(SDL_Event *ev) +{ + void (*func)(); + + switch(ev->type) { + case SDL_VIDEORESIZE: + /* XXX this'll fuck up big time on windows, will lose the gl state! */ + SDL_SetVideoMode(ev->resize.w, ev->resize.h, 32, sdl_flags); + + if((func = sgl_get_callback(SGL_RESHAPE)) && + (ev->resize.w != win_width || ev->resize.h != win_height)) { + win_width = ev->resize.w; + win_height = ev->resize.h; + + func(win_width, win_height); + } + break; + + case SDL_VIDEOEXPOSE: + must_redisplay = 1; + break; + + case SDL_KEYDOWN: + case SDL_KEYUP: + if((func = sgl_get_callback(SGL_KEYBOARD))) { + func(ev->key.keysym.sym, ev->key.state == SDL_PRESSED); + } + break; + + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + if((func = sgl_get_callback(SGL_MOUSE))) { + func(ev->button.which - 1, ev->button.state == SDL_PRESSED, ev->button.x, ev->button.y); + } + break; + + case SDL_MOUSEMOTION: + if(ev->motion.state) { + func = sgl_get_callback(SGL_MOTION); + } else { + func = sgl_get_callback(SGL_PASSIVE); + } + + if(func) { + func(ev->motion.x, ev->motion.y); + } + break; + + case SDL_QUIT: + return -1; + } + + return 0; +} + +#else +int sgl_wsys_sdl_silence_the_fucking_empty_file_warnings; +#endif /* USE_WSYS_MODULE_SDL */