sgl

changeset 0:40491760d6e3

starting work on SimplyGL
author John Tsiombikas <nuclear@siggraph.org>
date Tue, 10 May 2011 00:06:20 +0300
parents
children 0c13a30be2c1
files Makefile include/sgl.h src/cb.c
diffstat 3 files changed, 140 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Tue May 10 00:06:20 2011 +0300
     1.3 @@ -0,0 +1,56 @@
     1.4 +src = $(wildcard src/*.c)
     1.5 +obj = $(src:.c=.o)
     1.6 +dep = $(src:.c=.d)
     1.7 +lib_a = libsgl.a
     1.8 +soname = libsgl.so.$(somajor)
     1.9 +lib_so = $(lib_so_$(sys))
    1.10 +
    1.11 +somajor = 0
    1.12 +sominor = 0
    1.13 +
    1.14 +lib_so_unix = $(soname).$(minor)
    1.15 +lib_so_mac = libsgl.dylib
    1.16 +
    1.17 +sharedopt_unix = -shared -Wl,-soname,$(soname)
    1.18 +sharedopt_mac = -dynamiclib
    1.19 +
    1.20 +ifeq ($(shell uname -a), Darwin)
    1.21 +	sys = mac
    1.22 +else
    1.23 +	sys = unix
    1.24 +endif
    1.25 +
    1.26 +AR = ar
    1.27 +CC = gcc
    1.28 +CFLAGS = -pedantic -Wall -g -Iinclude
    1.29 +
    1.30 +.PHONY: all
    1.31 +all: $(lib_so) $(lib_a)
    1.32 +
    1.33 +$(lib_a): $(obj)
    1.34 +	$(AR) rcs $@ $(obj)
    1.35 +
    1.36 +$(lib_so): $(obj)
    1.37 +	$(CC) $(sharedopt_$(sys)) -o $@ $(obj)
    1.38 +
    1.39 +-include $(dep)
    1.40 +
    1.41 +%.d: %.c
    1.42 +	@$(CPP) $(CFLAGS) -MM -MT $(@:.d=.o) $< >$@
    1.43 +
    1.44 +.PHONY: clean
    1.45 +clean:
    1.46 +	rm -f $(obj) $(dep) $(lib_so) $(lib_a)
    1.47 +
    1.48 +.PHONY: install
    1.49 +install:
    1.50 +	mkdir -p $(PREFIX)/include $(PREFIX)/lib
    1.51 +	cp $(lib_a) $(PREFIX)/lib/$(lib_a)
    1.52 +	cp $(lib_so) $(PREFIX)/lib/$(lib_so)
    1.53 +	cp include/sgl.h $(PREFIX)/include/sgl.h
    1.54 +
    1.55 +.PHONY: uninstall
    1.56 +uninstall:
    1.57 +	rm -f $(PREFIX)/lib/$(lib_a)
    1.58 +	rm -f $(PREFIX)/lib/$(lib_so)
    1.59 +	rm -f $(PREFIX)/include/sgl.h
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/include/sgl.h	Tue May 10 00:06:20 2011 +0300
     2.3 @@ -0,0 +1,34 @@
     2.4 +#ifndef SGL_H_
     2.5 +#define SGL_H_
     2.6 +
     2.7 +#define SGL_DOUBLE		1
     2.8 +#define SGL_DEPTH		2
     2.9 +#define SGL_STENCIL		4
    2.10 +#define SGL_STEREO		8
    2.11 +
    2.12 +enum {
    2.13 +	SGL_CREATE,
    2.14 +	SGL_CLOSE,
    2.15 +	SGL_DISPLAY,
    2.16 +	SGL_RESHAPE,
    2.17 +	SGL_KEYBOARD,
    2.18 +	SGL_MOUSE,
    2.19 +	SGL_MOTION,
    2.20 +	SGL_PASSIVE,
    2.21 +	SGL_IDLE,
    2.22 +
    2.23 +	SGL_NUM_CALLBACKS
    2.24 +};
    2.25 +
    2.26 +int sgl_set_video_mode(int xsz, int ysz, int bpp);
    2.27 +int sgl_get_video_mode(int *xsz, int *ysz, int *bpp);
    2.28 +
    2.29 +int sgl_window(int x, int y, unsigned int mode);
    2.30 +void sgl_close(int win);
    2.31 +
    2.32 +int sgl_push_callbacks(void);
    2.33 +int sgl_pop_callbacks(void);
    2.34 +void sgl_clear_callbacks(void);
    2.35 +void (*sgl_callback(int idx, void (*func)()))();
    2.36 +
    2.37 +#endif	/* SGL_H_ */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/cb.c	Tue May 10 00:06:20 2011 +0300
     3.3 @@ -0,0 +1,50 @@
     3.4 +#include <stdlib.h>
     3.5 +#include <string.h>
     3.6 +#include "sgl.h"
     3.7 +
     3.8 +struct cbnode {
     3.9 +	void (*func[SGL_NUM_CALLBACKS])();
    3.10 +	struct cbnode *next;
    3.11 +};
    3.12 +
    3.13 +struct cbnode first_cbnode;
    3.14 +struct cbnode *cb = &first_cbnode;
    3.15 +
    3.16 +int sgl_push_callbacks(void)
    3.17 +{
    3.18 +	struct cbnode *node;
    3.19 +
    3.20 +	if(!(node = malloc(sizeof *node))) {
    3.21 +		return -1;
    3.22 +	}
    3.23 +	node->next = cb;
    3.24 +	cb = node;
    3.25 +	sgl_clear_callbacks();
    3.26 +	return 0;
    3.27 +}
    3.28 +
    3.29 +int sgl_pop_callbacks(void)
    3.30 +{
    3.31 +	struct cbnode *node;
    3.32 +
    3.33 +	if(!cb->next) {
    3.34 +		return -1;
    3.35 +	}
    3.36 +
    3.37 +	node = cb;
    3.38 +	cb = cb->next;
    3.39 +	free(node);
    3.40 +	return 0;
    3.41 +}
    3.42 +
    3.43 +void sgl_clear_callbacks(void)
    3.44 +{
    3.45 +	memset(cb->func, 0, sizeof cb->func);
    3.46 +}
    3.47 +
    3.48 +void (*sgl_callback(int idx, void (*func)()))()
    3.49 +{
    3.50 +	void (*prev)() = cb->func[idx];
    3.51 +	cb->func[idx] = func;
    3.52 +	return prev;
    3.53 +}