# HG changeset patch # User John Tsiombikas # Date 1304975180 -10800 # Node ID 40491760d6e38dace21a87d32d306315e86ba548 starting work on SimplyGL diff -r 000000000000 -r 40491760d6e3 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Tue May 10 00:06:20 2011 +0300 @@ -0,0 +1,56 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) +dep = $(src:.c=.d) +lib_a = libsgl.a +soname = libsgl.so.$(somajor) +lib_so = $(lib_so_$(sys)) + +somajor = 0 +sominor = 0 + +lib_so_unix = $(soname).$(minor) +lib_so_mac = libsgl.dylib + +sharedopt_unix = -shared -Wl,-soname,$(soname) +sharedopt_mac = -dynamiclib + +ifeq ($(shell uname -a), Darwin) + sys = mac +else + sys = unix +endif + +AR = ar +CC = gcc +CFLAGS = -pedantic -Wall -g -Iinclude + +.PHONY: all +all: $(lib_so) $(lib_a) + +$(lib_a): $(obj) + $(AR) rcs $@ $(obj) + +$(lib_so): $(obj) + $(CC) $(sharedopt_$(sys)) -o $@ $(obj) + +-include $(dep) + +%.d: %.c + @$(CPP) $(CFLAGS) -MM -MT $(@:.d=.o) $< >$@ + +.PHONY: clean +clean: + rm -f $(obj) $(dep) $(lib_so) $(lib_a) + +.PHONY: install +install: + mkdir -p $(PREFIX)/include $(PREFIX)/lib + cp $(lib_a) $(PREFIX)/lib/$(lib_a) + cp $(lib_so) $(PREFIX)/lib/$(lib_so) + cp include/sgl.h $(PREFIX)/include/sgl.h + +.PHONY: uninstall +uninstall: + rm -f $(PREFIX)/lib/$(lib_a) + rm -f $(PREFIX)/lib/$(lib_so) + rm -f $(PREFIX)/include/sgl.h diff -r 000000000000 -r 40491760d6e3 include/sgl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/sgl.h Tue May 10 00:06:20 2011 +0300 @@ -0,0 +1,34 @@ +#ifndef SGL_H_ +#define SGL_H_ + +#define SGL_DOUBLE 1 +#define SGL_DEPTH 2 +#define SGL_STENCIL 4 +#define SGL_STEREO 8 + +enum { + SGL_CREATE, + SGL_CLOSE, + SGL_DISPLAY, + SGL_RESHAPE, + SGL_KEYBOARD, + SGL_MOUSE, + SGL_MOTION, + SGL_PASSIVE, + SGL_IDLE, + + SGL_NUM_CALLBACKS +}; + +int sgl_set_video_mode(int xsz, int ysz, int bpp); +int sgl_get_video_mode(int *xsz, int *ysz, int *bpp); + +int sgl_window(int x, int y, unsigned int mode); +void sgl_close(int win); + +int sgl_push_callbacks(void); +int sgl_pop_callbacks(void); +void sgl_clear_callbacks(void); +void (*sgl_callback(int idx, void (*func)()))(); + +#endif /* SGL_H_ */ diff -r 000000000000 -r 40491760d6e3 src/cb.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cb.c Tue May 10 00:06:20 2011 +0300 @@ -0,0 +1,50 @@ +#include +#include +#include "sgl.h" + +struct cbnode { + void (*func[SGL_NUM_CALLBACKS])(); + struct cbnode *next; +}; + +struct cbnode first_cbnode; +struct cbnode *cb = &first_cbnode; + +int sgl_push_callbacks(void) +{ + struct cbnode *node; + + if(!(node = malloc(sizeof *node))) { + return -1; + } + node->next = cb; + cb = node; + sgl_clear_callbacks(); + return 0; +} + +int sgl_pop_callbacks(void) +{ + struct cbnode *node; + + if(!cb->next) { + return -1; + } + + node = cb; + cb = cb->next; + free(node); + return 0; +} + +void sgl_clear_callbacks(void) +{ + memset(cb->func, 0, sizeof cb->func); +} + +void (*sgl_callback(int idx, void (*func)()))() +{ + void (*prev)() = cb->func[idx]; + cb->func[idx] = func; + return prev; +}