├── ebin └── .gitignore ├── priv └── .gitignore ├── vsn.mk ├── test ├── Beep.wav ├── Boing.wav ├── icon.bmp ├── Powered.bmp ├── sample.wav ├── PoweredBump.bmp ├── PoweredSmall.bmp ├── erlang-drop-shadow.png ├── Makefile ├── testaudio.erl ├── testbin.erl ├── test_ttf.erl ├── testjoy.erl └── testgl.erl ├── .gitignore ├── woggle ├── tools │ ├── test.sh │ ├── etest.sh │ ├── ld.sh │ ├── gen_func.sh │ └── cc.sh ├── c_src │ ├── woggle_if_fp.h │ ├── woggle_if.h │ ├── woggle_if.c │ ├── woggle_compat_if_fp.h │ ├── woggle_compat_if.h │ ├── Makefile │ ├── woggle_wrapper.c │ ├── woggle_driver.h │ ├── woggle_driver.c │ └── woggle.h ├── include │ └── woggle.hrl ├── src │ ├── woggle_ops.hrl │ ├── Makefile │ └── woggle.erl ├── Makefile ├── test │ ├── Makefile │ ├── woggle_test.erl │ └── compat_testgl.erl └── README ├── api_gen ├── conv.hrl └── gludefs ├── esdl.pub ├── README-SDL.txt ├── doc ├── Makefile └── index.html ├── src ├── sdl.app.src ├── sdl_util.hrl ├── sdl_active.erl ├── esdl.hrl ├── sdl_img_funcs.hrl ├── sdl_keyboard.erl ├── sdl_ttf_funcs.hrl ├── sdl.erl ├── sdl_video_funcs.hrl ├── sdl_mouse.erl ├── sdl_audio.erl └── sdl_events.erl ├── include ├── sdl_active.hrl ├── sdl_ttf.hrl ├── sdl_mouse.hrl ├── sdl_joystick.hrl ├── sdl_audio.hrl ├── sdl.hrl ├── sdl_video.hrl └── sdl_events.hrl ├── c_src ├── esdl_gen.c ├── esdl_util.h ├── esdl_wrapper.c ├── esdl_audio.h ├── Makefile.macosx ├── esdl_util.c ├── esdl.h ├── esdl_conv.h ├── esdl_img.c ├── esdl_img.h ├── esdl_events.h ├── esdl_spec.c ├── esdl_ttf.h ├── esdl_audio.c └── esdl_video.h ├── rebar.config ├── license.terms └── Readme /ebin/.gitignore: -------------------------------------------------------------------------------- 1 | *.beam 2 | -------------------------------------------------------------------------------- /priv/.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | -------------------------------------------------------------------------------- /vsn.mk: -------------------------------------------------------------------------------- 1 | ESDL_VSN=esdl-1.3.1 2 | -------------------------------------------------------------------------------- /test/Beep.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/Beep.wav -------------------------------------------------------------------------------- /test/Boing.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/Boing.wav -------------------------------------------------------------------------------- /test/icon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/icon.bmp -------------------------------------------------------------------------------- /test/Powered.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/Powered.bmp -------------------------------------------------------------------------------- /test/sample.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/sample.wav -------------------------------------------------------------------------------- /test/PoweredBump.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/PoweredBump.bmp -------------------------------------------------------------------------------- /test/PoweredSmall.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/PoweredSmall.bmp -------------------------------------------------------------------------------- /test/erlang-drop-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgud/esdl/HEAD/test/erlang-drop-shadow.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # git ls-files --others --exclude-from=.git/info/exclude 2 | # Lines that start with '#' are comments. 3 | *~ 4 | .DS_Store 5 | *.beam 6 | doc/*.html 7 | c_src/*.o 8 | -------------------------------------------------------------------------------- /woggle/tools/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ -z "$WOGGLE_TOP" ]; then 3 | echo set WOGGLE_TOP please. 4 | exit 1 5 | fi 6 | WWOGGLE_TOP=`cygpath -d $WOGGLE_TOP` 7 | 8 | cmd.exe /c $WWOGGLE_TOP\\c_src\\woggle_test.exe 9 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_if_fp.h: -------------------------------------------------------------------------------- 1 | { WOGGLE_SwapBuffersFunc, "WOGGLE_SwapBuffersFunc", 2 | wog_if_swap_buffers }, 3 | { WOGGLE_ListModesFunc, "WOGGLE_ListModesFunc", 4 | wog_if_list_modes }, 5 | 6 | /*PLACEHOLDER_FOR_GENERATED_FUNCTIONS*/ 7 | -------------------------------------------------------------------------------- /woggle/include/woggle.hrl: -------------------------------------------------------------------------------- 1 | -ifndef(WOGGLE_HRL). 2 | -define(WOGGLE_HRL,1). 3 | 4 | -record(woggle_rect, 5 | { 6 | x, 7 | y, 8 | w, 9 | h 10 | }). 11 | 12 | -record(woggle_res, 13 | { 14 | cdepth, 15 | freq, 16 | w, 17 | h 18 | }). 19 | -endif. % WOGGLE_HRL 20 | -------------------------------------------------------------------------------- /woggle/tools/etest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | if [ -z "$WOGGLE_TOP" ]; then 3 | echo set WOGGLE_TOP please. 4 | exit 1 5 | fi 6 | ESDL_TOP=$WOGGLE_TOP/.. 7 | 8 | MWOGGLE_TOP=`cygpath -m $WOGGLE_TOP` 9 | MESDL_TOP=`cygpath -m $ESDL_TOP` 10 | 11 | werl -pa $MESDL_TOP/ebin -pa $MWOGGLE_TOP/test -s woggle_test go -------------------------------------------------------------------------------- /woggle/src/woggle_ops.hrl: -------------------------------------------------------------------------------- 1 | -ifndef(WOGGLE_OPS_HRL). 2 | -define(WOGGLE_OPS_HRL,1). 3 | 4 | % Corresponds to values in woggle_if.h and woggle_driver.h (WOGGLE_IF_H) 5 | -define(WOGGLE_IF_H, 133). 6 | 7 | -define(WOGGLE_SwapBuffers, (?WOGGLE_IF_H + 1)). 8 | -define(WOGGLE_ListModes, (?WOGGLE_SwapBuffers + 1)). 9 | %% PLACEHOLDER_FOR_GENERATED_FUNCTIONS:WOGGLE_ListModes 10 | 11 | -endif. % WOGGLE_OPS_HRL 12 | -------------------------------------------------------------------------------- /api_gen/conv.hrl: -------------------------------------------------------------------------------- 1 | %%%---------------------------------------------------------------------- 2 | %%% File : conv.hrl 3 | %%% Author : Dan Gudmundsson 4 | %%% Purpose : 5 | %%% Created : 11 Oct 2001 by Dan Gudmundsson 6 | %%%---------------------------------------------------------------------- 7 | 8 | %% Some knowledge about lengths of arrays and similar stuff. 9 | 10 | -define(array_lengths, []). 11 | 12 | 13 | -------------------------------------------------------------------------------- /esdl.pub: -------------------------------------------------------------------------------- 1 | {name, "esdl"}. 2 | {vsn, {0,9}}. 3 | {summary, "A 2D & 3D (Opengl) graphics package"}. 4 | {author, "Dan Gudmundsson", "dgud@erix.ericsson.se", "001201"}. 5 | {keywords, ["sdl", "opengl", "graphic"]}. 6 | {needs, [{"sdl (C-lib)",{1,5}}, {"Opengl (c-lib)",{1,1}}]}. 7 | {abstract, 8 | "Provides access to 2d and 3d graphics through Opengl and SDL." 9 | "More information and a prebuilt Windows release" 10 | "can be found on http://www.ericsson.se/cslab/~dgud/esdl/"}. 11 | 12 | -------------------------------------------------------------------------------- /README-SDL.txt: -------------------------------------------------------------------------------- 1 | 2 | Please distribute this file with the SDL runtime environment: 3 | 4 | The Simple DirectMedia Layer (SDL for short) is a cross-platfrom library 5 | designed to make it easy to write multi-media software, such as games and 6 | emulators. 7 | 8 | The Simple DirectMedia Layer library source code is available from: 9 | http://www.libsdl.org/ 10 | 11 | This library is distributed under the terms of the GNU LGPL license: 12 | http://www.gnu.org/copyleft/lesser.html 13 | 14 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_if.h: -------------------------------------------------------------------------------- 1 | /* This file is certainly NOT auto generated! */ 2 | #ifndef _WOGGLE_IF_H 3 | #define _WOGGLE_IF_H 4 | 5 | /* Now for the real Woggle functions */ 6 | #define WOGGLE_SwapBuffersFunc (WOGGLE_IF_H + 1) 7 | void wog_if_swap_buffers(sdl_data *sd, int len, char *buff); 8 | #define WOGGLE_ListModesFunc (WOGGLE_SwapBuffersFunc + 1) 9 | void wog_if_list_modes(sdl_data *sd, int len, char *buff); 10 | 11 | /*PLACEHOLDER_FOR_GENERATED_FUNCTIONS:WOGGLE_ListModesFunc*/ 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ESRC = ../src 3 | ERLC = erlc 4 | 5 | DOCG = makedoc.beam 6 | DOC = sdl.html sdl_active.html \ 7 | sdl_audio.html sdl_events.html sdl_keyboard.html sdl_mouse.html sdl_joystick.html \ 8 | sdl_util.html sdl_video.html sdl_ttf.html sdl_img.html 9 | 10 | 11 | target: $(DOCG) $(DOC) 12 | %.beam: %.erl 13 | $(ERLC) -W -bbeam $(ERL_FLAGS) $(ERL_COMPILE_FLAGS) $< 14 | 15 | clean: 16 | rm -f $(DOCG) $(DOC) 17 | rm -f *~ 18 | 19 | %.html: $(ESRC)/%.erl $(DOCG) 20 | erl -noshell -s makedoc start $< -s erlang halt 21 | -------------------------------------------------------------------------------- /src/sdl.app.src: -------------------------------------------------------------------------------- 1 | %%%------------------------------------------------------------------- 2 | %%% @author Dan Gudmundsson 3 | %%% @copyright (C) 2013, Dan Gudmundsson 4 | %%% @doc 5 | %%% 6 | %%% @end 7 | %%% Created : 25 Feb 2013 by Dan Gudmundsson 8 | %%%------------------------------------------------------------------- 9 | 10 | 11 | {application, sdl, 12 | [{description, "SDL binding for Erlang"}, 13 | {vsn, git}, 14 | {modules, {modules}}, 15 | {env, []}, 16 | {applications,[kernel,stdlib]} 17 | ] 18 | }. 19 | 20 | -------------------------------------------------------------------------------- /src/sdl_util.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_util.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : 12 | %%% Created : 13 Sep 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | 16 | -record(sdlmem, {bin, size, type}). 17 | -define(_PTR, 64/unsigned-native). 18 | 19 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2001 Dan Gudmundsson 2 | # See the file "license.terms" for information on usage and redistribution 3 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | # 5 | # $Id$ 6 | # 7 | 8 | TestMods = testsprite testgl testbin erldemo testaudio testjoy test_glfont test_ttf test_glimg 9 | TestTargets = $(TestMods:%=%.beam) 10 | 11 | # Targets 12 | target: $(TestTargets) 13 | 14 | clean: 15 | rm -f $(TestTargets) 16 | rm -f *~ core erl_crash.dump 17 | 18 | # Rules 19 | ESRC = . 20 | EBIN = . 21 | ERLC = erlc 22 | ERLINC = ../include 23 | ERL_COMPILE_FLAGS = -pa ../../esdl/ebin 24 | 25 | %.beam: $(ESRC)/%.erl 26 | $(ERLC) -W -I$(ERLINC) -bbeam $(ERL_FLAGS) $(ERL_COMPILE_FLAGS) -o$(EBIN) $< 27 | -------------------------------------------------------------------------------- /include/sdl_active.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_active.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : Active Macros 12 | %%% Created : 12 Jul 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -define(SDL_APPMOUSEFOCUS, 16#01). %/* The app has mouse coverage */ 16 | -define(SDL_APPINPUTFOCUS, 16#02). %/* The app has input focus */ 17 | -define(SDL_APPACTIVE, 16#04). %/* The application is active */ 18 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_if.c: -------------------------------------------------------------------------------- 1 | #include "woggle_driver.h" 2 | #include "woggle_if.h" 3 | 4 | void wog_if_swap_buffers(sdl_data *sd, int len, char *buff) 5 | { 6 | wog_swap_buffers(&(sd->wd)); 7 | } 8 | 9 | void wog_if_list_modes(sdl_data *sd, int len, char *buff) 10 | { 11 | WogRes *tmp = NULL; 12 | char *bp; 13 | int res; 14 | int i; 15 | 16 | res = wog_list_modes(&tmp); /* tmp will point into static buffer */ 17 | if (res <= 0) { 18 | bp = sdl_getbuff(sd, 2); 19 | put16be(bp,res); 20 | } 21 | bp = sdl_getbuff(sd, 9 * res); 22 | for (i = 0; i < res; ++i) { 23 | put8(bp, tmp[i].cdepth); 24 | put32be(bp, tmp[i].freq); 25 | put16be(bp, tmp[i].w); 26 | put16be(bp, tmp[i].h); 27 | } 28 | sdl_send(sd, 9 * res); 29 | } 30 | 31 | /*PLACEHOLDER_FOR_GENERATED_FUNCTIONS*/ 32 | -------------------------------------------------------------------------------- /woggle/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2001 Dan Gudmundsson and Patrik Nyblom 2 | # See the file "license.terms" for information on usage and redistribution 3 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | # 5 | # $Id$ 6 | # 7 | 8 | ifeq ($(OS_FLAG), mingw) 9 | include ../win32_conf/mingw_vars.mk 10 | woggle: 11 | (cd c_src; $(MAKE) OS_FLAG=$(OS_FLAG)) 12 | (cd src; $(MAKE) OS_FLAG=$(OS_FLAG)) 13 | (cd test; $(MAKE) OS_FLAG=$(OS_FLAG)) 14 | 15 | clean: top_clean 16 | (cd c_src; $(MAKE) OS_FLAG=$(OS_FLAG) clean) 17 | (cd src; $(MAKE) OS_FLAG=$(OS_FLAG) clean) 18 | (cd test; $(MAKE) OS_FLAG=$(OS_FLAG) clean) 19 | 20 | 21 | top_clean: 22 | rm -f *~ erl_crash.dump core 23 | rm -f tools/*~ 24 | 25 | else 26 | 27 | woggle clean: 28 | @echo Only windows for now. 29 | 30 | endif 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /woggle/test/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2001 Dan Gudmundsson and Patrik Nyblom 2 | # See the file "license.terms" for information on usage and redistribution 3 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | # 5 | # $Id$ 6 | # 7 | 8 | ifeq ($(OS_FLAG), mingw) 9 | include ../../win32_conf/mingw_vars.mk 10 | 11 | ERLC = erlc 12 | 13 | TARGETDIR = . 14 | 15 | # Files 16 | 17 | ERL_SOURCES = woggle_test.erl 18 | ERL_OBJECTS = $(ERL_SOURCES:%.erl=$(TARGETDIR)/%.beam) 19 | ERL_HEADERS = ../../include/gl.hrl ../include/woggle.hrl 20 | 21 | all: $(ERL_OBJECTS) 22 | @echo Build done 23 | 24 | clean: 25 | rm -f $(ERL_OBJECTS) 26 | rm -f *~ 27 | 28 | $(TARGETDIR)/%.beam: %.erl $(ERL_HEADERS) 29 | $(ERLC) -I../../include -I../include -o $@ $< 30 | 31 | else 32 | 33 | target clean: 34 | @echo Only windows for now. 35 | 36 | endif 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /woggle/src/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2001 Dan Gudmundsson and Patrik Nyblom 2 | # See the file "license.terms" for information on usage and redistribution 3 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | # 5 | # $Id$ 6 | # 7 | 8 | ifeq ($(OS_FLAG), mingw) 9 | include ../../win32_conf/mingw_vars.mk 10 | 11 | ERLC = erlc 12 | 13 | TARGETDIR = ../../ebin 14 | 15 | # Files 16 | 17 | ERL_SOURCES = woggle.erl 18 | ERL_OBJECTS = $(ERL_SOURCES:%.erl=$(TARGETDIR)/%.beam) 19 | ERL_HEADERS = ../../include/gl.hrl ../include/woggle.hrl \ 20 | woggle_ops.hrl 21 | 22 | all: $(ERL_OBJECTS) 23 | @echo Build done 24 | 25 | clean: 26 | rm -f $(ERL_OBJECTS) 27 | rm -f *~ 28 | 29 | $(TARGETDIR)/%.beam: %.erl $(ERL_HEADERS) 30 | $(ERLC) -I../../include -I../include -o $(TARGETDIR) $< 31 | 32 | else 33 | 34 | target clean: 35 | @echo Only windows for now. 36 | 37 | endif 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_compat_if_fp.h: -------------------------------------------------------------------------------- 1 | { SDL_GL_SwapBuffersFunc, "SDL_GL_SwapBuffersFunc", 2 | wog_compat_if_swap_buffers }, 3 | { SDL_ListModesFunc, "SDL_ListModesFunc", wog_compat_if_list_modes}, 4 | { SDL_SetVideoModeFunc, "SDL_SetVideoModeFunc", wog_compat_if_set_video_mode}, 5 | { SDL_VideoDriverNameFunc, "SDL_VideoDriverNameFunc", wog_compat_if_video_driver_name}, 6 | { SDL_GL_SetAttributeFunc, "SDL_GL_SetAttributeFunc", wog_compat_if_gl_set_attribute}, 7 | { SDL_GL_GetAttributeFunc, "SDL_GL_GetAttributeFunc", wog_compat_if_gl_get_attribute}, 8 | { SDL_WM_GetInfoFunc, "SDL_WM_GetInfoFunc", wog_compat_if_wm_get_info}, 9 | { SDL_WM_IsMaximizedFunc, "SDL_WM_IsMaximizedFunc", wog_compat_if_wm_is_maximized}, 10 | { SDL_VideoModeOKFunc, "SDL_VideoModeOKFunc", wog_compat_if_video_mode_o_k}, 11 | { SDL_EventStateFunc, "SDL_EventStateFunc", wog_compat_if_event_state}, 12 | { SDL_PollEventFunc, "SDL_PollEventFunc", wog_compat_if_poll_event}, 13 | /*PLACEHOLDER_FOR_GENERATED_FUNCTIONS*/ 14 | -------------------------------------------------------------------------------- /include/sdl_ttf.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2007 Klas Johansson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_ttf.hrl 10 | %%% Author : Klas Johansson 11 | %%% Purpose : defines from SDL_ttf.h 12 | %%% Created : 29 Jan 2007 by Klas Johansson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -record(ttf_font, {ptr}). 16 | 17 | %% ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) 18 | -define(UNICODE_BOM_NATIVE, 16#FEFF). 19 | -define(UNICODE_BOM_SWAPPED, 16#FFFE). 20 | 21 | -define(SDL_TTF_STYLE_NORMAL, 16#00). 22 | -define(SDL_TTF_STYLE_BOLD, 16#01). 23 | -define(SDL_TTF_STYLE_ITALIC, 16#02). 24 | -define(SDL_TTF_STYLE_UNDERLINE, 16#04). 25 | 26 | 27 | -------------------------------------------------------------------------------- /include/sdl_mouse.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_mouse.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : Usable mouse macros 12 | %%% Created : 12 Jul 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -define(SDL_BUTTON_LEFT, 1). 16 | -define(SDL_BUTTON_MIDDLE, 2). 17 | -define(SDL_BUTTON_RIGHT, 3). 18 | -define(SDL_BUTTON_X1, 4). 19 | -define(SDL_BUTTON_X2, 5). 20 | -define(SDL_BUTTON_LMASK, 2#00001). 21 | -define(SDL_BUTTON_MMASK, 2#00010). 22 | -define(SDL_BUTTON_RMASK, 2#00100). 23 | -define(SDL_BUTTON_X1MASK, 2#01000). 24 | -define(SDL_BUTTON_X2MASK, 2#10000). 25 | 26 | -------------------------------------------------------------------------------- /include/sdl_joystick.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_joystick.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : 12 | %%% Created : 19 Apr 2001 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -define( SDL_HAT_CENTERED, 16#00). 16 | -define( SDL_HAT_UP, 16#01). 17 | -define( SDL_HAT_RIGHT, 16#02). 18 | -define( SDL_HAT_DOWN, 16#04). 19 | -define( SDL_HAT_LEFT, 16#08). 20 | -define( SDL_HAT_RIGHTUP, (?SDL_HAT_RIGHT bor ?SDL_HAT_UP)). 21 | -define( SDL_HAT_RIGHTDOWN, (?SDL_HAT_RIGHT bor ?SDL_HAT_DOWN)). 22 | -define( SDL_HAT_LEFTUP, (?SDL_HAT_LEFT bor ?SDL_HAT_UP)). 23 | -define( SDL_HAT_LEFTDOWN, (?SDL_HAT_LEFT bor ?SDL_HAT_DOWN)). 24 | 25 | -------------------------------------------------------------------------------- /c_src/esdl_gen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | 9 | /* 10 | * General SDL functions. 11 | */ 12 | 13 | #include "esdl.h" 14 | #include 15 | 16 | void es_init(sdl_data *sd, int len, char *bp) 17 | { 18 | Uint32 mode; 19 | 20 | mode = * (Uint32 *) bp; 21 | if (SDL_Init(mode) < 0) { 22 | char* e = SDL_GetError(); 23 | fprintf(stderr, "Couldn't initialize SDL: %s\n\r", e); 24 | } 25 | } 26 | 27 | void es_quit(sdl_data *sd, int len, char * buff) 28 | { 29 | SDL_Quit(); 30 | } 31 | 32 | void es_getError(sdl_data *sd, int len, char *buff) 33 | { 34 | char * err, *bp, *start; 35 | int length; 36 | err = SDL_GetError(); 37 | length = (int) strlen(err); 38 | bp = start = sdl_getbuff(sd, length); 39 | while(*err != '\0') { 40 | put8(bp, *err++); 41 | } 42 | sdl_send(sd, (int) (bp - start)); 43 | } 44 | -------------------------------------------------------------------------------- /rebar.config: -------------------------------------------------------------------------------- 1 | %% -*- erlang -*- 2 | %% Config file for cl-application 3 | {erl_opts, [debug_info, fail_on_warning]}. 4 | 5 | %% Also see rebar.config.script 6 | 7 | {port_env, [ 8 | {"linux", "CFLAGS", "$CFLAGS $SDL_CFLAGS"}, 9 | {"linux", "LDFLAGS", "$LDFLAGS $SDL_LIBDIR"}, 10 | 11 | {"darwin", "CFLAGS", "$CFLAGS -ObjC -D_OSX_COCOA -I/opt/X11/include"}, 12 | {"darwin", "LDFLAGS", "$LDFLAGS -framework SDL -rpath @executable_path/../Frameworks"}, 13 | 14 | {"win32", "CFLAGS", "$CFLAGS -DWIN32 -D_WIN32 -D__WIN32__ $SDL_INCDIR"}, 15 | {"win32", "DRV_CFLAGS", "/Zi /W3 $ERL_CFLAGS"}, 16 | {"win32", "ERL_LDFLAGS", " /debug /LIBPATH:$SDL_LIBDIR SDL.lib user32.lib"} 17 | ]}. 18 | 19 | {port_specs, [ 20 | {"priv/sdl_driver.so", 21 | ["c_src/esdl_audio.c", 22 | "c_src/esdl_driver.c", 23 | "c_src/esdl_events.c", 24 | "c_src/esdl_gen.c", 25 | "c_src/esdl_gl.c", 26 | "c_src/esdl_spec.c", 27 | "c_src/esdl_util.c", 28 | "c_src/esdl_video.c", 29 | "c_src/esdl_wrapper.c" 30 | ]} 31 | ]}. 32 | 33 | %% {edoc_opts, [{doclet, edown_doclet}]}. 34 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_compat_if.h: -------------------------------------------------------------------------------- 1 | #ifndef _WOGGLE_COMPAT_IF_H 2 | #define _WOGGLE_COMPAT_IF_H 3 | #include /* faking some of those */ 4 | #include /* and those...*/ 5 | 6 | /* SDL compatibility, implemented in woggle_compat_if.c */ 7 | void wog_compat_if_swap_buffers(sdl_data *sd, int len, char *buff); 8 | void wog_compat_if_list_modes(sdl_data *sd, int len, char *buff); 9 | 10 | void wog_compat_if_set_video_mode(sdl_data *sd, int len, char *buff); 11 | 12 | void wog_compat_if_video_driver_name(sdl_data *sd, int len, char *buff); 13 | 14 | void wog_compat_if_gl_set_attribute(sdl_data *sd, int len, char *buff); 15 | 16 | void wog_compat_if_gl_get_attribute(sdl_data *sd, int len, char *buff); 17 | 18 | void wog_compat_if_wm_get_info(sdl_data *sd, int len, char *buff); 19 | 20 | void wog_compat_if_wm_is_maximized(sdl_data *sd, int len, char *buff); 21 | 22 | void wog_compat_if_video_mode_o_k(sdl_data *sd, int len, char *buff); 23 | 24 | void wog_compat_if_event_state(sdl_data *sd, int len, char *buff); 25 | 26 | void wog_compat_if_poll_event(sdl_data *sd, int len, char *buff); 27 | 28 | /*PLACEHOLDER_FOR_GENERATED_FUNCTIONS*/ 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /woggle/README: -------------------------------------------------------------------------------- 1 | What's this? 2 | 3 | This is only an embryo. It's going to be a lightweight version 4 | of ESDL for applications only demanding windowed mode OpenGL. 5 | 6 | * Woggle has a different event model than SDL's. 7 | * Woggle is SDL derived work although it does not use the SDL libraries. 8 | * Woggle depends on ESDL, but the ESDL driver or SDL itself is not needed 9 | in runtime. No real SDL interfaces are used. ESDL sources are needed 10 | at compile time to keep compatibility with the ESDDL opcodes. 11 | * The erlang modules from ESDL are reused for woggle, which means you 12 | can use woggle and ESDL in the same erlang installation without 13 | clashes. 14 | * I'm starting with windows, convinced that if I only get that working, 15 | X-windows and MacOSX Aqua will be a breeze. 16 | 17 | The name Woggle is an abbreviation of Wings3d OpenGL Engine, 18 | where the extra g is there to avoid questions about pronunciation. 19 | 20 | A Woggle is also some sort of ring that boyscouts wear around their 21 | scarves. The connection between that and an Erlang-OpenGL-interface 22 | still remains to be invented. 23 | 24 | More info when I get more things working. 25 | 26 | /Patrik 27 | -------------------------------------------------------------------------------- /c_src/esdl_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | 15 | #define getPointer(bp) ((void *) get32be((bp))) 16 | #define putPointer(bp, ptr) put32be((bp), ((int) (ptr))) 17 | 18 | 19 | /* We always use 8 bytes to store pointers */ 20 | 21 | #define POPGLPTR(dstp, srcp) \ 22 | do { memcpy(&dstp,srcp,sizeof(void *)); srcp += 8; } while (0) 23 | #define PUSHGLPTR(srcp,dstp) \ 24 | do { memset(dstp,0,8);memcpy(dstp,&srcp,sizeof(void *)); dstp += 8; } while (0) 25 | 26 | #define SDL_UTIL_copySdlImage2GLArrayFunc (SDL_UTIL_H+1) 27 | void copySdlImage2GLArray(sdl_data *, int, char *); 28 | #define SDL_UTIL_DebugFunc (SDL_UTIL_H+2) 29 | void sdl_util_debug(sdl_data *sd, int len, char * buff); 30 | 31 | #define mygl_allocFunc (SDL_UTIL_H+3) 32 | void mygl_alloc(sdl_data *, int, char *); 33 | #define mygl_writeFunc (SDL_UTIL_H+4) 34 | void mygl_write(sdl_data *, int, char *); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /test/testaudio.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% See the file "license.terms" for information on usage and redistribution 3 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | %% 5 | %% $Id$ 6 | %% 7 | %%%---------------------------------------------------------------------- 8 | %%% File : testaudio.erl 9 | %%% Author : Dan Gudmundsson 10 | %%% Purpose : Test the audio functionality 11 | %%% Created : 21 Sep 2000 by Dan Gudmundsson 12 | %%%---------------------------------------------------------------------- 13 | 14 | -module(testaudio). 15 | -author('dgud@erix.ericsson.se'). 16 | 17 | -compile(export_all). 18 | %%-export([Function/Arity, ...]). 19 | 20 | -include("sdl.hrl"). 21 | 22 | go() -> 23 | sdl:init(?SDL_INIT_AUDIO), 24 | 25 | {ASpec,Sample} = sdl_audio:loadWAV("Beep.wav"), 26 | Obtained = sdl_audio:openAudio(ASpec, true), 27 | io:format("Driver: ~s\n", [sdl_audio:audioDrivername()]), 28 | io:format("Obtained: ~p\n", [Obtained]), 29 | sdl_audio:play_audio(Sample, 3), 30 | sdl_audio:pauseAudio(false), 31 | timer:sleep(2500), 32 | sdl_audio:pauseAudio(true), 33 | sdl_audio:freeWAV(Sample), 34 | timer:sleep(500), 35 | sdl_audio:closeAudio(), 36 | sdl:getError(). 37 | -------------------------------------------------------------------------------- /src/sdl_active.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_active.erl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : 12 | %%% Created : 12 Jul 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -module(sdl_active). 16 | 17 | -include("sdl_events.hrl"). 18 | -include("esdl.hrl"). 19 | 20 | -export([getAppState/0, 21 | quitRequested/0]). 22 | 23 | -define(SDL_GetAppState, ?SDL_ACTIVE_HRL+1). 24 | 25 | -import(sdl, [call/2]). 26 | 27 | %% Func: quitRequested 28 | %% Args: none 29 | %% Returns: true | false 30 | %% C-API func: SDL_QuitRequested() 31 | quitRequested() -> 32 | sdl_events:pumpEvents(), 33 | case sdl_events:peepEvents(0, ?SDL_PEEKEVENT, ?SDL_QUITMASK) of 34 | [] -> false; 35 | _ -> true 36 | end. 37 | 38 | %% Func: getAppState 39 | %% Args: none 40 | %% Returns: State (bitmask) 41 | %% C-API func: Uint8 SDL_GetAppState(void); 42 | getAppState() -> 43 | <> = call(?SDL_GetAppState, []), 44 | Res. 45 | -------------------------------------------------------------------------------- /src/esdl.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %%%---------------------------------------------------------------------- 6 | %%% File : esdl.hrl 7 | %%% Author : Dan Gudmundsson 8 | %%% Purpose : 9 | %%% Created : 6 Oct 2000 by Dan Gudmundsson 10 | %%%---------------------------------------------------------------------- 11 | 12 | -ifndef(SDL_HRL). %% These must exactly match those in c_src/esdl.h 13 | 14 | -define(SDL_HRL, 20). 15 | -define(SDL_VIDEO_HRL, 30). 16 | -define(SDL_EVENTS_HRL, 100). 17 | -define(SDL_MOUSE_HRL, 110). 18 | -define(SDL_KEYBOARD_HRL, 120). 19 | -define(SDL_ACTIVE_HRL, 130). 20 | -define(SDL_JOYSTICK_HRL, 133). 21 | -define(SDL_AUDIO_HRL, 150). 22 | -define(SDL_UTIL_HRL, 180). 23 | -define(SDL_TTF_HRL, 200). 24 | -define(SDL_IMG_HRL, 300). 25 | -define(SDL_MAX_FUNCTIONS_HRL, 400). %/* Current Max.. Increase if needed */ 26 | 27 | -define(SDL_Init, ?SDL_HRL + 1). 28 | -define(SDL_Quit, ?SDL_Init + 1). 29 | -define(SDL_GetError, ?SDL_Quit +1). 30 | -define(ESDL_Init_Opengl, ?SDL_GetError +1). 31 | 32 | -endif. 33 | -------------------------------------------------------------------------------- /test/testbin.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% See the file "license.terms" for information on usage and redistribution 3 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | %% 5 | %% $Id$ 6 | %% 7 | %%%---------------------------------------------------------------------- 8 | %%% File : testbin.erl 9 | %%% Author : Dan Gudmundsson 10 | %%% Purpose : 11 | %%% Created : 12 Sep 2000 by Dan Gudmundsson 12 | %%%---------------------------------------------------------------------- 13 | 14 | -module(testbin). 15 | -author('dgud@erix.ericsson.se'). 16 | 17 | -compile(export_all). 18 | %%-export([Function/Arity, ...]). 19 | -include("sdl.hrl"). 20 | 21 | init() -> 22 | go(). 23 | 24 | go() -> 25 | Wrapper = sdl:init(?SDL_INIT_VIDEO), 26 | io:format("Wrapper ~p~n", [Wrapper]), 27 | F32 = sdl_util:malloc(7, ?SDL_FLOAT), 28 | F64 = sdl_util:malloc(7, ?SDL_DOUBLE), 29 | Args = [0.0, 1.0, 1000000.0, 0.000001, -1.0, -1000000.0, -0.000001], 30 | io:format("E Writing ~f ~f ~f ~f ~f ~f ~f~n", Args), 31 | sdl_util:write(F32, Args), 32 | sdl_util:write(F64, Args), 33 | io:format("Reading~n"), 34 | 35 | List32 = sdl_util:read(F32, length(Args)), 36 | io:format("E Read32 ~f ~f ~f ~f ~f ~f ~f~n", List32), 37 | List64 = sdl_util:read(F64, length(Args)), 38 | io:format("E Read64 ~f ~f ~f ~f ~f ~f ~f~n", List64), 39 | ok. 40 | -------------------------------------------------------------------------------- /include/sdl_audio.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_video.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : defines from SDL_audio.h 12 | %%% Created : 9 Aug 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | %% Data Types 16 | 17 | -record(audiospec, 18 | {freq, %% Int32 DSP frequency -- samples per second 19 | format, %% Uint16 Audio data format 20 | channels, %% Uint8 Number of channels: 1 mono, 2 stereo 21 | silence, %% Uint8 Audio buffer silence value (calculated) 22 | samples, %% Uint16 Audio buffer size in samples 23 | padding, %% Uint16 Necessary for some compile environments 24 | size}). %% Uint32 Audio buffer size in bytes (calculated) 25 | 26 | %% Audio format flags (defaults to LSB byte order) 27 | -define(AUDIO_U8, 16#0008). %% Unsigned 8-bit samples 28 | -define(AUDIO_S8, 16#8008). %% Signed 8-bit samples 29 | -define(AUDIO_U16LSB, 16#0010). %% Unsigned 16-bit samples 30 | -define(AUDIO_S16LSB, 16#8010). %% Signed 16-bit samples 31 | -define(AUDIO_U16MSB, 16#1010). %% As above, but big-endian byte order 32 | -define(AUDIO_S16MSB, 16#9010). %% As above, but big-endian byte order 33 | 34 | -define(AUDIO_U16SYS, 16#FFF1). %% Native audio ordering 35 | -define(AUDIO_S16SYS, 16#FFF0). 36 | 37 | -------------------------------------------------------------------------------- /c_src/esdl_wrapper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | /* 9 | Command Handler 10 | Dispatch the work on the functions 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include "esdl.h" 17 | #include "esdl_util.h" 18 | #ifndef APIENTRY 19 | # define APIENTRY 20 | #endif 21 | 22 | typedef struct sdl_code_fn_def { 23 | int op; 24 | char *str; 25 | sdl_fun fn; 26 | } sdl_code_fn; 27 | 28 | static sdl_code_fn code_fns[] = { 29 | 30 | #include "esdl_sdl_fp.h" 31 | 32 | { 0, "LastFunction", NULL}}; 33 | 34 | static void 35 | undefined_function(sdl_data *sd, int len, char *buff) 36 | { 37 | sd->len = -2; 38 | } 39 | 40 | void init_fps(sdl_data* sd) 41 | { 42 | int i; 43 | int n = MAX_FUNCTIONS_H; /* Must be greater than then the last function op */ 44 | int op; 45 | sdl_fun* fun_tab; 46 | char** str_tab; 47 | 48 | fun_tab = sd->fun_tab = malloc((n+1) * sizeof(sdl_fun)); 49 | str_tab = sd->str_tab = malloc((n+1) * sizeof(char*)); 50 | 51 | for (i = 0; i < MAX_FUNCTIONS_H; i++) { 52 | fun_tab[i] = undefined_function; 53 | str_tab[i] = "unknown function"; 54 | } 55 | 56 | for (i = 0; ((op = code_fns[i].op) != 0); i++) { 57 | if (fun_tab[op] == undefined_function) { 58 | fun_tab[op] = code_fns[i].fn; 59 | str_tab[op] = code_fns[i].str; 60 | } else { 61 | fprintf(stderr, 62 | "FParray mismatch in initialization: %d '%s' %d '%s'\r\n", 63 | i, str_tab[op], op, code_fns[i].str); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /woggle/src/woggle.erl: -------------------------------------------------------------------------------- 1 | -module(woggle). 2 | 3 | -define(WOGGLE_PORT,esdl_port). 4 | -define(DRIVER_NAME,"woggle_driver"). 5 | 6 | -include("woggle.hrl"). 7 | -include("woggle_ops.hrl"). 8 | 9 | -compile(export_all). 10 | 11 | init() -> 12 | ok = erl_ddll:load_driver(priv_dir(),?DRIVER_NAME), 13 | Port = open_port({spawn,?DRIVER_NAME},[binary]), 14 | register(?WOGGLE_PORT, Port). 15 | 16 | swapBuffers() -> 17 | cast(?WOGGLE_SwapBuffers,[]). 18 | 19 | listModes() -> 20 | listModesConvert(call(?WOGGLE_ListModes,[])). 21 | 22 | listModesConvert(<<>>) -> 23 | []; 24 | listModesConvert(<>) -> 25 | [#woggle_res{cdepth = D, freq=F, w=W, h=H} | listModesConvert(Rest)]; 26 | listModesConvert(<>) -> 27 | {error,Res}. 28 | 29 | %% PLACEHOLDER_FOR_GENERATED_FUNCTIONS 30 | 31 | %% Same as in sdl.erl, but we should be able to run without 32 | %% most of esdl eventually, so we keep local copies, and omit sdlmem. 33 | 34 | cast(Op, Arg) -> 35 | erlang:port_control(?WOGGLE_PORT, Op, Arg), 36 | ok. 37 | 38 | call(Op, Arg) -> 39 | erlang:port_control(?WOGGLE_PORT, Op, Arg). 40 | 41 | send_bin(Bin) when is_binary(Bin) -> 42 | erlang:port_command(?WOGGLE_PORT, Bin). 43 | 44 | send_bin(Bin, _, _) when is_binary(Bin) -> send_bin(Bin); 45 | send_bin(Term, Mod, Line) -> erlang:error({Mod,Line,unsupported_type,Term}). 46 | 47 | % XXX Fixme 48 | priv_dir() -> 49 | case code:priv_dir(esdl) of 50 | P when list(P) -> 51 | P; 52 | {error, _} -> 53 | case code:is_loaded(?MODULE) of 54 | {file, SDLPath} -> 55 | strip(SDLPath, "ebin/" ++ atom_to_list(?MODULE) 56 | ++ ".beam") ++ "priv/"; 57 | _ -> 58 | atom_to_list(c:pwd()) ++ "../../priv/" 59 | end 60 | end. 61 | 62 | strip(Src, Src) -> 63 | []; 64 | strip([H|R], Src) -> 65 | [H| strip(R, Src)]. 66 | -------------------------------------------------------------------------------- /c_src/esdl_audio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * 7 | * $Id$ 8 | */ 9 | /* Defines the audio functions */ 10 | /* Used for switching */ 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #define SDL_AudioDriverNameFunc AUDIO_H +1 17 | void es_audioDriverName(sdl_data *, int, char *); 18 | #define SDL_OpenAudioFunc SDL_AudioDriverNameFunc +1 19 | void es_openAudio(sdl_data *, int, char *); 20 | #define SDL_GetAudioStatusFunc SDL_OpenAudioFunc +1 21 | void es_getAudioStatus(sdl_data *, int, char *); 22 | #define SDL_PauseAudioFunc SDL_GetAudioStatusFunc +1 23 | void es_pauseAudio(sdl_data *, int, char *); 24 | #define SDL_LoadWAVFunc SDL_PauseAudioFunc +1 25 | void es_loadWAV(sdl_data *, int, char *); 26 | #define SDL_LoadWAV_RWFunc SDL_LoadWAVFunc +1 27 | void es_loadWAV(sdl_data *, int, char *); 28 | #define SDL_FreeWAVFunc SDL_LoadWAV_RWFunc +1 29 | void es_freeWAV(sdl_data *, int, char *); 30 | #define SDL_BuildAudioCVTFunc SDL_FreeWAVFunc +1 31 | void es_buildAudioCVT(sdl_data *, int, char *); 32 | #define SDL_ConvertAudioFunc SDL_BuildAudioCVTFunc +1 33 | void es_convertAudio(sdl_data *, int, char *); 34 | #define SDL_MixAudioFunc SDL_ConvertAudioFunc +1 35 | void es_mixAudio(sdl_data *, int, char *); 36 | #define SDL_LockAudioFunc SDL_MixAudioFunc +1 37 | void es_lockAudio(sdl_data *, int, char *); 38 | #define SDL_UnlockAudioFunc SDL_LockAudioFunc +1 39 | void es_unlockAudio(sdl_data *, int, char *); 40 | #define SDL_CloseAudioFunc SDL_UnlockAudioFunc +1 41 | void es_closeAudio(sdl_data *, int, char *); 42 | #define play_audioFunc SDL_CloseAudioFunc +1 43 | void play_audio(sdl_data *, int, char *); 44 | 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /license.terms: -------------------------------------------------------------------------------- 1 | This software is copyrighted by Dan Gudmundsson, and other parties. 2 | The following terms apply to all files associated with the software unless 3 | explicitly disclaimed in individual files. 4 | 5 | The authors hereby grant permission to use, copy, modify, distribute, 6 | and license this software and its documentation for any purpose, provided 7 | that existing copyright notices are retained in all copies and that this 8 | notice is included verbatim in any distributions. No written agreement, 9 | license, or royalty fee is required for any of the authorized uses. 10 | Modifications to this software may be copyrighted by their authors 11 | and need not follow the licensing terms described here, provided that 12 | the new terms are clearly indicated on the first page of each file where 13 | they apply. 14 | 15 | IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY 16 | FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 17 | ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY 18 | DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE 19 | POSSIBILITY OF SUCH DAMAGE. 20 | 21 | THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE 24 | IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE 25 | NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 26 | MODIFICATIONS. 27 | 28 | GOVERNMENT USE: If you are acquiring this software on behalf of the 29 | U.S. government, the Government shall have only "Restricted Rights" 30 | in the software and related documentation as defined in the Federal 31 | Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you 32 | are acquiring the software on behalf of the Department of Defense, the 33 | software shall be classified as "Commercial Computer Software" and the 34 | Government shall have only "Restricted Rights" as defined in Clause 35 | 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the 36 | authors grant the U.S. Government and others acting in its behalf 37 | permission to use and distribute the software in accordance with the 38 | terms specified in this license. 39 | -------------------------------------------------------------------------------- /c_src/Makefile.macosx: -------------------------------------------------------------------------------- 1 | # -*- makefile -*- 2 | # 3 | # Copyright (c) 2001-2009 Dan Gudmundsson, Bjorn Gustavsson 4 | # 5 | # See the file "license.terms" for information on usage and redistribution 6 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 7 | # 8 | 9 | # Uncomment the two lines beginning with UNIVERSAL below if you want 10 | # to build universal binaries that will work on both Tiger and Leopard. 11 | # 12 | # You will also need to do 13 | # 14 | # export MACOSX_DEPLOYMENT_TARGET=10.4 15 | # 16 | # in a bash shell before running this Makefile. 17 | # 18 | 19 | #UNIVERSAL_SDK = -isysroot /Developer/SDKs/MacOSX10.4u.sdk 20 | #UNIVERSAL_FLAGS = $(UNIVERSAL_SDK) -arch i386 -arch ppc 21 | 22 | # or 23 | UNIVERSAL_FLAGS = -arch i386 24 | CC = cc 25 | 26 | # 27 | # The settings of CFLAGS and LDFLAGS that follows assume 28 | # the SDL framework has been installed in /Library/Frameworks. 29 | # 30 | 31 | CFLAGS = -g -O2 -Wall -ObjC -D_THREAD_SAFE -D_REENTRANT -D_OSX_COCOA -I/Library/Frameworks/SDL.framework/Headers -F/Library/Frameworks $(ERLINC) $(UNIVERSAL_FLAGS) 32 | 33 | LDFLAGS = -F/Library/Frameworks -framework SDL -framework IOKit -framework Carbon -framework Cocoa -L. $(UNIVERSAL_FLAGS) 34 | 35 | TARGETDIR = ../priv 36 | 37 | ## The driver part needs erlang includes 38 | ERL_DIR := $(shell echo 'io:format("~s~n",[code:root_dir()]),halt().' | erl | sed 's,^[0-9]*> *,,g' | tail +2) 39 | ERLINC = -I$(ERL_DIR)/usr/include 40 | 41 | # Files 42 | 43 | COMMON = esdl_wrapper esdl_gen esdl_spec esdl_util \ 44 | esdl_video esdl_events esdl_audio \ 45 | esdl_gl 46 | 47 | COMMON_OBJ = $(COMMON:%=%.o) 48 | 49 | # Targets 50 | 51 | target: $(TARGETDIR)/sdl_driver.so 52 | 53 | clean: 54 | rm -f $(COMMON_OBJ) 55 | rm -f ../priv/*.so ../priv/sdlwrapper *.o libsdlmain.a 56 | rm -f *~ erl_crash.dump 57 | 58 | ## 59 | ## 60 | 61 | %.o: %.c 62 | $(CC) -c $(CFLAGS) $< 63 | 64 | %.o: %.m 65 | $(CC) -c -I/Library/Frameworks/SDL.framework/Headers $(CFLAGS) $< 66 | 67 | 68 | esdl_driver.o : esdl_driver.c 69 | $(CC) -c -ObjC $(CFLAGS) $(ERLINC) $< 70 | 71 | esdl_video.o : esdl_video.c 72 | $(CC) -c -ObjC $(CFLAGS) $(ERLINC) $< 73 | 74 | ## 75 | ## sdl_driver.so 76 | 77 | $(TARGETDIR)/sdl_driver.so: esdl_driver.o $(COMMON_OBJ) 78 | $(CC) $< $(COMMON_OBJ) $(LDFLAGS) -bundle -flat_namespace -undefined suppress -o $@ 79 | -------------------------------------------------------------------------------- /include/sdl.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%% Defines for SDL 9 | %%% see documentation for SDL and SDL/sdl.h 10 | %%% 11 | %%% By Dan Gudmundsson 12 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 13 | %% sdl.h 14 | 15 | -define(SDL_INIT_TIMER, 16#00000001). 16 | -define(SDL_INIT_AUDIO, 16#00000010). 17 | -define(SDL_INIT_VIDEO, 16#00000020). 18 | -define(SDL_INIT_CDROM, 16#00000100). 19 | -define(SDL_INIT_JOYSTICK, 16#00000200). 20 | -define(SDL_INIT_NOPARACHUTE, 16#00100000). 21 | -define(SDL_INIT_EVENTTHREAD, 16#01000000). %% Don't work on windows and in the driver 22 | -define(SDL_INIT_EVERYTHING, 16#0000FFFF). 23 | 24 | -define(SDL_INIT_NOERLDRIVER, 16#02000000). %% Don't use the linked in driver 25 | -define(SDL_INIT_ERLDRIVER, 16#04000000). %% Use the linked driver 26 | 27 | -define(printError(), 28 | fun([]) -> ignore; 29 | (Estr) -> 30 | io:format("SDL Error in ~p ~p: " ++ Estr ++"~n", 31 | [?MODULE, ?LINE]) 32 | end (sdl:getError())). 33 | 34 | -define(SDL_USES_WX_GL, 1). 35 | 36 | -define(GL_BYTE_SIZE, 8). 37 | -define(GL_UNSIGNED_BYTE_SIZE, 8). 38 | -define(GL_SHORT_SIZE, 16). 39 | -define(GL_UNSIGNED_SHORT_SIZE, 16). 40 | -define(GL_INT_SIZE, 32). 41 | -define(GL_UNSIGNED_INT_SIZE, 32). 42 | -define(GL_FLOAT_SIZE, 32). 43 | -define(GL_DOUBLE_SIZE, 64). 44 | 45 | -define(gl_type_size(TYPE), 46 | case (TYPE) of 47 | 16#1400 -> ?GL_BYTE_SIZE; 48 | 16#1401 -> ?GL_UNSIGNED_BYTE_SIZE; 49 | 16#1402 -> ?GL_SHORT_SIZE; 50 | 16#1403 -> ?GL_UNSIGNED_SHORT_SIZE; 51 | 16#1404 -> ?GL_INT_SIZE; 52 | 16#1405 -> ?GL_UNSIGNED_INT_SIZE; 53 | 16#1406 -> ?GL_FLOAT_SIZE; 54 | 16#140A -> ?GL_DOUBLE_SIZE 55 | end). 56 | 57 | -define(SDL_BYTE, 16#1400). 58 | -define(SDL_UNSIGNED_BYTE, 16#1401). 59 | -define(SDL_SHORT, 16#1402). 60 | -define(SDL_UNSIGNED_SHORT, 16#1403). 61 | -define(SDL_INT, 16#1404). 62 | -define(SDL_UNSIGNED_INT, 16#1405). 63 | -define(SDL_FLOAT, 16#1406). 64 | -define(SDL_2_BYTES, 16#1407). 65 | -define(SDL_3_BYTES, 16#1408). 66 | -define(SDL_4_BYTES, 16#1409). 67 | -define(SDL_DOUBLE, 16#140A). 68 | -define(SDL_DOUBLE_EXT, 16#140A). 69 | -------------------------------------------------------------------------------- /woggle/c_src/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2001 Dan Gudmundsson and Patrik Nyblom 2 | # See the file "license.terms" for information on usage and redistribution 3 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | # 5 | # $Id$ 6 | # 7 | 8 | ifeq ($(OS_FLAG), mingw) 9 | include ../../win32_conf/mingw_vars.mk 10 | LIBS := $(GL_LIBS) -lgdi32 11 | 12 | TARGETDIR = ../../priv 13 | 14 | GCC_O = $(CC) -c $(CFLAGS) $< 15 | 16 | ESDL_SRC = ../../c_src 17 | 18 | # Optimization currently disabled 19 | #CFLAGS := -g -O2 -funroll-loops -Wall -ffast-math -fomit-frame-pointer \ 20 | # -DWIN32 -D_WIN32 -D__WIN32__ -DFLAVOUR_WOGGLE $(GL_INCS) $(ERL_INCS) \ 21 | # -I$(ESDL_SRC) -I. 22 | CFLAGS := -g -Wall \ 23 | -DWIN32 -D_WIN32 -D__WIN32__ -DFLAVOUR_WOGGLE $(GL_INCS) $(ERL_INCS) \ 24 | -I$(ESDL_SRC) -I. 25 | 26 | # Files 27 | 28 | TSOURCES = woggle_win.c woggle_test.c 29 | SOURCES = \ 30 | woggle_win.c \ 31 | woggle_driver.c \ 32 | woggle_wrapper.c \ 33 | woggle_if.c \ 34 | woggle_compat_if.c \ 35 | $(ESDL_SRC)/esdl_gl.c \ 36 | $(ESDL_SRC)/esdl_glu.c \ 37 | $(ESDL_SRC)/esdl_glext.c \ 38 | $(ESDL_SRC)/esdl_util.c 39 | 40 | 41 | TOBJECTS = $(TSOURCES:%.c=%.o) 42 | OBJECTS0 = $(SOURCES:%.c=%.o) 43 | OBJECTS = $(OBJECTS0:$(ESDL_SRC)/%.o=%.o) 44 | 45 | THEADERS = woggle_win.h 46 | HEADERS = woggle_win.h woggle_driver.h woggle_if.h woggle_if_fp.h\ 47 | $(ESDL_SRC)/esdl_gl.h $(ESDL_SRC)/esdl_gl_fp.h \ 48 | $(ESDL_SRC)/esdl_glext.h $(ESDL_SRC)/esdl_glext_fp.h \ 49 | $(ESDL_SRC)/esdl_glu.h $(ESDL_SRC)/esdl_glu_fp.h \ 50 | $(ESDL_SRC)/esdl_util.h 51 | 52 | TTARGET = ./woggle_test.exe 53 | TOBJECTS = ./woggle_test.o woggle_win.o 54 | TARGET = $(TARGETDIR)/woggle_driver.$(SOEXT) 55 | TARGET_JUNK = $(TARGETDIR)/woggle_driver.lib $(TARGETDIR)/woggle_driver.exp 56 | 57 | all: $(TARGET) $(TTARGET) 58 | @echo Build done 59 | 60 | clean: 61 | rm -f $(OBJECTS) $(TOBJECTS) 62 | rm -f $(TARGET) $(TTARGET) $(TARGET_JUNK) 63 | rm -f *~ erl_crash.dump 64 | 65 | %.o: %.c $(HEADERS) 66 | $(GCC_O) 67 | 68 | %.o: $(ESDL_SRC)/%.c $(HEADERS) 69 | $(GCC_O) 70 | 71 | $(TTARGET): $(TOBJECTS) 72 | $(CC) $(CFLAGS) $(TOBJECTS) $(LIBS) -o $(TTARGET) 73 | 74 | $(TARGET): $(OBJECTS) 75 | $(CC) $(CLINKFLAGS) $(CFLAGS) $(ERL_INCS) $(OBJECTS) $(LIBS) -o $(TARGET) 76 | rm -f $(TARGET_JUNK) 77 | 78 | 79 | else 80 | 81 | target clean: 82 | @echo Only windows for now. 83 | 84 | endif 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/sdl_img_funcs.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2007 Klas Johansson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_img_funcs.hrl 10 | %%% Author : Klas Johansson 11 | %%% Purpose : 12 | %%% Created : 18 Feb 2007 by Klas Johansson 13 | %%%---------------------------------------------------------------------- 14 | 15 | %%% Functions 16 | -include("esdl.hrl"). 17 | 18 | -define(SDL_IMG_LinkedVersion, ?SDL_IMG_HRL + 1). 19 | -define(SDL_IMG_LoadTypedRW, ?SDL_IMG_LinkedVersion + 1). 20 | -define(SDL_IMG_Load, ?SDL_IMG_LoadTypedRW + 1). 21 | -define(SDL_IMG_LoadRW, ?SDL_IMG_Load + 1). 22 | -define(SDL_IMG_InvertAlpha, ?SDL_IMG_LoadRW + 1). 23 | -define(SDL_IMG_isBMP, ?SDL_IMG_InvertAlpha + 1). 24 | -define(SDL_IMG_isPNM, ?SDL_IMG_isBMP + 1). 25 | -define(SDL_IMG_isXPM, ?SDL_IMG_isPNM + 1). 26 | -define(SDL_IMG_isXCF, ?SDL_IMG_isXPM + 1). 27 | -define(SDL_IMG_isPCX, ?SDL_IMG_isXCF + 1). 28 | -define(SDL_IMG_isGIF, ?SDL_IMG_isPCX + 1). 29 | -define(SDL_IMG_isJPG, ?SDL_IMG_isGIF + 1). 30 | -define(SDL_IMG_isTIF, ?SDL_IMG_isJPG + 1). 31 | -define(SDL_IMG_isPNG, ?SDL_IMG_isTIF + 1). 32 | -define(SDL_IMG_isLBM, ?SDL_IMG_isPNG + 1). 33 | -define(SDL_IMG_LoadBMPRW, ?SDL_IMG_isLBM + 1). 34 | -define(SDL_IMG_LoadPNMRW, ?SDL_IMG_LoadBMPRW + 1). 35 | -define(SDL_IMG_LoadXPMRW, ?SDL_IMG_LoadPNMRW + 1). 36 | -define(SDL_IMG_LoadXCFRW, ?SDL_IMG_LoadXPMRW + 1). 37 | -define(SDL_IMG_LoadPCXRW, ?SDL_IMG_LoadXCFRW + 1). 38 | -define(SDL_IMG_LoadGIFRW, ?SDL_IMG_LoadPCXRW + 1). 39 | -define(SDL_IMG_LoadJPGRW, ?SDL_IMG_LoadGIFRW + 1). 40 | -define(SDL_IMG_LoadTIFRW, ?SDL_IMG_LoadJPGRW + 1). 41 | -define(SDL_IMG_LoadPNGRW, ?SDL_IMG_LoadTIFRW + 1). 42 | -define(SDL_IMG_LoadTGARW, ?SDL_IMG_LoadPNGRW + 1). 43 | -define(SDL_IMG_LoadLBMRW, ?SDL_IMG_LoadTGARW + 1). 44 | -define(SDL_IMG_ReadXPMFromArray, ?SDL_IMG_LoadLBMRW + 1). 45 | -define(SDL_IMG_SetError, ?SDL_IMG_ReadXPMFromArray + 1). 46 | -define(SDL_IMG_GetError, ?SDL_IMG_SetError + 1). 47 | -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- 1 | ESDL - SDL and OpenGL for Erlang 2 | 3 |

ESDL Introduction

4 |

5 | ESDL is an api which invokes corresponding functions in the 6 | Sdl and Opengl libraries. 7 |

8 | 9 |

Since most of the functions are 1 to 1 mapping to the original 10 | libraries, the descriptions (if any) are brief. For detailed 11 | descriptions and manual pages take a look at the 12 | SDL and 13 | Opengl sites which should 14 | be able guide you to the documentation. I have tried to generate link 15 | to the descriptions on net, but may have failed in some cases. 16 |

17 | 18 |

19 | With some common sense you should be able to figure out the arguments 20 | and return values to the functions. Arguments in the 'C' libraries that 21 | are used as out parameters, are often returned as a tuple with values. 22 | C functions that take pointer to an array as argument takes a list 23 | as argument in erlang (and/or tuple). 24 |

25 | 26 |

The thing that differs are of course the memory handling and 27 | memory references, check out the examples. 28 |

29 | 30 |

31 | If you have complaints of non trivial (or errors) arguments or return values, 32 | send me an email and I'll try to update the documentation or (the fast way) 33 | check the source. 34 |

35 | 36 |

SDL commands

37 |

38 | Init and Quit Functions
39 | Video Functions
40 | Audio Functions
41 | General Event Functions
42 | TTF Functions
43 | Image Functions
44 |

50 |

OpenGL

51 |

52 | Opengl functions that uses pointers requires 53 | that you use the memory functions in sdl_util 54 | to handle the memory references. 55 | 56 |
57 | GL Functions
58 | GLU Functions
59 | 60 |

Additions

61 | Memory and Utility functions
62 | 63 | -------------------------------------------------------------------------------- /src/sdl_keyboard.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_keyboard.erl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : 12 | %%% Created : 12 Jul 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -module(sdl_keyboard). 16 | 17 | -include("esdl.hrl"). 18 | 19 | %%-compile(export_all). 20 | -export([enableKeyRepeat/2, 21 | enableUNICODE/1, 22 | getKeyName/1, 23 | getKeyState/0, 24 | getModState/0, 25 | setModState/1]). 26 | 27 | -define(SDL_EnableUNICODE, ?SDL_KEYBOARD_HRL+1). 28 | -define(SDL_EnableKeyRepeat, ?SDL_EnableUNICODE+1). 29 | -define(SDL_GetKeyName, ?SDL_EnableKeyRepeat+1). 30 | -define(SDL_GetKeyState, ?SDL_GetKeyName+1). 31 | -define(SDL_GetModState, ?SDL_GetKeyState+1). 32 | -define(SDL_SetModState, ?SDL_GetModState+1). 33 | 34 | -import(sdl, [call/2,cast/2]). 35 | 36 | %%%%%%%%%%%%%%%% KEYBOARD FUNCTIONS %%%%%%%%%%%%%%%%%%% 37 | %% Func: getKeyState 38 | %% Args: none 39 | %% Returns: A tuple continaing the state of each key(i.e. state of each Key) 40 | %% C-API func: Uint8 * SDL_GetKeyState(int *numkeys); 41 | getKeyState() -> 42 | Res = call(?SDL_GetKeyState, []), 43 | list_to_tuple(binary_to_list(Res)). 44 | 45 | %% Func: SDL_EnableUNICODE 46 | %% Args: true | false 47 | %% Returns: Previous Setting (true | False) 48 | %% C-API func: int SDL_EnableUNICODE(int enable); 49 | %% Desc: 50 | enableUNICODE(Bool) -> 51 | B = if Bool == true -> 1; true -> 0 end, 52 | <> = call(?SDL_EnableUNICODE, [B]), 53 | Res. 54 | 55 | %% Func: SDL_EnableKeyRepeat 56 | %% Args: Delay Interval 57 | %% Returns: true | false (if failure) 58 | %% C-API func: int SDL_EnableKeyRepeat(int delay, int interval); 59 | %% Desc: 60 | enableKeyRepeat(Delay, Interval) -> 61 | <> = call(?SDL_EnableKeyRepeat, <>), 62 | Res =:= 0. 63 | 64 | %% Func: SDL_GetKeyName 65 | %% Args: SDLKey 66 | %% Returns: A string 67 | %% C-API func: char * SDL_GetKeyName(SDLKey key); 68 | %% Desc: 69 | getKeyName(Key) -> 70 | binary_to_list(call(?SDL_GetKeyName, <>)). 71 | 72 | %% Func: getModState 73 | %% Args: none 74 | %% Returns: KModState (see KMOD_* in sdl_keyboard.hrl) 75 | %% C-API func: SDLMod SDL_GetModState(void); 76 | getModState() -> 77 | case call(?SDL_GetModState, []) of 78 | [] -> 0; 79 | <> -> Res 80 | end. 81 | 82 | %% Func: setModState 83 | %% Args: KModState (see KMOD_* in sdl_keyboard.hrl) 84 | %% Returns: ok 85 | %% C-API func: void SDL_SetModState(SDLMod modstate); 86 | setModState(ModState) -> 87 | cast(?SDL_SetModState, <>). 88 | 89 | 90 | -------------------------------------------------------------------------------- /c_src/esdl_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | /* 9 | * Some useful extra functions 10 | */ 11 | 12 | #ifdef _WIN32 13 | #include 14 | #endif 15 | 16 | #include 17 | #include /* malloc */ 18 | #ifdef FLAVOUR_WOGGLE 19 | #include 20 | #else 21 | #include "esdl.h" 22 | #endif 23 | 24 | void mygl_alloc(sdl_data *sd, int len, char *bp) 25 | { 26 | char *start; 27 | unsigned size; 28 | 29 | size = * (unsigned *) bp; 30 | bp = start = sdl_getbuff(sd, size); 31 | sdl_send(sd, size); 32 | } 33 | 34 | void mygl_write(sdl_data *sd, int len, char *bp) 35 | { 36 | if (sd->next_bin == 1) { 37 | memcpy(sd->bin[0].base, bp, len); 38 | } else if (sd->next_bin == 2) { 39 | memcpy(sd->bin[0].base, sd->bin[1].base, sd->bin[1].size); 40 | } 41 | sdl_free_binaries(sd); 42 | } 43 | #ifndef FLAVOUR_WOGGLE 44 | void copySdlImage2GLArray(sdl_data *sd, int len, char * buff) 45 | { 46 | Uint8 *rowhi, *rowlo, type; 47 | SDL_Surface *image; 48 | unsigned char * mem; 49 | char *bp, *start; 50 | int i, j = 0, k; 51 | Uint8 rs,bs,gs,as; 52 | 53 | bp = buff; 54 | POPGLPTR(image, bp); 55 | type = *bp; 56 | if (sd->next_bin == 1) { 57 | mem = (unsigned char *) sd->bin[0].base; 58 | 59 | #if SDL_BYTEORDER == SDL_BIG_ENDIAN 60 | rs = (2 - image->format->Rshift/8); 61 | gs = (2 - image->format->Gshift/8); 62 | bs = (2 - image->format->Bshift/8); 63 | as = (2 - image->format->Ashift/8); 64 | #else 65 | rs = image->format->Rshift/8; 66 | gs = image->format->Gshift/8; 67 | bs = image->format->Bshift/8; 68 | as = image->format->Ashift/8; 69 | #endif 70 | /* GL surfaces are upsidedown (according to SDL examples)?? */ 71 | k = 0; 72 | rowhi = (Uint8 *)image->pixels; 73 | rowlo = rowhi + (image->h * image->pitch) - image->pitch; 74 | 75 | for(i=0; ih; ++i ) { 76 | for(j=0; jw; ++j ) { 77 | switch(image->format->BytesPerPixel) 78 | { 79 | case 1: 80 | mem[k++] = image->format->palette->colors[rowlo[j]].r; 81 | mem[k++] = image->format->palette->colors[rowlo[j]].g; 82 | mem[k++] = image->format->palette->colors[rowlo[j]].b; 83 | if(type == 4) 84 | mem[k++] = 0; 85 | break; 86 | case 3: 87 | mem[k++] = rowlo[j*3 + rs]; 88 | mem[k++] = rowlo[j*3 + gs]; 89 | mem[k++] = rowlo[j*3 + bs]; 90 | if(type == 4) 91 | mem[k++] = 0; 92 | break; 93 | case 4: 94 | mem[k++] = rowlo[j*4 + rs]; 95 | mem[k++] = rowlo[j*4 + gs]; 96 | mem[k++] = rowlo[j*4 + bs]; 97 | if(type == 4) 98 | mem[k++] = rowlo[j*4 + as]; 99 | break; 100 | } 101 | } 102 | rowlo -= image->pitch; 103 | } 104 | /* fprintf(stderr, "i %d, j %d k%d\n\r", i, j, k); */ 105 | start = sdl_get_temp_buff(sd, 2); 106 | start[0] = 1; 107 | sdl_send(sd, 1); 108 | sdl_free_binaries(sd); 109 | } 110 | } 111 | #endif 112 | -------------------------------------------------------------------------------- /src/sdl_ttf_funcs.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2007 Klas Johansson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_ttf_funcs.hrl 10 | %%% Author : Klas Johansson 11 | %%% Purpose : 12 | %%% Created : 29 Jan 2007 by Klas Johansson 13 | %%%---------------------------------------------------------------------- 14 | 15 | %%% Functions 16 | -include("esdl.hrl"). 17 | 18 | -define(SDL_TTF_LinkedVersion, ?SDL_TTF_HRL + 1). 19 | -define(SDL_TTF_ByteSwappedUNICODE, ?SDL_TTF_LinkedVersion + 1). 20 | -define(SDL_TTF_Init, ?SDL_TTF_ByteSwappedUNICODE + 1). 21 | -define(SDL_TTF_OpenFont, ?SDL_TTF_Init + 1). 22 | -define(SDL_TTF_OpenFontIndex, ?SDL_TTF_OpenFont + 1). 23 | -define(SDL_TTF_OpenFontRW, ?SDL_TTF_OpenFontIndex + 1). 24 | -define(SDL_TTF_OpenFontIndexRW, ?SDL_TTF_OpenFontRW + 1). 25 | -define(SDL_TTF_GetFontStyle, ?SDL_TTF_OpenFontIndexRW + 1). 26 | -define(SDL_TTF_SetFontStyle, ?SDL_TTF_GetFontStyle + 1). 27 | -define(SDL_TTF_FontHeight, ?SDL_TTF_SetFontStyle + 1). 28 | -define(SDL_TTF_FontAscent, ?SDL_TTF_FontHeight + 1). 29 | -define(SDL_TTF_FontDescent, ?SDL_TTF_FontAscent + 1). 30 | -define(SDL_TTF_FontLineSkip, ?SDL_TTF_FontDescent + 1). 31 | -define(SDL_TTF_FontFaces, ?SDL_TTF_FontLineSkip + 1). 32 | -define(SDL_TTF_FontFaceIsFixedWidth, ?SDL_TTF_FontFaces + 1). 33 | -define(SDL_TTF_FontFaceFamilyName, ?SDL_TTF_FontFaceIsFixedWidth + 1). 34 | -define(SDL_TTF_FontFaceStyleName, ?SDL_TTF_FontFaceFamilyName + 1). 35 | -define(SDL_TTF_GlyphMetrics, ?SDL_TTF_FontFaceStyleName + 1). 36 | -define(SDL_TTF_SizeText, ?SDL_TTF_GlyphMetrics + 1). 37 | -define(SDL_TTF_SizeUTF8, ?SDL_TTF_SizeText + 1). 38 | -define(SDL_TTF_SizeUNICODE, ?SDL_TTF_SizeUTF8 + 1). 39 | -define(SDL_TTF_RenderTextSolid, ?SDL_TTF_SizeUNICODE + 1). 40 | -define(SDL_TTF_RenderUTF8Solid, ?SDL_TTF_RenderTextSolid + 1). 41 | -define(SDL_TTF_RenderUNICODESolid, ?SDL_TTF_RenderUTF8Solid + 1). 42 | -define(SDL_TTF_RenderGlyphSolid, ?SDL_TTF_RenderUNICODESolid + 1). 43 | -define(SDL_TTF_RenderTextShaded, ?SDL_TTF_RenderGlyphSolid + 1). 44 | -define(SDL_TTF_RenderUTF8Shaded, ?SDL_TTF_RenderTextShaded + 1). 45 | -define(SDL_TTF_RenderUNICODEShaded, ?SDL_TTF_RenderUTF8Shaded + 1). 46 | -define(SDL_TTF_RenderGlyphShaded, ?SDL_TTF_RenderUNICODEShaded + 1). 47 | -define(SDL_TTF_RenderTextBlended, ?SDL_TTF_RenderGlyphShaded + 1). 48 | -define(SDL_TTF_RenderUTF8Blended, ?SDL_TTF_RenderTextBlended + 1). 49 | -define(SDL_TTF_RenderUNICODEBlended, ?SDL_TTF_RenderUTF8Blended + 1). 50 | -define(SDL_TTF_RenderGlyphBlended, ?SDL_TTF_RenderUNICODEBlended + 1). 51 | -define(SDL_TTF_CloseFont, ?SDL_TTF_RenderGlyphBlended + 1). 52 | -define(SDL_TTF_Quit, ?SDL_TTF_CloseFont + 1). 53 | -define(SDL_TTF_WasInit, ?SDL_TTF_Quit + 1). 54 | -define(SDL_TTF_SetError, ?SDL_TTF_WasInit + 1). 55 | -define(SDL_TTF_GetError, ?SDL_TTF_SetError + 1). 56 | -------------------------------------------------------------------------------- /src/sdl.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl.erl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : To give access to the Simple Direct Media Layer 12 | %%% by Sam Lantinga, see www.libsdl.org. 13 | %%% Created : 23 Jun 2000 by Dan Gudmundsson 14 | %%%---------------------------------------------------------------------- 15 | 16 | -module(sdl). 17 | 18 | -include("sdl.hrl"). 19 | -include("esdl.hrl"). 20 | -include("sdl_util.hrl"). 21 | 22 | -export([init/1, quit/0, getError/0]). 23 | -export([cast/2, call/2]). 24 | -export([send_bin/1, send_bin/3]). 25 | 26 | %% SDL functions 27 | %%% Functions 28 | 29 | %% Func: init 30 | %% Args: BitMask 31 | %% Returns: WrapperRef 32 | %% C-API func: int SDL_Init(Uint32 flags); 33 | %% Desc: Initializes the SDL (including the erlang specific parts) 34 | init(Flags) when is_integer(Flags) -> 35 | Path = case code:priv_dir(esdl) of 36 | P when is_list(P) -> 37 | P; 38 | {error, _} -> %% in case you use erl -pa ../ebin priv_dir don't work :-( 39 | case code:is_loaded(?MODULE) of 40 | {file, SDLPath} -> 41 | strip(SDLPath, "ebin/" ++ atom_to_list(?MODULE) ++ ".beam") ++ "priv/"; 42 | _ -> %% For debugging 43 | atom_to_list(c:pwd()) ++ "../priv/" 44 | end 45 | end, 46 | case os:type() of 47 | {win32, _} -> 48 | OsPath = Path ++ ";" ++ os:getenv("PATH"), 49 | os:putenv("PATH", OsPath); 50 | _ -> 51 | ignore 52 | end, 53 | case catch erl_ddll:load_driver(Path, "sdl_driver") of 54 | ok -> 55 | ok; 56 | {error, R} -> 57 | io:format("Driver failed: ~s ~n", [erl_ddll:format_error(R)]); 58 | Other -> 59 | io:format("Driver crashed: ~p ~n", [Other]) 60 | end, 61 | Port = open_port({spawn, "sdl_driver"}, [binary]), 62 | register(esdl_port, Port), 63 | cast(?SDL_Init, <>), 64 | Port. 65 | 66 | %% Func: quit 67 | %% Args: none 68 | %% Returns: Quits the wrapper 69 | %% C-API func: void SDL_Quit(void); 70 | quit() -> 71 | %% cast(?SDL_Quit, []), 72 | erlang:port_close(esdl_port), 73 | erl_ddll:unload_driver("sdl_driver"). 74 | 75 | %% Func: getError 76 | %% Args: none 77 | %% Returns: DescString 78 | %% C-API func: char * SDL_GetError(void); 79 | getError() -> 80 | Bin = call(?SDL_GetError, []), 81 | binary_to_list(Bin). 82 | 83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 84 | 85 | cast(Op, Arg) -> 86 | erlang:port_control(esdl_port, Op, Arg), 87 | ok. 88 | 89 | call(Op, Arg) -> 90 | erlang:port_control(esdl_port, Op, Arg). 91 | 92 | send_bin(Bin) when is_binary(Bin) -> 93 | erlang:port_command(esdl_port, Bin). 94 | 95 | send_bin(#sdlmem{bin=Bin}, _, _) -> send_bin(Bin); 96 | send_bin(Bin, _, _) when is_binary(Bin) -> send_bin(Bin); 97 | send_bin(Term, Mod, Line) -> erlang:error({Mod,Line,unsupported_type,Term}). 98 | 99 | %%%%%%%%%%%%%%%%% NON SDL FUNCTIONS %%%%%%%%%%%%%%%% 100 | 101 | strip(Src, Src) -> 102 | []; 103 | strip([H|R], Src) -> 104 | [H| strip(R, Src)]. 105 | -------------------------------------------------------------------------------- /c_src/esdl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | /* Define function's */ 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #ifndef SDL_H 14 | #include 15 | 16 | #ifdef WIN32 17 | #include /* needed by Windows' gl.h etc */ 18 | #include "SDL.h" 19 | #include "SDL_byteorder.h" 20 | #include "SDL_events.h" 21 | #include "SDL_syswm.h" 22 | #else 23 | #include "SDL/SDL.h" 24 | #include "SDL/SDL_byteorder.h" 25 | #include "SDL/SDL_events.h" 26 | #include "SDL/SDL_syswm.h" 27 | #endif 28 | 29 | #include "esdl_conv.h" 30 | 31 | #define MAXBUFF 8000000 /* Covers 1600x1200x4 (32bits) */ 32 | 33 | #define error() {fprintf(stderr, "Error in %s:%d \n\r", __FILE__, __LINE__); return;} 34 | 35 | typedef struct sdl_data_def *sdl_data_ptr; 36 | typedef void (*sdl_fun)(sdl_data_ptr, int, char*); 37 | 38 | typedef sdl_fun (*sdl_load_fun)(void); 39 | 40 | typedef struct { 41 | char* base; 42 | size_t size; 43 | ErlDrvBinary* bin; 44 | } EsdlBinRef; 45 | 46 | typedef struct sdl_data_def { 47 | void* driver_data; /* Port or Driver specific data */ 48 | int use_smp; /* Use a thread for opengl commands */ 49 | sdl_fun* fun_tab; /* Pointers to functions */ 50 | char** str_tab; /* Pointers to function names */ 51 | 52 | int op; /* Current (or last) function */ 53 | int len; /* Length of message buffer */ 54 | void* buff; /* Pointer to message buffer */ 55 | 56 | void* temp_bin; /* Temporary binary */ 57 | EsdlBinRef bin[3]; /* Argument binaries */ 58 | int next_bin; /* Next binary */ 59 | #ifdef _OSX_COCOA 60 | void* release_pool; 61 | void* app; 62 | #endif 63 | } sdl_data; 64 | 65 | void sdl_send(sdl_data *, int); 66 | char* sdl_getbuff(sdl_data*, int); 67 | char* sdl_get_temp_buff(sdl_data*, int); 68 | void sdl_free_binaries(sdl_data*); 69 | 70 | void init_fps(sdl_data*); 71 | void gl_dispatch(sdl_data *, int, ErlDrvSizeT, char *); 72 | void es_init_opengl(sdl_data *, int, char *); 73 | void start_opengl_thread(sdl_data *); 74 | void stop_opengl_thread(); 75 | void * esdl_gl_sync(); 76 | 77 | /* These must exactly match those in src/esdl.hrl */ 78 | #define SDL_H 20 79 | #define VIDEO_H 30 80 | #define EVENTS_H 100 81 | #define MOUSE_H 110 82 | #define KEYBOARD_H 120 83 | #define ACTIVE_H 130 84 | #define JOYSTICK_H 133 85 | #define AUDIO_H 150 86 | #define SDL_UTIL_H 180 87 | #define TTF_H 200 88 | #define IMG_H 300 89 | #define MAX_FUNCTIONS_H 400 /* Current Max.. Increase if needed */ 90 | 91 | #define OPENGL_START 5000 /* see wx/c_src/wxe_driver.h */ 92 | 93 | #define SDL_InitFunc (SDL_H + 1) 94 | #define SDL_QuitFunc (SDL_InitFunc + 1) 95 | #define SDL_GetErrorFunc (SDL_QuitFunc + 1) 96 | #define ESDL_OpenglInitFunc (SDL_GetErrorFunc + 1) 97 | 98 | #include "esdl_video.h" 99 | #include "esdl_events.h" 100 | #include "esdl_audio.h" 101 | #include "esdl_util.h" 102 | #include "esdl_ttf.h" 103 | #include "esdl_img.h" 104 | 105 | void es_init(sdl_data *sd, int len, char * buff); 106 | void es_quit(sdl_data *sd, int len, char * buff); 107 | void es_getError(sdl_data *sd, int len, char *buff); 108 | 109 | void esdl_init_native_gui(); 110 | 111 | #endif 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | -------------------------------------------------------------------------------- /c_src/esdl_conv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | 9 | /*************************** 10 | Some Macros to the byte conversion 11 | between the byte buffer and real types. 12 | This code is borrowed from the erl_interface 13 | file putget.h 14 | ****************************/ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #ifndef BYTECONV_H 21 | #define BYTECONV_H 22 | 23 | #define put8(s,n) do { \ 24 | (s)[0] = (char)((n) & 0xff); \ 25 | (s) += 1; \ 26 | } while (0) 27 | 28 | #define put16le(s,n) do { \ 29 | (s)[0] = (n) & 0xff; \ 30 | (s)[1] = ((n) >> 8) & 0xff; \ 31 | (s) += 2; \ 32 | } while (0) \ 33 | 34 | #define put32le(s,n) do { \ 35 | (s)[0] = (n) & 0xff; \ 36 | (s)[1] = ((n) >> 8) & 0xff; \ 37 | (s)[2] = ((n) >> 16) & 0xff; \ 38 | (s)[3] = ((n) >> 24) & 0xff; \ 39 | (s) += 4; \ 40 | } while (0) 41 | 42 | #define put16be(s,n) do { \ 43 | (s)[0] = ((n) >> 8) & 0xff; \ 44 | (s)[1] = (n) & 0xff; \ 45 | (s) += 2; \ 46 | } while (0) 47 | 48 | #define put32be(s,n) do { \ 49 | (s)[0] = ((n) >> 24) & 0xff; \ 50 | (s)[1] = ((n) >> 16) & 0xff; \ 51 | (s)[2] = ((n) >> 8) & 0xff; \ 52 | (s)[3] = (n) & 0xff; \ 53 | (s) += 4; \ 54 | } while (0) 55 | 56 | #define get8(s) \ 57 | ((s) += 1, \ 58 | ((unsigned char *)(s))[-1] & 0xff) 59 | 60 | #define get16le(s) \ 61 | ((s) += 2, \ 62 | (((((unsigned char *)(s))[-1] << 8) | \ 63 | ((unsigned char *)(s))[-2])) & 0xffff) 64 | 65 | #define get32le(s) \ 66 | ((s) += 4, \ 67 | ((((unsigned char *)(s))[-1] << 24) | \ 68 | (((unsigned char *)(s))[-2] << 16) | \ 69 | (((unsigned char *)(s))[-3] << 8) | \ 70 | ((unsigned char *)(s))[-4])) 71 | 72 | #define get16be(s) \ 73 | ((s) += 2, \ 74 | (((((unsigned char *)(s))[-2] << 8) | \ 75 | ((unsigned char *)(s))[-1])) & 0xffff) 76 | 77 | #define get32be(s) \ 78 | ((s) += 4, \ 79 | ((((unsigned char *)(s))[-4] << 24) | \ 80 | (((unsigned char *)(s))[-3] << 16) | \ 81 | (((unsigned char *)(s))[-2] << 8) | \ 82 | ((unsigned char *)(s))[-1])) 83 | 84 | #if SDL_BYTEORDER == SDL_BIG_ENDIAN 85 | 86 | #define putFloat32be(s,n) do { \ 87 | unsigned char * t = (unsigned char *) &n; \ 88 | (s)[0] = t[0]; \ 89 | (s)[1] = t[1];\ 90 | (s)[2] = t[2];\ 91 | (s)[3] = t[3];\ 92 | (s) += 4; \ 93 | } while (0) 94 | 95 | #define putFloat64be(s,n) do { \ 96 | unsigned char * t = (unsigned char *) &n; \ 97 | (s)[0] = t[0]; \ 98 | (s)[1] = t[1]; \ 99 | (s)[2] = t[2]; \ 100 | (s)[3] = t[3]; \ 101 | (s)[4] = t[4]; \ 102 | (s)[5] = t[5]; \ 103 | (s)[6] = t[6]; \ 104 | (s)[7] = t[7]; \ 105 | (s) += 8; \ 106 | } while (0) 107 | 108 | #else 109 | 110 | #define putFloat32be(s,n) do { \ 111 | unsigned char * t = (unsigned char *) &n; \ 112 | (s)[3] = t[0];\ 113 | (s)[2] = t[1];\ 114 | (s)[1] = t[2];\ 115 | (s)[0] = t[3];\ 116 | (s) += 4; \ 117 | } while (0) 118 | 119 | #define putFloat64be(s,n) do { \ 120 | unsigned char * t = (unsigned char *) &n; \ 121 | (s)[7] = t[0]; \ 122 | (s)[6] = t[1]; \ 123 | (s)[5] = t[2]; \ 124 | (s)[4] = t[3]; \ 125 | (s)[3] = t[4]; \ 126 | (s)[2] = t[5]; \ 127 | (s)[1] = t[6]; \ 128 | (s)[0] = t[7]; \ 129 | (s) += 8; \ 130 | } while (0) 131 | 132 | #endif 133 | 134 | #endif 135 | 136 | #ifdef __cplusplus 137 | } 138 | #endif 139 | -------------------------------------------------------------------------------- /woggle/tools/ld.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # set -x 3 | # Save the command line for debug outputs 4 | SAVE="$@" 5 | kernel_libs="kernel32.lib advapi32.lib" 6 | gdi_libs="gdi32.lib user32.lib comctl32.lib comdlg32.lib shell32.lib" 7 | DEFAULT_LIBRARIES="$kernel_libs $gdi_libs" 8 | 9 | CMD="" 10 | STDLIB=MSVCRT.LIB 11 | DEBUG_BUILD=false 12 | STDLIB_FORCED=false 13 | BUILD_DLL=false 14 | OUTPUT_FILENAME="" 15 | 16 | while test -n "$1" ; do 17 | x="$1" 18 | case "$x" in 19 | -dll| -DLL) 20 | BUILD_DLL=true;; 21 | -L/*) 22 | y=`echo $x | sed 's,^-L\(/.*\),\1,g'`; 23 | MPATH=`cygpath -m $y`; 24 | CMD="$CMD -libpath:\"$MPATH\"";; 25 | -L*) 26 | y=`echo $x | sed 's,^-L\(.*\),\1,g'`; 27 | CMD="$CMD -libpath:\"$y\"";; 28 | -lMSVCRT|-lmsvcrt) 29 | STDLIB_FORCED=true; 30 | STDLIB=MSVCRT.LIB;; 31 | -lMSVCRTD|-lmsvcrtd) 32 | STDLIB_FORCED=true; 33 | STDLIB=MSVCRTD.LIB;; 34 | -lLIBCMT|-llibcmt) 35 | STDLIB_FORCED=true; 36 | STDLIB=LIBCMT.LIB;; 37 | -lLIBCMTD|-llibcmtd) 38 | STDLIB_FORCED=true; 39 | STDLIB=LIBCMTD.LIB;; 40 | -lsocket) 41 | DEFAULT_LIBRARIES="$DEFAULT_LIBRARIES WS2_32.LIB";; 42 | -l*) 43 | y=`echo $x | sed 's,^-l\(.*\),\1,g'`; 44 | MPATH=`cygpath -m $y`; 45 | CMD="$CMD \"${MPATH}.lib\"";; 46 | -g) 47 | DEBUG_BUILD=true;; 48 | -pdb:none|-incremental:no) 49 | ;; 50 | -funroll-loops|-ffast-math|-fomit-frame-pointer) 51 | ;; 52 | -implib:*) 53 | y=`echo $x | sed 's,^-implib:\(.*\),\1,g'`; 54 | MPATH=`cygpath -m $y`; 55 | CMD="$CMD -implib:\"${MPATH}\"";; 56 | -def:*) 57 | y=`echo $x | sed 's,^-def:\(.*\),\1,g'`; 58 | MPATH=`cygpath -m $y`; 59 | CMD="$CMD -def:\"${MPATH}\"";; 60 | -o) 61 | shift 62 | MPATH=`cygpath -m $1`; 63 | OUTPUT_FILENAME="$MPATH";; 64 | -o/*) 65 | y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`; 66 | MPATH=`cygpath -m $y`; 67 | OUTPUT_FILENAME="$MPATH";; 68 | /*) 69 | MPATH=`cygpath -m $x`; 70 | CMD="$CMD \"$MPATH\"";; 71 | *) 72 | y=`echo $x | sed 's,",\\\",g'`; 73 | CMD="$CMD \"$y\"";; 74 | esac 75 | shift 76 | done 77 | if [ $DEBUG_BUILD = true ]; then 78 | linktype="-debug -pdb:none" 79 | if [ $STDLIB_FORCED = false ]; then 80 | STDLIB=MSVCRTD.LIB 81 | fi 82 | else 83 | linktype=-release 84 | fi 85 | 86 | if [ $BUILD_DLL = true ];then 87 | case "$OUTPUT_FILENAME" in 88 | *.exe|*.EXE) 89 | echo "Warning, output set to .exe when building DLL" >&2 90 | CMD="-dll -out:\"$OUTPUT_FILENAME\" $CMD";; 91 | *.dll|*.DLL) 92 | CMD="-dll -out:\"$OUTPUT_FILENAME\" $CMD";; 93 | "") 94 | CMD="-dll -out:\"a.dll\" $CMD";; 95 | *) 96 | CMD="-dll -out:\"${OUTPUT_FILENAME}.dll\" $CMD";; 97 | esac 98 | else 99 | case "$OUTPUT_FILENAME" in 100 | *.exe|*.EXE) 101 | CMD="-out:\"$OUTPUT_FILENAME\" $CMD";; 102 | *.dll|*.DLL) 103 | echo "Warning, output set to .dll when building EXE" >&2 104 | CMD="-out:\"$OUTPUT_FILENAME\" $CMD";; 105 | "") 106 | CMD="-out:\"a.exe\" $CMD";; 107 | *) 108 | CMD="-out:\"${OUTPUT_FILENAME}.exe\" $CMD";; 109 | esac 110 | fi 111 | 112 | p=$$ 113 | CMD="$linktype -nologo -incremental:no $CMD $STDLIB $DEFAULT_LIBRARIES" 114 | if [ "X$LD_SH_DEBUG_LOG" != "X" ]; then 115 | echo ld.sh "$SAVE" >>$LD_SH_DEBUG_LOG 116 | echo link.exe $CMD >>$LD_SH_DEBUG_LOG 117 | fi 118 | eval link.exe "$CMD" >/tmp/link.exe.${p}.1 2>/tmp/link.exe.${p}.2 119 | RES=$? 120 | tail +2 /tmp/link.exe.${p}.2 >&2 121 | cat /tmp/link.exe.${p}.1 122 | rm -f /tmp/link.exe.${p}.2 /tmp/link.exe.${p}.1 123 | exit $RES 124 | -------------------------------------------------------------------------------- /c_src/esdl_img.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Klas Johanssson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | /* 9 | Map erl esdl_img calls to C SDL_image calls 10 | */ 11 | 12 | #include "esdl.h" 13 | #include 14 | #include 15 | #include 16 | 17 | void es_img_linkedVersion(sdl_data *sd, int len, char *buff) 18 | { 19 | char *bp, *start; 20 | int sendlen; 21 | const SDL_version *version; 22 | 23 | version = IMG_Linked_Version(); 24 | 25 | bp = start = sdl_get_temp_buff(sd, 3); 26 | put8(bp, version->major); 27 | put8(bp, version->minor); 28 | put8(bp, version->patch); 29 | sendlen = bp - start; 30 | sdl_send(sd, sendlen); 31 | } 32 | 33 | void es_img_loadTypedRW(sdl_data *sd, int len, char *buff) 34 | { 35 | } 36 | 37 | void es_img_load(sdl_data *sd, int len, char *buff) 38 | { 39 | char *file, *bp, *start; 40 | int sendlen; 41 | SDL_Surface *surface; 42 | 43 | file = buff; 44 | surface = IMG_Load(file); 45 | bp = start = sdl_get_temp_buff(sd, 8); 46 | PUSHGLPTR(surface, bp); 47 | sendlen = bp - start; 48 | sdl_send(sd, sendlen); 49 | } 50 | 51 | void es_img_loadRW(sdl_data *sd, int len, char *buff) 52 | { 53 | } 54 | 55 | void es_img_invertAlpha(sdl_data *sd, int len, char *buff) 56 | { 57 | } 58 | 59 | void es_img_isBMP(sdl_data *sd, int len, char *buff) 60 | { 61 | } 62 | 63 | void es_img_isPNM(sdl_data *sd, int len, char *buff) 64 | { 65 | } 66 | 67 | void es_img_isXPM(sdl_data *sd, int len, char *buff) 68 | { 69 | } 70 | 71 | void es_img_isXCF(sdl_data *sd, int len, char *buff) 72 | { 73 | } 74 | 75 | void es_img_isPCX(sdl_data *sd, int len, char *buff) 76 | { 77 | } 78 | 79 | void es_img_isGIF(sdl_data *sd, int len, char *buff) 80 | { 81 | } 82 | 83 | void es_img_isJPG(sdl_data *sd, int len, char *buff) 84 | { 85 | } 86 | 87 | void es_img_isTIF(sdl_data *sd, int len, char *buff) 88 | { 89 | } 90 | 91 | void es_img_isPNG(sdl_data *sd, int len, char *buff) 92 | { 93 | } 94 | 95 | void es_img_isLBM(sdl_data *sd, int len, char *buff) 96 | { 97 | } 98 | 99 | void es_img_loadBMPRW(sdl_data *sd, int len, char *buff) 100 | { 101 | } 102 | 103 | void es_img_loadPNMRW(sdl_data *sd, int len, char *buff) 104 | { 105 | } 106 | 107 | void es_img_loadXPMRW(sdl_data *sd, int len, char *buff) 108 | { 109 | } 110 | 111 | void es_img_loadXCFRW(sdl_data *sd, int len, char *buff) 112 | { 113 | } 114 | 115 | void es_img_loadPCXRW(sdl_data *sd, int len, char *buff) 116 | { 117 | } 118 | 119 | void es_img_loadGIFRW(sdl_data *sd, int len, char *buff) 120 | { 121 | } 122 | 123 | void es_img_loadJPGRW(sdl_data *sd, int len, char *buff) 124 | { 125 | } 126 | 127 | void es_img_loadTIFRW(sdl_data *sd, int len, char *buff) 128 | { 129 | } 130 | 131 | void es_img_loadPNGRW(sdl_data *sd, int len, char *buff) 132 | { 133 | } 134 | 135 | void es_img_loadTGARW(sdl_data *sd, int len, char *buff) 136 | { 137 | } 138 | 139 | void es_img_loadLBMRW(sdl_data *sd, int len, char *buff) 140 | { 141 | } 142 | 143 | void es_img_readXPMFromArray(sdl_data *sd, int len, char *buff) 144 | { 145 | } 146 | 147 | void es_img_setError(sdl_data *sd, int len, char *buff) 148 | { 149 | // not implemented 150 | } 151 | 152 | void es_img_getError(sdl_data *sd, int len, char *buff) 153 | { 154 | char *err, *bp, *start; 155 | int length; 156 | err = IMG_GetError(); 157 | length = strlen(err); 158 | bp = start = sdl_getbuff(sd, length); 159 | while(*err != '\0') { 160 | put8(bp, *err++); 161 | } 162 | sdl_send(sd, bp - start); 163 | } 164 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_wrapper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | /* 9 | Command Handler 10 | Dispatch the work on the functions 11 | */ 12 | 13 | #ifdef WIN32 14 | #include 15 | #endif 16 | #include 17 | 18 | #include "woggle_driver.h" 19 | #include "woggle_compat_if.h" 20 | #include "woggle_if.h" 21 | #include 22 | #include 23 | #include 24 | #ifndef APIENTRY 25 | # define APIENTRY 26 | #endif 27 | #define ESDL_DEFINE_EXTS 28 | #include 29 | 30 | typedef struct sdl_code_fn_def { 31 | int op; 32 | char *str; 33 | sdl_fun fn; 34 | } sdl_code_fn; 35 | 36 | static sdl_code_fn code_fns[] = { 37 | 38 | #include "woggle_compat_if_fp.h" 39 | 40 | #include "woggle_if_fp.h" 41 | 42 | #include 43 | 44 | #include 45 | 46 | { 0, "LastFunction", NULL}}; 47 | 48 | static struct { 49 | int op; 50 | char* name; 51 | sdl_fun fun; 52 | void* ext_fun; 53 | } ext_fns[] = { 54 | 55 | #include 56 | 57 | { 0, "LastFunction", NULL, NULL}}; 58 | 59 | static void 60 | undefined_function(sdl_data *sd, int len, char *buff) 61 | { 62 | sd->len = -2; 63 | } 64 | 65 | static void 66 | undefined_extension(sdl_data *sd, int len, char *buff) 67 | { 68 | sd->len = -3; 69 | } 70 | 71 | void init_fps(sdl_data* sd) 72 | { 73 | int i; 74 | int n = MAX_FUNCTIONS_H; /* Must be greater than then the last function op */ 75 | int op; 76 | sdl_fun* fun_tab; 77 | char** str_tab; 78 | 79 | fun_tab = sd->fun_tab = malloc((n+1) * sizeof(sdl_fun)); 80 | str_tab = sd->str_tab = malloc((n+1) * sizeof(char*)); 81 | 82 | for (i = 0; i < OPENGL_EXTS_H; i++) { 83 | fun_tab[i] = undefined_function; 84 | str_tab[i] = "unknown function"; 85 | } 86 | 87 | for ( ; i < n; i++) { 88 | fun_tab[i] = undefined_extension; 89 | str_tab[i] = "unknown extension"; 90 | } 91 | 92 | for (i = 0; ((op = code_fns[i].op) != 0); i++) { 93 | if (fun_tab[op] == undefined_function) { 94 | fun_tab[op] = code_fns[i].fn; 95 | str_tab[op] = code_fns[i].str; 96 | /*{char buff[1024]; 97 | sprintf(buff,"%s:%d",str_tab[op],op); 98 | MessageBox(NULL,buff,"debug",MB_OK);}*/ 99 | } else { 100 | fprintf(stderr, 101 | "FParray mismatch in initialization: %d '%s' %d '%s'\r\n", 102 | i, str_tab[op], op, code_fns[i].str); 103 | } 104 | } 105 | } 106 | 107 | /* Must be done after creating a rendering context */ 108 | void init_glexts(sdl_data* sd) 109 | { 110 | static int already_done = 0; 111 | 112 | if (already_done == 0) { 113 | int i; 114 | int op; 115 | sdl_fun* fun_tab = sd->fun_tab; 116 | char** str_tab = sd->str_tab; 117 | 118 | already_done = 1; 119 | for (i = 0; (op = ext_fns[i].op) != 0; i++) { 120 | if (fun_tab[op] == undefined_extension) { 121 | #ifdef WIN32 122 | void* ext_ptr = (void *) wglGetProcAddress(ext_fns[i].name); 123 | #else 124 | /* FIXME? */ 125 | void* ext_ptr = NULL; 126 | #endif 127 | str_tab[op] = ext_fns[i].name; 128 | if (ext_ptr) { 129 | /* fprintf(stderr, "Success %s \r\n", code_fns[i].str);*/ 130 | * (void **) (ext_fns[i].ext_fun) = ext_ptr; 131 | fun_tab[op] = ext_fns[i].fun; 132 | } else { 133 | /* fprintf(stderr, "Failed %s \r\n", code_fns[i].str); */ 134 | fun_tab[op] = undefined_extension; 135 | } 136 | } else { 137 | fprintf(stderr, "Exiting FP EXTENSION array mismatch in initialization %d %d %s\r\n", 138 | i, ext_fns[i].op, ext_fns[i].name); 139 | } 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /c_src/esdl_img.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Klas Johansson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * 7 | * $Id$ 8 | */ 9 | /* Defines the image functions */ 10 | 11 | #ifdef _USE_SDL_IMAGE 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define SDL_IMG_LinkedVersionFunc IMG_H +1 18 | void es_img_linkedVersion(sdl_data *, int, char *); 19 | #define SDL_IMG_LoadTypedRWFunc SDL_IMG_LinkedVersionFunc +1 20 | void es_img_loadTypedRW(sdl_data *, int, char *); 21 | #define SDL_IMG_LoadFunc SDL_IMG_LoadTypedRWFunc +1 22 | void es_img_load(sdl_data *, int, char *); 23 | #define SDL_IMG_LoadRWFunc SDL_IMG_LoadFunc +1 24 | void es_img_loadRW(sdl_data *, int, char *); 25 | #define SDL_IMG_InvertAlphaFunc SDL_IMG_LoadRWFunc +1 26 | void es_img_invertAlpha(sdl_data *, int, char *); 27 | #define SDL_IMG_isBMPFunc SDL_IMG_InvertAlphaFunc +1 28 | void es_img_isBMP(sdl_data *, int, char *); 29 | #define SDL_IMG_isPNMFunc SDL_IMG_isBMPFunc +1 30 | void es_img_isPNM(sdl_data *, int, char *); 31 | #define SDL_IMG_isXPMFunc SDL_IMG_isPNMFunc +1 32 | void es_img_isXPM(sdl_data *, int, char *); 33 | #define SDL_IMG_isXCFFunc SDL_IMG_isXPMFunc +1 34 | void es_img_isXCF(sdl_data *, int, char *); 35 | #define SDL_IMG_isPCXFunc SDL_IMG_isXCFFunc +1 36 | void es_img_isPCX(sdl_data *, int, char *); 37 | #define SDL_IMG_isGIFFunc SDL_IMG_isPCXFunc +1 38 | void es_img_isGIF(sdl_data *, int, char *); 39 | #define SDL_IMG_isJPGFunc SDL_IMG_isGIFFunc +1 40 | void es_img_isJPG(sdl_data *, int, char *); 41 | #define SDL_IMG_isTIFFunc SDL_IMG_isJPGFunc +1 42 | void es_img_isTIF(sdl_data *, int, char *); 43 | #define SDL_IMG_isPNGFunc SDL_IMG_isTIFFunc +1 44 | void es_img_isPNG(sdl_data *, int, char *); 45 | #define SDL_IMG_isLBMFunc SDL_IMG_isPNGFunc +1 46 | void es_img_isLBM(sdl_data *, int, char *); 47 | #define SDL_IMG_LoadBMPRWFunc SDL_IMG_isLBMFunc +1 48 | void es_img_loadBMPRW(sdl_data *, int, char *); 49 | #define SDL_IMG_LoadPNMRWFunc SDL_IMG_LoadBMPRWFunc +1 50 | void es_img_loadPNMRW(sdl_data *, int, char *); 51 | #define SDL_IMG_LoadXPMRWFunc SDL_IMG_LoadPNMRWFunc +1 52 | void es_img_loadXPMRW(sdl_data *, int, char *); 53 | #define SDL_IMG_LoadXCFRWFunc SDL_IMG_LoadXPMRWFunc +1 54 | void es_img_loadXCFRW(sdl_data *, int, char *); 55 | #define SDL_IMG_LoadPCXRWFunc SDL_IMG_LoadXCFRWFunc +1 56 | void es_img_loadPCXRW(sdl_data *, int, char *); 57 | #define SDL_IMG_LoadGIFRWFunc SDL_IMG_LoadPCXRWFunc +1 58 | void es_img_loadGIFRW(sdl_data *, int, char *); 59 | #define SDL_IMG_LoadJPGRWFunc SDL_IMG_LoadGIFRWFunc +1 60 | void es_img_loadJPGRW(sdl_data *, int, char *); 61 | #define SDL_IMG_LoadTIFRWFunc SDL_IMG_LoadJPGRWFunc +1 62 | void es_img_loadTIFRW(sdl_data *, int, char *); 63 | #define SDL_IMG_LoadPNGRWFunc SDL_IMG_LoadTIFRWFunc +1 64 | void es_img_loadPNGRW(sdl_data *, int, char *); 65 | #define SDL_IMG_LoadTGARWFunc SDL_IMG_LoadPNGRWFunc +1 66 | void es_img_loadTGARW(sdl_data *, int, char *); 67 | #define SDL_IMG_LoadLBMRWFunc SDL_IMG_LoadTGARWFunc +1 68 | void es_img_loadLBMRW(sdl_data *, int, char *); 69 | #define SDL_IMG_ReadXPMFromArrayFunc SDL_IMG_LoadLBMRWFunc +1 70 | void es_img_readXPMFromArray(sdl_data *, int, char *); 71 | #define SDL_IMG_SetErrorFunc SDL_IMG_ReadXPMFromArrayFunc +1 72 | void es_img_setError(sdl_data *, int, char *); 73 | #define SDL_IMG_GetErrorFunc SDL_IMG_SetErrorFunc +1 74 | void es_img_getError(sdl_data *, int, char *); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* _USE_SDL_IMAGE */ 81 | -------------------------------------------------------------------------------- /src/sdl_video_funcs.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_video_funcs.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : 12 | %%% Created : 30 Aug 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | %%% Functions 16 | -include("esdl.hrl"). 17 | 18 | -define(SDL_VideoDriverName, ?SDL_VIDEO_HRL + 1). 19 | -define(SDL_GetVideoSurface, ?SDL_VideoDriverName + 1). 20 | -define(SDL_GetVideoInfo, ?SDL_GetVideoSurface + 1). 21 | -define(SDL_VideoModeOK, ?SDL_GetVideoInfo + 1). 22 | -define(SDL_ListModes, ?SDL_VideoModeOK + 1). 23 | -define(SDL_SetVideoMode, ?SDL_ListModes + 1). 24 | -define(SDL_UpdateRect, ?SDL_SetVideoMode + 1). 25 | -define(SDL_UpdateRects, ?SDL_UpdateRect + 1). 26 | -define(SDL_Flip, ?SDL_UpdateRects + 1). 27 | -define(SDL_SetColors, ?SDL_Flip + 1). 28 | -define(SDL_MapRGB, ?SDL_SetColors + 1). 29 | -define(SDL_GetRGB, ?SDL_MapRGB + 1). 30 | -define(SDL_CreateRGBSurface,?SDL_GetRGB + 1). 31 | -define(SDL_CreateRGBSurfaceFrom, ?SDL_CreateRGBSurface + 1). 32 | -define(SDL_FreeSurface, ?SDL_CreateRGBSurfaceFrom + 1). 33 | 34 | -define(SDL_MUSTLOCK, 0). %% Needed ? Implemented as an erlang func!! 35 | -define(SDL_LockSurface, ?SDL_FreeSurface + 1 ). 36 | -define(SDL_UnlockSurface, ?SDL_LockSurface + 1). 37 | 38 | -define(SDL_LoadBMP_RW, ?SDL_UnlockSurface + 1). 39 | -define(SDL_LoadBMP, ?SDL_LoadBMP_RW + 1). 40 | 41 | -define(SDL_SaveBMP_RW, ?SDL_LoadBMP + 1). 42 | -define(SDL_SaveBMP, ?SDL_SaveBMP_RW + 1). 43 | 44 | -define(SDL_SetColorKey, ?SDL_SaveBMP + 1). 45 | -define(SDL_SetAlpha, ?SDL_SetColorKey + 1). 46 | -define(SDL_SetClipping, ?SDL_SetAlpha + 1). 47 | 48 | -define(SDL_ConvertSurface, ?SDL_SetClipping + 1 ). % SDL_internal 49 | -define(SDL_BlitSurface, ?SDL_ConvertSurface + 1). 50 | -define(SDL_UpperBlit, ?SDL_BlitSurface + 1). 51 | -define(SDL_LowerBlit, ?SDL_UpperBlit + 1 ).% SDL_semi private 52 | -define(SDL_FillRect, ?SDL_LowerBlit + 1). 53 | 54 | -define(SDL_DisplayFormat, ?SDL_FillRect + 1). 55 | 56 | %% video overlays ... not supported rigth now 57 | 58 | %% Windowing stuff 59 | -define(SDL_WM_SetCaption, ?SDL_DisplayFormat +1). 60 | -define(SDL_WM_GetCaption, ?SDL_WM_SetCaption +1). 61 | -define(SDL_WM_SetIcon, ?SDL_WM_GetCaption +1). 62 | -define(SDL_WM_IconifyWindow,?SDL_WM_SetIcon +1). 63 | -define(SDL_WM_ToggleFullScreen, ?SDL_WM_IconifyWindow +1). 64 | 65 | -define(SDL_WM_GrabInput, ?SDL_WM_ToggleFullScreen+1). 66 | -define(SDL_WM_GetInfo, ?SDL_WM_GrabInput+1). 67 | 68 | -define(SDL_GL_SetAttribute, ?SDL_WM_GetInfo+1). 69 | -define(SDL_GL_GetAttribute, ?SDL_GL_SetAttribute +1). 70 | -define(SDL_GL_SwapBuffers, ?SDL_GL_GetAttribute +1). 71 | 72 | %% Erl sdl special functions 73 | -define(ESDL_getSurface, ?SDL_GL_SwapBuffers + 1). 74 | -define(ESDL_getPalette, ?ESDL_getSurface + 1). 75 | -define(ESDL_getPixelFormat, ?ESDL_getPalette +1). 76 | -define(ESDL_getPixels, ?ESDL_getPixelFormat +1). 77 | -define(SDL_WM_IsMaximized, ?ESDL_getPixels +1). 78 | 79 | %% Sdl additions 80 | -define(SDL_SetGamma, ?SDL_WM_IsMaximized +1). 81 | -define(SDL_SetGammaRamp, ?SDL_SetGamma +1). 82 | -define(SDL_GetGammaRamp, ?SDL_SetGammaRamp +1). 83 | 84 | -define(SDL_MapRGBA, ?SDL_GetGammaRamp + 1). 85 | -define(SDL_GetRGBA, ?SDL_MapRGBA + 1). 86 | -define(SDL_GetClipRect, ?SDL_GetRGBA + 1). 87 | -define(SDL_SetClipRect, ?SDL_GetClipRect + 1). 88 | -define(SDL_DisplayFormatAlpha, ?SDL_SetClipRect + 1). 89 | -define(SDL_WM_Maximize, ?SDL_DisplayFormatAlpha +1). 90 | -define(SDL_WM_MacFileDialog, ?SDL_WM_Maximize +1). 91 | -------------------------------------------------------------------------------- /src/sdl_mouse.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_mouse.erl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : Mouse related functions 12 | %%% Created : 12 Jul 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -module(sdl_mouse). 16 | 17 | -include("esdl.hrl"). 18 | -include("sdl_mouse.hrl"). 19 | -include("sdl_util.hrl"). 20 | 21 | -export([createCursor/6, 22 | freeCursor/1, 23 | getCursor/0, 24 | getMouseState/0, 25 | getRelativeMouseState/0, 26 | setCursor/1, 27 | showCursor/1, 28 | warpMouse/2 29 | ]). 30 | 31 | -import(sdl, [call/2,cast/2]). 32 | 33 | -define(SDL_GetMouseState, ?SDL_MOUSE_HRL+1). 34 | -define(SDL_GetRelativeMouseState, ?SDL_GetMouseState+1). 35 | -define(SDL_WarpMouse, ?SDL_GetRelativeMouseState +1). 36 | -define(SDL_CreateCursor, ?SDL_WarpMouse +1). 37 | -define(SDL_SetCursor, ?SDL_CreateCursor+1). 38 | -define(SDL_GetCursor, ?SDL_SetCursor+1). 39 | -define(SDL_FreeCursor, ?SDL_GetCursor+1). 40 | -define(SDL_ShowCursor, ?SDL_FreeCursor+1). 41 | 42 | %%%%%%%%%%%%%%%%%%%%% MOUSE FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%% 43 | %% Func: getMouseState 44 | %% Args: none 45 | %% Returns: {MouseState, X, Y} 46 | %% C-API func: Uint8 SDL_GetMouseState(int *x, int *y); 47 | %% Desc: 48 | getMouseState() -> 49 | <> = call(?SDL_GetMouseState, []), 50 | {State,X,Y}. 51 | 52 | %% Func: getRelativeMouseState 53 | %% Args: none 54 | %% Returns: {MouseState, X, Y} 55 | %% C-API func: Uint8 SDL_GetRelativeMouseState(int *x, int *y); 56 | %% Desc: 57 | getRelativeMouseState() -> 58 | <> = call(?SDL_GetRelativeMouseState, []), 59 | {State,X,Y}. 60 | 61 | %% Func: warpMouse 62 | %% Args: X, Y 63 | %% Returns: ok 64 | %% C-API func: void SDL_WarpMouse(Uint16 x, Uint16 y); 65 | %% Desc: 66 | warpMouse(X, Y) -> 67 | cast(?SDL_WarpMouse, <>). 68 | 69 | %% Func: createCursor 70 | %% Args: Data (Binary), Mask(Binary), W, H, HotX, HotY 71 | %% Returns: CursorRef 72 | %% C-API func: SDL_Cursor *SDL_CreateCursor 73 | %% (Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); 74 | %% Desc: Data & Mask must be less than 32*32 bytes. 75 | createCursor(Data, Mask, W, H, HotX, HotY) when is_binary(Data), is_binary(Mask) -> 76 | case call(?SDL_CreateCursor, 77 | <>) of 79 | <<0:64>> -> 80 | exit({createCursor, returned_null}); 81 | <> -> 82 | {cursorp,Ptr} 83 | end. 84 | 85 | %% Func: setCursor 86 | %% Args: CursorRef 87 | %% Returns: ok 88 | %% C-API func: void SDL_SetCursor(SDL_Cursor *cursor); 89 | setCursor({cursorp,Ref}) -> 90 | cast(?SDL_SetCursor, <>). 91 | 92 | %% Func: getCursor 93 | %% Args: none 94 | %% Returns: A cursorRef 95 | %% C-API func: void SDL_SetCursor(SDL_Cursor *cursor); 96 | getCursor() -> 97 | case call(?SDL_GetCursor, []) of 98 | <<0:64>> -> 99 | exit({getCursor, returned_null}); 100 | <> -> 101 | {cursorp, Ptr} 102 | end. 103 | 104 | %% Func: freeCursor 105 | %% Args: CursorRef 106 | %% Returns: ok 107 | %% C-API func: void SDL_FreeCursor(SDL_Cursor *cursor); 108 | freeCursor({cursorp,Ref}) -> 109 | cast(?SDL_FreeCursor, <>). 110 | 111 | %% Func: showCursor 112 | %% Args: true | false 113 | %% Returns: true | false (if cursor was displayed before the call) 114 | %% C-API func: int SDL_ShowCursor(int toggle); 115 | showCursor(Bool) -> 116 | B = case Bool of 117 | false -> 0; 118 | true -> 1 119 | end, 120 | call(?SDL_ShowCursor, [B]), 121 | receive 122 | {'_esdl_result_', Res} -> 123 | Res =:= 1 124 | end. 125 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | #ifndef _WOGGLE_DRIVER_H 9 | #define _WOGGLE_DRIVER_H 10 | #include 11 | 12 | #ifndef FLAVOUR_WOGGLE 13 | #define FLAVOUR_WOGGLE 1 14 | #endif 15 | #define SDL_BIGENDIAN 0 16 | #define SDL_LITTLEENDIAN 1 17 | #define SDL_BYTEORDER SDL_LITTLEENDIAN 18 | 19 | #define WOGGLE_VERSION_MAJOR 0 20 | #define WOGGLE_VERSION_MINOR 1 21 | #define WOGGLE_VERSION_PATCH 0 22 | 23 | typedef unsigned char Uint8; 24 | typedef unsigned int Uint32; 25 | 26 | #ifdef WIN32 27 | #include 28 | #include 29 | #include "woggle_win.h" 30 | #endif 31 | 32 | /* 33 | * It seems I need to steal more and more from esdl.h... 34 | */ 35 | 36 | /* Some new GL types (eleminates the need for glext.h) */ 37 | #ifndef GL_VERSION_1_5 38 | #include 39 | /* GL types for handling large vertex buffer objects */ 40 | typedef ptrdiff_t GLintptr; 41 | typedef ptrdiff_t GLsizeiptr; 42 | #endif 43 | #ifndef GL_ARB_shader_objects 44 | /* GL types for handling shader object handles and characters */ 45 | typedef char GLcharARB; /* native character */ 46 | typedef unsigned int GLhandleARB; /* shader object handle */ 47 | #endif 48 | 49 | #include 50 | 51 | #define MAXBUFF 8000000 /* Covers 1600x1200x4 (32bits) */ 52 | 53 | #define error() {fprintf(stderr, "Error in %s:%d \n\r", \ 54 | __FILE__, __LINE__); \ 55 | return;} 56 | 57 | typedef struct sdl_data_def *sdl_data_ptr; 58 | typedef void (*sdl_fun)(sdl_data_ptr, int, char*); 59 | 60 | typedef sdl_fun (*sdl_load_fun)(void); 61 | 62 | typedef struct { 63 | char* base; 64 | size_t size; 65 | ErlDrvBinary* bin; 66 | } EsdlBinRef; 67 | 68 | typedef struct sdl_data_def { 69 | void* driver_data; /* Port or Driver specific data */ 70 | sdl_fun* fun_tab; /* Pointers to functions */ 71 | char** str_tab; /* Pointers to function names */ 72 | int extensions_loaded; 73 | 74 | HANDLE qh; 75 | 76 | WogWindowData wd; 77 | WogEventMessage *saved_event; /* Used by compatibility interface */ 78 | int save_x,save_y; /* Used by compat IF */ 79 | int op; /* Current (or last) function */ 80 | int len; /* Length of message buffer */ 81 | void* buff; /* Pointer to message buffer */ 82 | 83 | void* temp_bin; /* Temporary binary */ 84 | EsdlBinRef bin[3]; /* Argument binaries */ 85 | int next_bin; /* Next binary */ 86 | } sdl_data; 87 | 88 | void sdl_send(sdl_data *, int); 89 | char* sdl_getbuff(sdl_data*, int); 90 | char* sdl_get_temp_buff(sdl_data*, int); 91 | void sdl_free_binaries(sdl_data*); 92 | 93 | void init_fps(sdl_data*); 94 | void init_glexts(sdl_data*); 95 | 96 | /* These must exactly match those in src/esdl.hrl */ 97 | #if 0 98 | #define SDL_H 20 99 | #endif 100 | #define VIDEO_H 30 101 | #define EVENTS_H 100 102 | 103 | /* This is how they are in SDL */ 104 | #if 0 105 | #define MOUSE_H 110 106 | #define KEYBOARD_H 120 107 | #define ACTIVE_H 130 108 | #define JOYSTICK_H 133 109 | #define AUDIO_H 150 110 | #endif 111 | 112 | /* Using same as JOYSTICK_H, will never implement Joy and audio */ 113 | #define WOGGLE_IF_H 133 114 | 115 | #define SDL_UTIL_H 180 116 | #define OPENGL_H 200 117 | #define OPENGLU_H 600 118 | #define OPENGL_EXTS_H 700 /* Must be last */ 119 | #define MAX_FUNCTIONS_H 1023 /* Current Max.. Increase if needed */ 120 | 121 | #define SDL_InitFunc (SDL_H + 1) 122 | #define SDL_QuitFunc (SDL_InitFunc + 1) 123 | #define SDL_GetErrorFunc (SDL_QuitFunc + 1) 124 | 125 | #if 0 126 | #include "esdl_video.h" 127 | #include "esdl_events.h" 128 | #include "esdl_audio.h" 129 | #endif 130 | #include 131 | 132 | void es_init(sdl_data *sd, int len, char * buff); 133 | void es_quit(sdl_data *sd, int len, char * buff); 134 | void es_getError(sdl_data *sd, int len, char *buff); 135 | 136 | #endif 137 | 138 | -------------------------------------------------------------------------------- /Readme: -------------------------------------------------------------------------------- 1 | ESDL by Dan Gudmundsson 2 | Currently located at http://esdl.sourceforge.net 3 | 4 | What is it? 5 | =========== 6 | Esdl is library for accessing SDL (Simple DirectMedia Layer) 7 | and OpenGL through Erlang. 8 | 9 | Simple DirectMedia Layer is a cross-platform multimedia library 10 | designed to provide fast access to the graphics framebuffer and audio 11 | device. It also do event handling from mouse, keyboards and joysticks. 12 | It is also possible to use TrueType fonts through SDL_ttf 13 | (www.libsdl.org/projects/SDL_ttf/) and images through SDL_image 14 | (www.libsdl.org/projects/SDL_image/). More information can be 15 | found at libsdl.org 16 | 17 | OpenGL is a cross-platform standard for 3D rendering and 18 | 3D hardware acceleration. More information can be found at 19 | www.opengl.org 20 | 21 | News 22 | ========= 23 | 1.3.1: 24 | Throw away Makefiles and use rebar for building 25 | 26 | 1.3: 27 | Builds with otp-r15b 28 | 29 | 1.2: 30 | I have removed the opengl specific part from esdl, now esdl 31 | requires that wx is available for opengl usage. 32 | 33 | This means that this release is not backwards compatible 34 | with the old release, some gl functions have been changed in wx gl. 35 | 36 | This is done to only have one gl.erl in your (erlang) system, 37 | and it also more up to date with the standard. 38 | Actually only wx/ebin/gl.beam wx/ebin/glu.beam and wx/priv/OS/erl_gl.[so|dll] 39 | is required. 40 | 41 | Also using wx's opengl allowed me to create an opengl thread, 42 | if the erlang emulator is multithreaded. So now sdl with opengl 43 | works for both smp and single threaded erlang. 44 | 45 | 46 | Compilation and Installation 47 | ============================= 48 | 49 | You need erlang (www.erlang.org). This release has only been 50 | tested on R16B, it requires R14B version for opengl to work. 51 | 52 | You need libsdl (www.libsdl.org) (the development package) version > 1.2.5 53 | For windows grab SDL-devel-1.2.15-VC.zip 54 | (which work with both gcc and cl and contains both x86 and x64 libs) 55 | 56 | On Mac OS X, you also must install XQuartz from: 57 | 58 | http://xquartz.macosforge.org 59 | 60 | (Needed for the X11 header files.) 61 | 62 | And optionally you'll need: 63 | * SDL_ttf (www.libsdl.org/projects/SDL_ttf/) version > 2.0.7 64 | * SDL_image (www.libsdl.org/projects/SDL_image/) version > 1.2.4 65 | 66 | You need rebar, see: github.com/rebar/rebar 67 | 68 | Build with: 69 | rebar compile 70 | 71 | On windows: 72 | =========== 73 | SDL_DIR=/opt/local rebar compile (requires Microsoft's SDK) 74 | or 75 | CC=gcc SDL_DIR=/opt/local rebar compile (requires mingw) 76 | also copy SDL.dll to esdl/priv dir or put SDL.dll somewhere in your path. 77 | 78 | Note: for x64 and mingw-gcc you (currently) can not link against libraries build with 79 | MCL so you will need to recreate the dependency libs, 80 | see http://sourceforge.net/apps/trac/mingw-w64/wiki/Answer%2064%20bit%20MSVC-generated%20x64%20.lib 81 | 82 | ::This is currently not supported:: 83 | 84 | Optionally you'll also need SDL_ttf for the font support 85 | and SDL_image for the image support. 86 | 87 | Note: SDL_ttf and SDL_image are disabled by default, since they 88 | depend on libraries not in the plain vanilla SDL packages. 89 | By making them optional one can compile and run esdl without 90 | having to bother about getting hold of the SDL_ttf and 91 | SDL_image libraries. Enable them in the Makefile: 92 | 93 | ENABLE_SDL_TTF = yes 94 | ENABLE_SDL_IMAGE = yes 95 | 96 | 97 | Testing esdl can be done by building the tests in the test directory and 98 | running the test programs, example: 99 | cd test 100 | erl +S1 -pa ../ebin (werl on windows) 101 | Erlang (BEAM) emulator version 5.1.1 [threads:0] 102 | Eshell V5.1.1 (abort with ^G) 103 | 1> testsprite:go(). %% Escape quits 104 | 2> testgl:go(). 105 | 3> erldemo:go(). 106 | 4> testaudio:go(). 107 | 5> testjoy:go(). 108 | 6> test_ttf:go("/usr/share/fonts/truetype/freefont/FreeSerif.ttf", 20). 109 | 7> test_glfont:go("/usr/share/fonts/truetype/freefont/FreeSans.ttf"). 110 | 8> test_glimg:go(). 111 | 112 | 113 | Regards 114 | /Dan (d g u d @ users.sf.net) 115 | -------------------------------------------------------------------------------- /c_src/esdl_events.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * 7 | * $Id$ 8 | */ 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define SDL_PumpEventsFunc (EVENTS_H + 1) 14 | void es_pumpEvents(sdl_data *, int , char *); 15 | #define SDL_PeepEventsFunc SDL_PumpEventsFunc+1 16 | void es_peepEvents(sdl_data *, int , char *); 17 | void es_peepEvents2(ErlDrvPort port, ErlDrvTermData caller, char *bp); 18 | #define SDL_PollEventFunc SDL_PeepEventsFunc+1 19 | void es_pollEvent(sdl_data *, int , char *); 20 | void es_pollEvent2(ErlDrvPort port, ErlDrvTermData caller); 21 | #define SDL_WaitEventFunc SDL_PollEventFunc +1 22 | void es_waitEvent(sdl_data *, int , char *); 23 | void es_waitEvent2(ErlDrvPort port, ErlDrvTermData caller); 24 | #define SDL_EventStateFunc SDL_WaitEventFunc +1 25 | void es_eventState(sdl_data *, int , char *); 26 | 27 | #define SDL_GetMouseStateFunc MOUSE_H +1 28 | void es_getMouseState(sdl_data *, int , char *); 29 | #define SDL_GetRelativeMouseStateFunc SDL_GetMouseStateFunc+1 30 | void es_getRelativeMouseState(sdl_data *, int , char *); 31 | #define SDL_WarpMouseFunc SDL_GetRelativeMouseStateFunc +1 32 | void es_warpMouse(sdl_data *, int len, char *buff); 33 | #define SDL_CreateCursorFunc SDL_WarpMouseFunc +1 34 | void es_createCursor(sdl_data *, int len, char *buff); 35 | #define SDL_SetCursorFunc SDL_CreateCursorFunc+1 36 | void es_setCursor(sdl_data *, int len, char *buff); 37 | #define SDL_GetCursorFunc SDL_SetCursorFunc+1 38 | void es_getCursor(sdl_data *, int len, char *buff); 39 | #define SDL_FreeCursorFunc SDL_GetCursorFunc+1 40 | void es_freeCursor(sdl_data *, int len, char *buff); 41 | #define SDL_ShowCursorFunc SDL_FreeCursorFunc+1 42 | void es_showCursor(sdl_data *, int len, char *buff); 43 | void es_showCursor2(ErlDrvPort port, ErlDrvTermData caller, char *buff); 44 | 45 | #define SDL_GetWMInfoFunc SDL_ShowCursorFunc+1 46 | void es_getWMInfo(sdl_data *, int , char *); 47 | 48 | 49 | #define SDL_EnableUNICODEFunc KEYBOARD_H +1 50 | void es_enableUNICODE(sdl_data *, int , char *); 51 | #define SDL_EnableKeyRepeatFunc SDL_EnableUNICODEFunc+1 52 | void es_enableKeyRepeat(sdl_data *, int , char *); 53 | #define SDL_GetKeyNameFunc SDL_EnableKeyRepeatFunc+1 54 | void es_getKeyName(sdl_data *, int , char *); 55 | #define SDL_GetKeyStateFunc SDL_GetKeyNameFunc+1 56 | void es_getKeyState(sdl_data *, int , char *); 57 | #define SDL_GetModStateFunc SDL_GetKeyStateFunc+1 58 | void es_getModState(sdl_data *, int , char *); 59 | #define SDL_SetModStateFunc SDL_GetModStateFunc+1 60 | void es_setModState(sdl_data *, int , char *); 61 | 62 | #define SDL_GetAppStateFunc ACTIVE_H +1 63 | void es_getAppState(sdl_data *, int , char *); 64 | 65 | #define SDL_NumJoysticksFunc JOYSTICK_H +1 66 | void es_numJoysticks(sdl_data *, int , char *); 67 | #define SDL_JoystickNameFunc SDL_NumJoysticksFunc + 1 68 | void es_joystick_name(sdl_data *, int , char *); 69 | #define SDL_JoystickOpenFunc SDL_JoystickNameFunc + 1 70 | void es_joystick_open(sdl_data *, int , char *); 71 | #define SDL_JoystickOpenedFunc SDL_JoystickOpenFunc + 1 72 | void es_joystick_opened(sdl_data *, int , char *); 73 | #define SDL_JoystickIndexFunc SDL_JoystickOpenedFunc + 1 74 | void es_joystick_index(sdl_data *, int , char *); 75 | #define SDL_JoystickNumAxesFunc SDL_JoystickIndexFunc + 1 76 | void es_joystick_numAxes(sdl_data *, int , char *); 77 | #define SDL_JoystickNumBallsFunc SDL_JoystickNumAxesFunc + 1 78 | void es_joystick_numBalls(sdl_data *, int , char *); 79 | #define SDL_JoystickNumHatsFunc SDL_JoystickNumBallsFunc + 1 80 | void es_joystick_numHats(sdl_data *, int , char *); 81 | #define SDL_JoystickNumButtonsFunc SDL_JoystickNumHatsFunc + 1 82 | void es_joystick_numButtons(sdl_data *, int , char *); 83 | #define SDL_JoystickUpdateFunc SDL_JoystickNumButtonsFunc + 1 84 | void es_joystick_update(sdl_data *, int , char *); 85 | #define SDL_JoystickEventStateFunc SDL_JoystickUpdateFunc + 1 86 | void es_joystick_eventState(sdl_data *, int , char *); 87 | #define SDL_JoystickGetAxisFunc SDL_JoystickEventStateFunc + 1 88 | void es_joystick_getAxis(sdl_data *, int , char *); 89 | #define SDL_JoystickGetHatFunc SDL_JoystickGetAxisFunc + 1 90 | void es_joystick_getHat(sdl_data *, int , char *); 91 | #define SDL_JoystickGetButtonFunc SDL_JoystickGetHatFunc + 1 92 | void es_joystick_getButton(sdl_data *, int , char *); 93 | #define SDL_JoystickGetBallFunc SDL_JoystickGetButtonFunc + 1 94 | void es_joystick_getBall(sdl_data *, int , char *); 95 | #define SDL_JoystickCloseFunc SDL_JoystickGetBallFunc + 1 96 | void es_joystick_close(sdl_data *, int , char *); 97 | -------------------------------------------------------------------------------- /c_src/esdl_spec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * 7 | * $Id$ 8 | */ 9 | /* The special functions */ 10 | 11 | #include "esdl.h" 12 | 13 | void es_getSurface(sdl_data *sd, int len, char * buff) 14 | { 15 | char *bp, *start; 16 | int sendlen; 17 | SDL_Surface *screen; 18 | 19 | bp = buff; 20 | POPGLPTR(screen, bp); 21 | if(screen == NULL) { 22 | error(); 23 | } 24 | bp = start = sdl_getbuff(sd, 4*4+2+8*2); 25 | put32be(bp, screen->flags); 26 | PUSHGLPTR(screen->format, bp); 27 | put32be(bp, screen->w); 28 | put32be(bp, screen->h); 29 | put16be(bp, screen->pitch); 30 | PUSHGLPTR(screen->pixels, bp); 31 | put32be(bp, screen->offset); 32 | /* put32be(bp, screen->clip_minx); */ 33 | /* put32be(bp, screen->clip_maxx); */ 34 | /* put32be(bp, screen->clip_miny); */ 35 | /* put32be(bp, screen->clip_maxy); */ 36 | 37 | sendlen = (int) (bp - start); 38 | sdl_send(sd, sendlen); 39 | } 40 | 41 | void es_getPixelFormat(sdl_data *sd, int len, char * buff) 42 | { 43 | char *bp, *start; 44 | int sendlen; 45 | SDL_Surface * sptr; 46 | SDL_PixelFormat *format; 47 | 48 | bp = buff; 49 | 50 | POPGLPTR(sptr, bp); 51 | if(sptr == NULL) 52 | error(); 53 | format = sptr->format; 54 | if(format == NULL) 55 | error(); 56 | 57 | bp = start = sdl_get_temp_buff(sd, 8+5*4+11); 58 | PUSHGLPTR(format->palette, bp); 59 | put8(bp, format->BitsPerPixel); 60 | put8(bp, format->BytesPerPixel); 61 | put8(bp, format->Rloss); 62 | put8(bp, format->Gloss); 63 | put8(bp, format->Bloss); 64 | put8(bp, format->Aloss); 65 | put8(bp, format->Rshift); 66 | put8(bp, format->Gshift); 67 | put8(bp, format->Bshift); 68 | put8(bp, format->Ashift); 69 | put32be(bp, format->Rmask); 70 | put32be(bp, format->Gmask); 71 | put32be(bp, format->Bmask); 72 | put32be(bp, format->Amask); 73 | put32be(bp, format->colorkey); 74 | put8(bp, format->alpha); 75 | 76 | sendlen = (int) (bp - start); 77 | sdl_send(sd, sendlen); 78 | } 79 | 80 | void es_getPalette(sdl_data *sd, int len, char * buff) 81 | { 82 | char *bp, *start; 83 | int sendlen; 84 | SDL_Palette *palette; 85 | SDL_Surface *sptr; 86 | int i; 87 | 88 | bp = buff; 89 | POPGLPTR(sptr, bp); 90 | palette = sptr->format->palette; 91 | 92 | if(palette == NULL) { 93 | bp = start = sdl_getbuff(sd, 2); 94 | put16be(bp, 0); 95 | sendlen = (int) (bp - start); 96 | sdl_send(sd, sendlen); 97 | return; 98 | } 99 | 100 | bp = start = sdl_getbuff(sd, 2 + palette->ncolors * 3); 101 | put16be(bp, palette->ncolors); 102 | 103 | for(i = 0; i < palette->ncolors; i++) 104 | { 105 | put8(bp, palette->colors[i].r); 106 | put8(bp, palette->colors[i].g); 107 | put8(bp, palette->colors[i].b); 108 | } 109 | 110 | sendlen = (int) (bp - start); 111 | sdl_send(sd, sendlen); 112 | } 113 | 114 | void es_getPixels(sdl_data *sd, int len, char * buff) 115 | { 116 | char *bp, *start; 117 | SDL_Surface *sptr; 118 | int sendlen, x, y, w, h, xi, yi; 119 | Uint8 *row; 120 | 121 | bp = buff; 122 | POPGLPTR(sptr, bp); 123 | 124 | if(sptr == NULL) 125 | error(); 126 | x = get16be(bp); 127 | y = get16be(bp); 128 | w = get16be(bp); 129 | h = get16be(bp); 130 | 131 | if(sptr->pixels == NULL) 132 | error(); 133 | /* see /usr/local/src/SDL-1.1.3/src/video/SDL_surface.c FillRect */ 134 | 135 | start = bp = sdl_getbuff(sd, w*h*sptr->format->BytesPerPixel); 136 | row = (Uint8 *) sptr->pixels + y * sptr->pitch + 137 | x * sptr->format->BytesPerPixel; 138 | 139 | switch(sptr->format->BytesPerPixel) { 140 | case 1: { 141 | Uint8 *pixels; 142 | for(yi = h; yi; --yi){ 143 | pixels = (Uint8 *) row; 144 | for(xi = w; xi; --xi){ 145 | put8(bp, *pixels); 146 | pixels += 1; 147 | } 148 | row += sptr->pitch; 149 | } 150 | break; 151 | } 152 | case 2: 153 | { 154 | Uint16 *pixels; 155 | for(yi = h; yi; --yi){ 156 | pixels = (Uint16 *) row; 157 | for(xi = w; xi; --xi){ 158 | put16be(bp, *pixels); 159 | pixels++; 160 | } 161 | row += sptr->pitch; 162 | } 163 | } 164 | break; 165 | case 3: 166 | { 167 | Uint8 *pixels; 168 | for(yi = h; yi; --yi){ 169 | pixels = (Uint8 *) row; 170 | for(xi = w; xi; --xi){ 171 | put8(bp, *pixels); 172 | put8(bp, *(pixels+1)); 173 | put8(bp, *(pixels+2)); 174 | pixels += 3; 175 | } 176 | row += sptr->pitch; 177 | } 178 | } 179 | break; 180 | case 4: 181 | { 182 | Uint32 *pixels; 183 | for(yi = h; yi; --yi){ 184 | pixels = (Uint32 *) row; 185 | for(xi = w; xi; --xi){ 186 | put32be(bp, *pixels); 187 | pixels++; 188 | } 189 | row += sptr->pitch; 190 | } 191 | } 192 | break; 193 | } 194 | 195 | sendlen = (int) (bp - start); 196 | sdl_send(sd, sendlen); 197 | } 198 | -------------------------------------------------------------------------------- /c_src/esdl_ttf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Klas Johansson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * 7 | * $Id$ 8 | */ 9 | /* Defines the text/ttf functions */ 10 | 11 | #ifdef _USE_SDL_TTF 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define SDL_TTF_Linked_VersionFunc TTF_H +1 18 | void es_ttf_linkedVersion(sdl_data *, int, char *); 19 | #define SDL_TTF_ByteSwappedUNICODEFunc SDL_TTF_Linked_VersionFunc +1 20 | void es_ttf_byteSwappedUNICODE(sdl_data *, int, char *); 21 | #define SDL_TTF_InitFunc SDL_TTF_ByteSwappedUNICODEFunc +1 22 | void es_ttf_init(sdl_data *, int, char *); 23 | #define SDL_TTF_OpenFontFunc SDL_TTF_InitFunc +1 24 | void es_ttf_openFont(sdl_data *, int, char *); 25 | #define SDL_TTF_OpenFontIndexFunc SDL_TTF_OpenFontFunc +1 26 | void es_ttf_openFontIndex(sdl_data *, int, char *); 27 | #define SDL_TTF_OpenFontRWFunc SDL_TTF_OpenFontIndexFunc +1 28 | void es_ttf_openFontRW(sdl_data *, int, char *); 29 | #define SDL_TTF_OpenFontIndexRWFunc SDL_TTF_OpenFontRWFunc +1 30 | void es_ttf_openFontIndexRW(sdl_data *, int, char *); 31 | #define SDL_TTF_GetFontStyleFunc SDL_TTF_OpenFontIndexRWFunc +1 32 | void es_ttf_getFontStyle(sdl_data *, int, char *); 33 | #define SDL_TTF_SetFontStyleFunc SDL_TTF_GetFontStyleFunc +1 34 | void es_ttf_setFontStyle(sdl_data *, int, char *); 35 | #define SDL_TTF_FontHeightFunc SDL_TTF_SetFontStyleFunc +1 36 | void es_ttf_fontHeight(sdl_data *, int, char *); 37 | #define SDL_TTF_FontAscentFunc SDL_TTF_FontHeightFunc +1 38 | void es_ttf_fontAscent(sdl_data *, int, char *); 39 | #define SDL_TTF_FontDescentFunc SDL_TTF_FontAscentFunc +1 40 | void es_ttf_fontDescent(sdl_data *, int, char *); 41 | #define SDL_TTF_FontLineSkipFunc SDL_TTF_FontDescentFunc +1 42 | void es_ttf_fontLineSkip(sdl_data *, int, char *); 43 | #define SDL_TTF_FontFacesFunc SDL_TTF_FontLineSkipFunc +1 44 | void es_ttf_fontFaces(sdl_data *, int, char *); 45 | #define SDL_TTF_FontFaceIsFixedWidthFunc SDL_TTF_FontFacesFunc +1 46 | void es_ttf_fontFaceIsFixedWidth(sdl_data *, int, char *); 47 | #define SDL_TTF_FontFaceFamilyNameFunc SDL_TTF_FontFaceIsFixedWidthFunc +1 48 | void es_ttf_fontFaceFamilyName(sdl_data *, int, char *); 49 | #define SDL_TTF_FontFaceStyleNameFunc SDL_TTF_FontFaceFamilyNameFunc +1 50 | void es_ttf_fontFaceStyleName(sdl_data *, int, char *); 51 | #define SDL_TTF_GlyphMetricsFunc SDL_TTF_FontFaceStyleNameFunc +1 52 | void es_ttf_glyphMetrics(sdl_data *, int, char *); 53 | #define SDL_TTF_SizeTextFunc SDL_TTF_GlyphMetricsFunc +1 54 | void es_ttf_sizeText(sdl_data *, int, char *); 55 | #define SDL_TTF_SizeUTF8Func SDL_TTF_SizeTextFunc +1 56 | void es_ttf_sizeUTF8(sdl_data *, int, char *); 57 | #define SDL_TTF_SizeUNICODEFunc SDL_TTF_SizeUTF8Func +1 58 | void es_ttf_sizeUNICODE(sdl_data *, int, char *); 59 | #define SDL_TTF_RenderText_SolidFunc SDL_TTF_SizeUNICODEFunc +1 60 | void es_ttf_renderTextSolid(sdl_data *, int, char *); 61 | #define SDL_TTF_RenderUTF8_SolidFunc SDL_TTF_RenderText_SolidFunc +1 62 | void es_ttf_renderUTF8Solid(sdl_data *, int, char *); 63 | #define SDL_TTF_RenderUNICODE_SolidFunc SDL_TTF_RenderUTF8_SolidFunc +1 64 | void es_ttf_renderUNICODESolid(sdl_data *, int, char *); 65 | #define SDL_TTF_RenderGlyph_SolidFunc SDL_TTF_RenderUNICODE_SolidFunc +1 66 | void es_ttf_renderGlyphSolid(sdl_data *, int, char *); 67 | #define SDL_TTF_RenderText_ShadedFunc SDL_TTF_RenderGlyph_SolidFunc +1 68 | void es_ttf_renderTextShaded(sdl_data *, int, char *); 69 | #define SDL_TTF_RenderUTF8_ShadedFunc SDL_TTF_RenderText_ShadedFunc +1 70 | void es_ttf_renderUTF8Shaded(sdl_data *, int, char *); 71 | #define SDL_TTF_RenderUNICODE_ShadedFunc SDL_TTF_RenderUTF8_ShadedFunc +1 72 | void es_ttf_renderUNICODEShaded(sdl_data *, int, char *); 73 | #define SDL_TTF_RenderGlyph_ShadedFunc SDL_TTF_RenderUNICODE_ShadedFunc +1 74 | void es_ttf_renderGlyphShaded(sdl_data *, int, char *); 75 | #define SDL_TTF_RenderText_BlendedFunc SDL_TTF_RenderGlyph_ShadedFunc +1 76 | void es_ttf_renderTextBlended(sdl_data *, int, char *); 77 | #define SDL_TTF_RenderUTF8_BlendedFunc SDL_TTF_RenderText_BlendedFunc +1 78 | void es_ttf_renderUTF8Blended(sdl_data *, int, char *); 79 | #define SDL_TTF_RenderUNICODE_BlendedFunc SDL_TTF_RenderUTF8_BlendedFunc +1 80 | void es_ttf_renderUNICODEBlended(sdl_data *, int, char *); 81 | #define SDL_TTF_RenderGlyph_BlendedFunc SDL_TTF_RenderUNICODE_BlendedFunc +1 82 | void es_ttf_renderGlyphBlended(sdl_data *, int, char *); 83 | #define SDL_TTF_CloseFontFunc SDL_TTF_RenderGlyph_BlendedFunc +1 84 | void es_ttf_closeFont(sdl_data *, int, char *); 85 | #define SDL_TTF_QuitFunc SDL_TTF_CloseFontFunc +1 86 | void es_ttf_quit(sdl_data *, int, char *); 87 | #define SDL_TTF_WasInitFunc SDL_TTF_QuitFunc +1 88 | void es_ttf_wasInit(sdl_data *, int, char *); 89 | #define SDL_TTF_SetErrorFunc SDL_TTF_WasInitFunc +1 90 | void es_ttf_setError(sdl_data *, int, char *); 91 | #define SDL_TTF_GetErrorFunc SDL_TTF_SetErrorFunc +1 92 | void es_ttf_getError(sdl_data *, int, char *); 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif /* _USE_SDL_TTF */ 99 | -------------------------------------------------------------------------------- /api_gen/gludefs: -------------------------------------------------------------------------------- 1 | enum { 2 | /* Normal vectors */ 3 | GLU_SMOOTH = 100000, 4 | GLU_FLAT = 100001, 5 | GLU_NONE = 100002, 6 | 7 | /* Quadric draw styles */ 8 | GLU_POINT = 100010, 9 | GLU_LINE = 100011, 10 | GLU_FILL = 100012, 11 | GLU_SILHOUETTE = 100013, 12 | 13 | /* Quadric orientation */ 14 | GLU_OUTSIDE = 100020, 15 | GLU_INSIDE = 100021, 16 | 17 | /* Tessellator */ 18 | GLU_TESS_BEGIN = 100100, 19 | GLU_TESS_VERTEX = 100101, 20 | GLU_TESS_END = 100102, 21 | GLU_TESS_ERROR = 100103, 22 | GLU_TESS_EDGE_FLAG = 100104, 23 | GLU_TESS_COMBINE = 100105, 24 | 25 | GLU_TESS_BEGIN_DATA = 100106, 26 | GLU_TESS_VERTEX_DATA = 100107, 27 | GLU_TESS_END_DATA = 100108, 28 | GLU_TESS_ERROR_DATA = 100109, 29 | GLU_TESS_EDGE_FLAG_DATA = 100110, 30 | GLU_TESS_COMBINE_DATA = 100111, 31 | 32 | /* Winding rules */ 33 | GLU_TESS_WINDING_ODD = 100130, 34 | GLU_TESS_WINDING_NONZERO = 100131, 35 | GLU_TESS_WINDING_POSITIVE = 100132, 36 | GLU_TESS_WINDING_NEGATIVE = 100133, 37 | GLU_TESS_WINDING_ABS_GEQ_TWO = 100134, 38 | 39 | /* Tessellation properties */ 40 | GLU_TESS_WINDING_RULE = 100140, 41 | GLU_TESS_BOUNDARY_ONLY = 100141, 42 | GLU_TESS_TOLERANCE = 100142, 43 | 44 | /* Tessellation errors */ 45 | GLU_TESS_ERROR1 = 100151, /* Missing gluBeginPolygon */ 46 | GLU_TESS_ERROR2 = 100152, /* Missing gluBeginContour */ 47 | GLU_TESS_ERROR3 = 100153, /* Missing gluEndPolygon */ 48 | GLU_TESS_ERROR4 = 100154, /* Missing gluEndContour */ 49 | GLU_TESS_ERROR5 = 100155, /* */ 50 | GLU_TESS_ERROR6 = 100156, /* */ 51 | GLU_TESS_ERROR7 = 100157, /* */ 52 | GLU_TESS_ERROR8 = 100158, /* */ 53 | 54 | /* NURBS */ 55 | GLU_AUTO_LOAD_MATRIX = 100200, 56 | GLU_CULLING = 100201, 57 | GLU_PARAMETRIC_TOLERANCE = 100202, 58 | GLU_SAMPLING_TOLERANCE = 100203, 59 | GLU_DISPLAY_MODE = 100204, 60 | GLU_SAMPLING_METHOD = 100205, 61 | GLU_U_STEP = 100206, 62 | GLU_V_STEP = 100207, 63 | 64 | GLU_PATH_LENGTH = 100215, 65 | GLU_PARAMETRIC_ERROR = 100216, 66 | GLU_DOMAIN_DISTANCE = 100217, 67 | 68 | GLU_MAP1_TRIM_2 = 100210, 69 | GLU_MAP1_TRIM_3 = 100211, 70 | 71 | GLU_OUTLINE_POLYGON = 100240, 72 | GLU_OUTLINE_PATCH = 100241, 73 | 74 | GLU_NURBS_ERROR1 = 100251, /* spline order un-supported */ 75 | GLU_NURBS_ERROR2 = 100252, /* too few knots */ 76 | GLU_NURBS_ERROR3 = 100253, /* valid knot range is empty */ 77 | GLU_NURBS_ERROR4 = 100254, /* decreasing knot sequence */ 78 | GLU_NURBS_ERROR5 = 100255, /* knot multiplicity > spline order */ 79 | GLU_NURBS_ERROR6 = 100256, /* endcurve() must follow bgncurve() */ 80 | GLU_NURBS_ERROR7 = 100257, /* bgncurve() must precede endcurve() */ 81 | GLU_NURBS_ERROR8 = 100258, /* ctrlarray or knot vector is NULL */ 82 | GLU_NURBS_ERROR9 = 100259, /* can't draw pwlcurves */ 83 | GLU_NURBS_ERROR10 = 100260, /* missing gluNurbsCurve() */ 84 | GLU_NURBS_ERROR11 = 100261, /* missing gluNurbsSurface() */ 85 | GLU_NURBS_ERROR12 = 100262, /* endtrim() must precede endsurface() */ 86 | GLU_NURBS_ERROR13 = 100263, /* bgnsurface() must precede endsurface() */ 87 | GLU_NURBS_ERROR14 = 100264, /* curve of improper type passed as trim curve */ 88 | GLU_NURBS_ERROR15 = 100265, /* bgnsurface() must precede bgntrim() */ 89 | GLU_NURBS_ERROR16 = 100266, /* endtrim() must follow bgntrim() */ 90 | GLU_NURBS_ERROR17 = 100267, /* bgntrim() must precede endtrim() */ 91 | GLU_NURBS_ERROR18 = 100268, /* invalid or missing trim curve */ 92 | GLU_NURBS_ERROR19 = 100269, /* bgntrim() must precede pwlcurve() */ 93 | GLU_NURBS_ERROR20 = 100270, /* pwlcurve referenced twice */ 94 | GLU_NURBS_ERROR21 = 100271, /* pwlcurve and nurbscurve mixed */ 95 | GLU_NURBS_ERROR22 = 100272, /* improper usage of trim data type */ 96 | GLU_NURBS_ERROR23 = 100273, /* nurbscurve referenced twice */ 97 | GLU_NURBS_ERROR24 = 100274, /* nurbscurve and pwlcurve mixed */ 98 | GLU_NURBS_ERROR25 = 100275, /* nurbssurface referenced twice */ 99 | GLU_NURBS_ERROR26 = 100276, /* invalid property */ 100 | GLU_NURBS_ERROR27 = 100277, /* endsurface() must follow bgnsurface() */ 101 | GLU_NURBS_ERROR28 = 100278, /* intersecting or misoriented trim curves */ 102 | GLU_NURBS_ERROR29 = 100279, /* intersecting trim curves */ 103 | GLU_NURBS_ERROR30 = 100280, /* UNUSED */ 104 | GLU_NURBS_ERROR31 = 100281, /* unconnected trim curves */ 105 | GLU_NURBS_ERROR32 = 100282, /* unknown knot error */ 106 | GLU_NURBS_ERROR33 = 100283, /* negative vertex count encountered */ 107 | GLU_NURBS_ERROR34 = 100284, /* negative byte-stride */ 108 | GLU_NURBS_ERROR35 = 100285, /* unknown type descriptor */ 109 | GLU_NURBS_ERROR36 = 100286, /* null control point reference */ 110 | GLU_NURBS_ERROR37 = 100287, /* duplicate point on pwlcurve */ 111 | 112 | /* Errors */ 113 | GLU_INVALID_ENUM = 100900, 114 | GLU_INVALID_VALUE = 100901, 115 | GLU_OUT_OF_MEMORY = 100902, 116 | GLU_INCOMPATIBLE_GL_VERSION = 100903, 117 | 118 | /* New in GLU 1.1 */ 119 | GLU_VERSION = 100800, 120 | GLU_EXTENSIONS = 100801, 121 | 122 | /* ** GLU 1.0 tessellation - obsolete! ** */ 123 | 124 | /* Contour types */ 125 | GLU_CW = 100120, 126 | GLU_CCW = 100121, 127 | GLU_INTERIOR = 100122, 128 | GLU_EXTERIOR = 100123, 129 | GLU_UNKNOWN = 100124, 130 | 131 | /* Tessellator */ 132 | GLU_BEGIN = GLU_TESS_BEGIN, 133 | GLU_VERTEX = GLU_TESS_VERTEX, 134 | GLU_END = GLU_TESS_END, 135 | GLU_ERROR = GLU_TESS_ERROR, 136 | GLU_EDGE_FLAG = GLU_TESS_EDGE_FLAG 137 | }; 138 | -------------------------------------------------------------------------------- /woggle/tools/gen_func.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ERL_PLACEHOLDER='%% PLACEHOLDER_FOR_GENERATED_FUNCTIONS' 4 | C_PLACEHOLDER='PLACEHOLDER_FOR_GENERATED_FUNCTIONS' 5 | TEMPFILE_TEMPLATE=/tmp/gen_func 6 | FINAL_COMMAND="" 7 | 8 | usage () 9 | { 10 | echo "Usage: $0 {woggle|compat} {call|cast} " 11 | exit 1 12 | } 13 | 14 | erlang_source () 15 | { 16 | echo "adding to $2:" 17 | TEMPFILE=${TEMPFILE_TEMPLATE}_1.tmp 18 | cp $2 $TEMPFILE 19 | ed $TEMPFILE > /dev/null 2>&1 < 23 | $CALLTYPE($ERLOPNAME,<<>>). 24 | 25 | . 26 | w 27 | EOF 28 | diff -c $2 $TEMPFILE 29 | echo -n 'edit OK? [ = continue,^C = quit]' 30 | read dummy 31 | FINAL_COMMAND="$FINAL_COMMAND cp $TEMPFILE $2;" 32 | } 33 | 34 | erlang_opcode () 35 | { 36 | last=`grep "$ERL_PLACEHOLDER" $2 | sed "s,$ERL_PLACEHOLDER:\([^ ]*\).*$,\1,g"` 37 | echo "adding to $2:" 38 | TEMPFILE=${TEMPFILE_TEMPLATE}_2.tmp 39 | cp $2 $TEMPFILE 40 | ed $TEMPFILE > /dev/null 2>&1 < = continue,^C = quit]' 51 | read dummy 52 | FINAL_COMMAND="$FINAL_COMMAND cp $TEMPFILE $2;" 53 | } 54 | 55 | c_opcode () 56 | { 57 | last=`grep "$C_PLACEHOLDER" $3 | sed "s,/\*$C_PLACEHOLDER:\([^ ]*\).*\*/$,\1,g"` 58 | echo "adding to $3:" 59 | TEMPFILE=${TEMPFILE_TEMPLATE}_3.tmp 60 | cp $3 $TEMPFILE 61 | ed $TEMPFILE > /dev/null 2>&1 < = continue,^C = quit]' 73 | read dummy 74 | FINAL_COMMAND="$FINAL_COMMAND cp $TEMPFILE $3;" 75 | } 76 | 77 | c_opcode_compat () 78 | { 79 | echo "adding to $2:" 80 | TEMPFILE=${TEMPFILE_TEMPLATE}_3.tmp 81 | cp $2 $TEMPFILE 82 | ed $TEMPFILE > /dev/null 2>&1 < = continue,^C = quit]' 92 | read dummy 93 | FINAL_COMMAND="$FINAL_COMMAND cp $TEMPFILE $2;" 94 | } 95 | 96 | c_funtab () 97 | { 98 | echo "adding to $3:" 99 | TEMPFILE=${TEMPFILE_TEMPLATE}_4.tmp 100 | cp $3 $TEMPFILE 101 | ed $TEMPFILE > /dev/null 2>&1 < = continue,^C = quit]' 110 | read dummy 111 | FINAL_COMMAND="$FINAL_COMMAND cp $TEMPFILE $3;" 112 | } 113 | 114 | c_source () 115 | { 116 | echo "adding to $2:" 117 | TEMPFILE=${TEMPFILE_TEMPLATE}_5.tmp 118 | cp $2 $TEMPFILE 119 | ed $TEMPFILE > /dev/null 2>&1 < = continue,^C = quit]' 131 | read dummy 132 | FINAL_COMMAND="$FINAL_COMMAND cp $TEMPFILE $2;" 133 | } 134 | 135 | if [ -z "$WOGGLE_TOP" ]; then 136 | echo set WOGGLE_TOP please. 137 | exit 1 138 | fi 139 | 140 | if [ $# -lt 3 ]; then 141 | usage 142 | fi 143 | 144 | if [ \( $1 != "woggle" \) -a \( $1 != "compat" \) ]; then 145 | usage 146 | fi 147 | if [ \( $2 != "call" \) -a \( $2 != "cast" \) ]; then 148 | usage 149 | fi 150 | 151 | GENTYPE=$1 152 | CALLTYPE=$2 153 | ERLNAME=$3 154 | UNDERSCORED=`echo $ERLNAME | sed 's,[A-Z],_&,g' | tr "[:upper:]" "[:lower:]"` 155 | 156 | case $ERLNAME in 157 | gl_*|wm_*) 158 | initial=`echo $ERLNAME | sed 's,\(....\).*,\1,g'`; 159 | rest=`echo $ERLNAME | sed 's,....\(.*\),\1,g'`;; 160 | *) 161 | initial=`echo $ERLNAME | sed 's,\(.\).*,\1,g'`; 162 | rest=`echo $ERLNAME | sed 's,.\(.*\),\1,g'`;; 163 | esac 164 | cinitial=`echo $initial | tr "[:lower:]" "[:upper:]"` 165 | if [ $cinitial = $initial ]; then 166 | echo "initial character of erlang name should be lowercase." 167 | usage 168 | fi 169 | CAPERLNAME=${cinitial}${rest} 170 | 171 | ESDL_HEADERS="../../c_src/esdl_video.h ../../c_src/esdl_events.h" 172 | 173 | if [ $GENTYPE = woggle ]; then 174 | ERLOPNAME=WOGGLE_$CAPERLNAME 175 | COPNAME=WOGGLE_${CAPERLNAME}Func 176 | CFUNNAME="wog_if_$UNDERSCORED" 177 | erlang_source $ERLNAME $WOGGLE_TOP/src/woggle.erl 178 | erlang_opcode $ERLOPNAME $WOGGLE_TOP/src/woggle_ops.hrl 179 | c_opcode $COPNAME $CFUNNAME $WOGGLE_TOP/c_src/woggle_if.h 180 | c_funtab $COPNAME $CFUNNAME $WOGGLE_TOP/c_src/woggle_if_fp.h 181 | c_source $CFUNNAME $WOGGLE_TOP/c_src/woggle_if.c 182 | eval "$FINAL_COMMAND echo Changes stored." 183 | else 184 | matches=`grep -h _${CAPERLNAME}Func $ESDL_HEADERS | grep -v ".*_${CAPERLNAME}Func *+ *1 *" | wc -l` 185 | echo grep -h _${CAPERLNAME}Func $ESDL_HEADERS '|' grep -v '"'"(.*_${CAPERLNAME}Func *+ *1 *)"'"' 186 | if [ $matches -ne 1 ]; then 187 | echo Could not resolve opcode for $ERLNAME 188 | exit 1 189 | fi 190 | COPNAME=`grep -h _${CAPERLNAME}Func $ESDL_HEADERS | grep -v ".*_${CAPERLNAME}Func *+ *1 *" | awk '{print $2}'` 191 | CFUNNAME="wog_compat_if_$UNDERSCORED" 192 | c_opcode_compat $CFUNNAME $WOGGLE_TOP/c_src/woggle_compat_if.h 193 | c_funtab $COPNAME $CFUNNAME $WOGGLE_TOP/c_src/woggle_compat_if_fp.h 194 | c_source $CFUNNAME $WOGGLE_TOP/c_src/woggle_compat_if.c 195 | eval "$FINAL_COMMAND echo Changes stored." 196 | fi 197 | 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /include/sdl_video.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_video.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : defines from SDL_video.h 12 | %%% Created : 22 Jun 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | %% Statics 16 | 17 | %% Data Types 18 | -record(sdl_rect, {x, y, w, h}). 19 | -record(sdl_color, {r,g,b}). %% Where each color is 8bits 20 | %% sdl_palette = [sdl_color] 21 | -record(sdl_pixelformat, 22 | { 23 | self = null, %% Ref to this record 24 | palette = null, %% colorRef 25 | bitsPerPixel, %% Uint8 26 | bytesPerPixel, %% Uint8 27 | rloss, %% Uint8 28 | gloss, %% Uint8 29 | bloss, %% Uint8 30 | aloss, %% Uint8 31 | rshift, %% Uint8 32 | gshift, %% Uint8 33 | bshift, %% Uint8 34 | ashift, %% Uint8 35 | rmask, %% Uint32 36 | gmask, %% Uint32 37 | bmask, %% Uint32 38 | amask, %% Uint32 39 | 40 | %%/* RGB color key information */ 41 | colorkey, %% Uint32 42 | %%/* Alpha value information (per-surface alpha) */ 43 | alpha %% Uint8 44 | }). 45 | 46 | -record(sdl_surface, 47 | { 48 | self, %% Ref to this record 49 | flags, % Uint32 /* Read-only */ 50 | format, % SDL_PixelFormat ref* /* Read-only */ 51 | w, h, % int /* Read-only */ 52 | pitch, % Uint16 /* Read-only */ 53 | pixels, % void * ref /* Read-write */ 54 | offset % int /* Private */ 55 | 56 | %% /* Hardware-specific surface info */ 57 | %%hwdata, % struct private_hwdata /* clipping information */ 58 | % clip_minx, % int /* Read-only */ 59 | % clip_maxx, % int /* Read-only */ 60 | % clip_miny, % int /* Read-only */ 61 | % clip_maxy % int /* Read-only */ 62 | 63 | %% /* info for fast blit mapping to other surfaces */ 64 | %%map, % struct SDL_BlitMap /* Private */ 65 | 66 | %% /* List of surfaces mapped */ 67 | %%mapped, % struct map_list /* Private */ 68 | 69 | %% /* Reference count -- used when freeing surface */ 70 | %%refcount % int /* Read-mostly */ 71 | }). 72 | 73 | -record(sdl_videoinfo, 74 | { 75 | hw_available , %boolean Flag: Can you create hardware surfaces? 76 | wm_available , %boolean Flag: Can you talk to a window manager? 77 | blit_hw , %boolean Flag: Accelerated blits HW --> HW 78 | blit_hw_CC , %boolean Flag: Accelerated blits with Colorkey 79 | blit_hw_A , %boolean Flag: Accelerated blits with Alpha 80 | blit_sw , %boolean Flag: Accelerated blits SW --> HW 81 | blit_sw_CC , %boolean Flag: Accelerated blits with Colorkey 82 | blit_sw_A , %boolean Flag: Accelerated blits with Alpha 83 | blit_fill , %boolean Flag: Accelerated color fill 84 | video_mem , % video memory in k bytes 85 | vfmt % Ref to SDL_PixelFormat 86 | }). 87 | 88 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 89 | %% SDL_video.h see file for documentation 90 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 91 | -define(SDL_GRAB_QUERY, -1). 92 | -define(SDL_GRAB_OFF, 0). 93 | -define(SDL_GRAB_ON, 1). 94 | -define(SDL_GRAB_FULLSCREEN, 2). 95 | 96 | %%/* These are the currently supported flags for the SDL_surface */ 97 | %%/* Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */ 98 | 99 | -define( SDL_SWSURFACE, 16#00000000). %% /* Surface is in system memory */ 100 | -define( SDL_HWSURFACE, 16#00000001). %% /* Surface is in video memory */ 101 | 102 | -define( SDL_ASYNCBLIT, 16#00000004). %% /* Use asynchronous blits if possible */ 103 | 104 | %% /* Available for SDL_SetVideoMode() */ 105 | -define( SDL_ANYFORMAT, 16#10000000). %% /* Allow any video depth/pixel-format */ 106 | -define( SDL_HWPALETTE, 16#20000000). %% /* Surface has exclusive palette */ 107 | -define( SDL_DOUBLEBUF, 16#40000000). %% /* Set up double-buffered video mode */ 108 | -define( SDL_FULLSCREEN,16#80000000). %% /* Surface is a full screen display */ 109 | -define( SDL_OPENGL, 16#00000002). %% /* Create an OpenGL rendering context */ 110 | -define( SDL_RESIZABLE, 16#00000010). %% /* This video mode may be resized */ 111 | -define( SDL_NOFRAME, 16#00000020). %% /* No window caption or edge frame */ 112 | 113 | %% /* Used internally (read-only) */ 114 | -define( SDL_HWACCEL, 16#00000100). %%/* Blit uses hardware acceleration */ 115 | -define( SDL_SRCCOLORKEY, 16#00001000). %%/* Blit uses a source color key */ 116 | -define( SDL_RLEACCELOK, 16#00002000). %%/* Private flag */ 117 | -define( SDL_RLEACCEL, 16#00004000). %%/* Colorkey blit is RLE accelerated */ 118 | -define( SDL_SRCALPHA, 16#00010000). %%/* Blit uses source alpha blending */ 119 | -define( SDL_SRCCLIPPING, 16#00100000). %%/* Blit uses source clipping */ 120 | -define( SDL_PREALLOC, 16#01000000). %%/* Surface uses preallocated memory */ 121 | 122 | %% The OpenGL window attributes 123 | -define(SDL_GL_RED_SIZE, 0). 124 | -define(SDL_GL_GREEN_SIZE, 1). 125 | -define(SDL_GL_BLUE_SIZE, 2). 126 | -define(SDL_GL_ALPHA_SIZE, 3). 127 | -define(SDL_GL_BUFFER_SIZE, 4). 128 | -define(SDL_GL_DOUBLEBUFFER, 5). 129 | -define(SDL_GL_DEPTH_SIZE, 6). 130 | -define(SDL_GL_STENCIL_SIZE, 7). 131 | -define(SDL_GL_ACCUM_RED_SIZE, 8). 132 | -define(SDL_GL_ACCUM_GREEN_SIZE, 9). 133 | -define(SDL_GL_ACCUM_BLUE_SIZE, 10). 134 | -define(SDL_GL_ACCUM_ALPHA_SIZE, 11). 135 | -define(SDL_GL_STEREO, 12). 136 | -define(SDL_GL_MULTISAMPLEBUFFERS, 13). 137 | -define(SDL_GL_MULTISAMPLESAMPLES, 14). 138 | -define(SDL_GL_ACCELERATED_VISUAL, 15). 139 | -define(SDL_GL_SWAP_CONTROL, 16). 140 | 141 | 142 | -------------------------------------------------------------------------------- /woggle/test/woggle_test.erl: -------------------------------------------------------------------------------- 1 | -module(woggle_test). 2 | 3 | -compile(export_all). 4 | -include("sdl_video.hrl"). 5 | -include("sdl_events.hrl"). 6 | -include("gl.hrl"). 7 | 8 | go() -> 9 | code:add_path("../../ebin"), 10 | woggle:init(), 11 | io:format("Driver ~p ~n", [sdl_video:videoDriverName()]), 12 | io:format("~p~n",[woggle:listModes()]), 13 | io:format("~p~n",[sdl_video:listModes(null,?SDL_FULLSCREEN)]), 14 | 15 | %% Misconseption from testgl.erl, but compatibility is useful anyway... 16 | AvailableWindowedSzs = sdl_video:listModes(null, ?SDL_FULLSCREEN), 17 | io:format("Available WindowSizes ~p ~n", [AvailableWindowedSzs]), 18 | case AvailableWindowedSzs of 19 | [{_, 0,0,W,H}|_] -> 20 | Res = [Test || Test <- [32,24,16,15], 21 | true == sdl_video:videoModeOK(W,H,Test,0)], 22 | io:format("A guess at max video res is ~px~p:~p ~n", [W,H, hd(Res)]); 23 | _ -> 24 | io:format("Can't guess max resolution~n", []) 25 | end, 26 | 27 | sdl_video:setVideoMode(640,480,16,?SDL_OPENGL bor ?SDL_RESIZABLE), 28 | sdl_video:gl_setAttribute(?SDL_GL_DOUBLEBUFFER, 1), %Ignored 29 | Rs= sdl_video:gl_getAttribute(?SDL_GL_RED_SIZE), 30 | Gs= sdl_video:gl_getAttribute(?SDL_GL_GREEN_SIZE), 31 | Bs= sdl_video:gl_getAttribute(?SDL_GL_BLUE_SIZE), 32 | Ds= sdl_video:gl_getAttribute(?SDL_GL_DEPTH_SIZE), 33 | Dz= sdl_video:gl_getAttribute(?SDL_GL_BUFFER_SIZE), 34 | Db= (1 == sdl_video:gl_getAttribute(?SDL_GL_DOUBLEBUFFER)), 35 | io:format("OpenGL attributes ~n"), 36 | io:format("Sizes in bits Red ~p Green ~p Blue ~p Depth ~p Buffer ~p Doublebuffered ~p~n", 37 | [Rs, Gs, Bs, Ds, Dz, Db]), 38 | io:format("Vendor: ~s~n", [gl:getString(?GL_VENDOR)]), 39 | io:format("Renderer: ~s~n", [gl:getString(?GL_RENDERER)]), 40 | io:format("Version: ~s~n", [gl:getString(?GL_VERSION)]), 41 | io:format("GL AUX BUFFERS ~p~n", [gl:getIntegerv(?GL_AUX_BUFFERS)]), 42 | io:format("SDL Version ~p~n", [sdl_video:wm_getInfo()]), 43 | 44 | io:format("Extensions: ~s~n", [gl:getString(?GL_EXTENSIONS)]), 45 | io:format("Maximized: ~p~n", [sdl_video:wm_isMaximized()]), 46 | 47 | io:format("~p", [catch gl:getConvolutionParameterfv(16#8011, 16#801A)]), 48 | sdl_events:eventState(?SDL_ALLEVENTS ,?SDL_ENABLE), 49 | sdl_events:eventState(?SDL_KEYDOWN ,?SDL_ENABLE), 50 | sdl_events:eventState(?SDL_QUIT ,?SDL_ENABLE), 51 | sdl_events:eventState(?SDL_VIDEORESIZE, ?SDL_ENABLE), 52 | 53 | dogl_start(), 54 | dogl(10000). 55 | 56 | 57 | dogl_start() -> 58 | gl:viewport(0,0,640,480), 59 | gl:matrixMode(?GL_PROJECTION), 60 | gl:loadIdentity(), 61 | gl:ortho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0), 62 | gl:matrixMode(?GL_MODELVIEW), 63 | gl:loadIdentity(), 64 | gl:enable(?GL_DEPTH_TEST), 65 | gl:depthFunc(?GL_LESS), 66 | gl:clearColor(0.0,0.0,0.0,1.0), 67 | io:format("Vendor: ~s~n", [gl:getString(?GL_VENDOR)]), 68 | gl:clear(?GL_COLOR_BUFFER_BIT bor ?GL_DEPTH_BUFFER_BIT). 69 | 70 | dogl(0) -> 71 | ok; 72 | 73 | dogl(N) -> 74 | gl:clearColor(0.0,0.0,0.0,1.0), 75 | gl:clear(?GL_COLOR_BUFFER_BIT bor ?GL_DEPTH_BUFFER_BIT), 76 | Cube = {{ 0.5, 0.5, -0.5}, 77 | { 0.5, -0.5, -0.5}, 78 | {-0.5, -0.5, -0.5}, 79 | {-0.5, 0.5, -0.5}, 80 | {-0.5, 0.5, 0.5}, 81 | { 0.5, 0.5, 0.5}, 82 | { 0.5, -0.5, 0.5}, 83 | {-0.5, -0.5, 0.5}}, 84 | Colors = {{ 1.0, 1.0, 0.0}, 85 | { 1.0, 0.0, 0.0}, 86 | { 0.0, 0.0, 0.0}, 87 | { 0.0, 1.0, 0.0}, 88 | { 0.0, 1.0, 1.0}, 89 | { 1.0, 1.0, 1.0}, 90 | { 1.0, 0.0, 1.0}, 91 | { 0.0, 0.0, 1.0}}, 92 | 93 | gl:glBegin(?GL_QUADS), 94 | 95 | gl:color3fv(element(1, Colors)), 96 | gl:vertex3fv(element(1, Cube)), 97 | gl:color3fv(element(2, Colors)), 98 | gl:vertex3fv(element(2, Cube)), 99 | gl:color3fv(element(3, Colors)), 100 | gl:vertex3fv(element(3, Cube)), 101 | gl:color3fv(element(4, Colors)), 102 | gl:vertex3fv(element(4, Cube)), 103 | 104 | gl:color3fv(element(4, Colors)), 105 | gl:vertex3fv(element(4, Cube)), 106 | gl:color3fv(element(5, Colors)), 107 | gl:vertex3fv(element(5, Cube)), 108 | gl:color3fv(element(8, Colors)), 109 | gl:vertex3fv(element(8, Cube)), 110 | gl:color3fv(element(3, Colors)), 111 | gl:vertex3fv(element(3, Cube)), 112 | 113 | gl:color3fv(element(1, Colors)), 114 | gl:vertex3fv(element(1, Cube)), 115 | gl:color3fv(element(6, Colors)), 116 | gl:vertex3fv(element(6, Cube)), 117 | gl:color3fv(element(7, Colors)), 118 | gl:vertex3fv(element(7, Cube)), 119 | gl:color3fv(element(2, Colors)), 120 | gl:vertex3fv(element(2, Cube)), 121 | 122 | gl:color3fv(element(6, Colors)), 123 | gl:vertex3fv(element(6, Cube)), 124 | gl:color3fv(element(5, Colors)), 125 | gl:vertex3fv(element(5, Cube)), 126 | gl:color3fv(element(8, Colors)), 127 | gl:vertex3fv(element(8, Cube)), 128 | gl:color3fv(element(7, Colors)), 129 | gl:vertex3fv(element(7, Cube)), 130 | 131 | gl:color3fv(element(6, Colors)), 132 | gl:vertex3fv(element(6, Cube)), 133 | gl:color3fv(element(1, Colors)), 134 | gl:vertex3fv(element(1, Cube)), 135 | gl:color3fv(element(4, Colors)), 136 | gl:vertex3fv(element(4, Cube)), 137 | gl:color3fv(element(5, Colors)), 138 | gl:vertex3fv(element(5, Cube)), 139 | 140 | gl:color3fv(element(7, Colors)), 141 | gl:vertex3fv(element(7, Cube)), 142 | gl:color3fv(element(2, Colors)), 143 | gl:vertex3fv(element(2, Cube)), 144 | gl:color3fv(element(3, Colors)), 145 | gl:vertex3fv(element(3, Cube)), 146 | gl:color3fv(element(8, Colors)), 147 | gl:vertex3fv(element(8, Cube)), 148 | 149 | gl:glEnd(), 150 | gl:matrixMode(?GL_MODELVIEW), 151 | gl:rotatef(5.0, 1.0, 1.0, 1.0), 152 | woggle:swapBuffers(), 153 | %gl:swapBuffers(), 154 | poll_events(), 155 | dogl(N-1). 156 | 157 | poll_events() -> 158 | case sdl_events:pollEvent() of 159 | no_event -> 160 | ok; 161 | Event -> 162 | io:format("Got event ~p~n", [Event]), 163 | poll_events() 164 | end. 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /src/sdl_audio.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%% File : sdl_audio.erl 9 | %%% Author : Dan Gudmundsson 10 | %%% Purpose : Implements a SDL_AUDIO interface 11 | %%% Created : 9 Aug 2000 by Dan Gudmundsson 12 | 13 | -module(sdl_audio). 14 | 15 | -compile(export_all). 16 | 17 | -include("esdl.hrl"). 18 | -include("sdl_util.hrl"). 19 | 20 | %% Functions 21 | 22 | -define(SDL_AudioDriverName, ?SDL_AUDIO_HRL +1). 23 | -define(SDL_OpenAudio, ?SDL_AudioDriverName +1). 24 | -define(SDL_GetAudioStatus, ?SDL_OpenAudio +1). 25 | -define(SDL_PauseAudio, ?SDL_GetAudioStatus +1). 26 | -define(SDL_LoadWAV, ?SDL_PauseAudio +1). 27 | -define(SDL_LoadWAV_RW, ?SDL_LoadWAV +1). 28 | -define(SDL_FreeWAV, ?SDL_LoadWAV_RW +1). 29 | -define(SDL_BuildAudioCVT, ?SDL_FreeWAV +1). 30 | -define(SDL_ConvertAudio, ?SDL_BuildAudioCVT +1). 31 | -define(SDL_MixAudio, ?SDL_ConvertAudio +1). 32 | -define(SDL_LockAudio, ?SDL_MixAudio +1). 33 | -define(SDL_UnlockAudio, ?SDL_LockAudio +1). 34 | -define(SDL_CloseAudio, ?SDL_UnlockAudio +1). 35 | -define(PLAY_AUDIO, ?SDL_CloseAudio +1). 36 | 37 | -import(sdl, [cast/2,call/2]). 38 | 39 | -include("sdl_audio.hrl"). 40 | 41 | -record(audiop, %Pointer to loaded audio data. 42 | {ptr, 43 | size}). 44 | 45 | %% Func: audioDrivername() 46 | %% Args: none 47 | %% Returns: DriverName(String) or [] 48 | %% C-API func: char *SDL_AudioDriverName(char *namebuf, int maxlen); 49 | audioDrivername() -> 50 | binary_to_list(call(?SDL_AudioDriverName, [])). 51 | 52 | %% Func: openAudio 53 | %% Args: DesiredFormat (audiospec-record), ForceFormat (true | false) 54 | %% Returns: ObtainedFormat or exit(audio_failure) 55 | %% C-API func: int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained); 56 | openAudio(Desired, ForceFormat) when is_record(Desired, audiospec) -> 57 | FF = if 58 | ForceFormat == true -> 1; 59 | ForceFormat == false -> 0 60 | end, 61 | Res = call(?SDL_OpenAudio, 62 | <>), 69 | case Res of 70 | <<>> -> 71 | exit(audio_failure); 72 | <> -> 74 | #audiospec{freq=Freq, format=Format, channels=Chs, silence=Sil, 75 | samples=Samps, padding=Padding, size=Size} 76 | end. 77 | 78 | %% Func: closeAudio 79 | %% Args: none 80 | %% Returns: ok 81 | %% C-API func: void SDL_CloseAudio(void); 82 | closeAudio() -> 83 | cast(?SDL_CloseAudio, []). 84 | 85 | %% Func: getAudioStatus 86 | %% Args: none 87 | %% Returns: Status 88 | %% C-API func: SDL_audiostatus SDL_GetAudioStatus(void); 89 | getAudioStatus() -> 90 | <> = call(?SDL_GetAudioStatus, []), 91 | Res. 92 | 93 | %% Func: pauseAudio 94 | %% Args: [true | false] 95 | %% Returns: ok 96 | %% C-API func: void SDL_PauseAudio(int pause_on); 97 | pauseAudio(true) -> 98 | cast(?SDL_PauseAudio, [1]); 99 | pauseAudio(false) -> 100 | cast(?SDL_PauseAudio, [0]). 101 | 102 | %% Func: loadWAV 103 | %% Args: FileName 104 | %% Returns: {AudioSpec, AudioBufferPtr} or exits 105 | %% C-API func: SDL_AudioSpec *SDL_LoadWAV(char *file, SDL_AudioSpec *spec, 106 | %% Uint8 **audio_buf, Uint32 *audio_len) 107 | loadWAV(File) -> 108 | Res = call(?SDL_LoadWAV, [File,0]), 109 | case Res of 110 | <> -> 113 | {#audiospec{freq=Freq, format=Format, channels=Chs, silence=Sil, 114 | samples=Samps, padding=Padding, size=Size}, 115 | #audiop{ptr=BufferPtr,size=BufferLen}}; 116 | Else -> 117 | erlang:error({load_wav_failed, Else}) 118 | end. 119 | 120 | %% Func: freeWAV 121 | %% Args: AudioWavRef 122 | %% Returns: ok 123 | %% C-API func: void SDL_FreeWAV(Uint8 *audio_buf); 124 | freeWAV(#audiop{ptr=Ptr}) -> 125 | cast(?SDL_FreeWAV, <>). 126 | 127 | %% Func: play_audio 128 | %% Args: AudioWavRef, SampleLen, Repeat (integer or infinity) 129 | %% Returns: ok 130 | %% Desc: Used to start audio playing 131 | play_audio(#audiop{ptr=Ptr,size=Size}, Repeat) -> 132 | R = if Repeat == infinity -> -1; 133 | true -> Repeat 134 | end, 135 | <<>> = call(?PLAY_AUDIO, <>). 136 | 137 | % %% Func: buildAudioCVT 138 | % %% Args: Src_format, Src_channels, Src_rate, 139 | % %% Dst_format, Dst_channels, Dst_rate 140 | % %% Returns: CVT record 141 | % %% Desc: 142 | 143 | %% Func: convertAudio 144 | %% Args: FromAudioSpec, ToAudioSpec, SampleBuffer 145 | %% Returns: NewBuffer or exists if conversion failed 146 | %% C-API func: int SDL_ConvertAudio(SDL_AudioCVT *cvt); 147 | %% Desc: This differs from the orginal SDL function in both syntax 148 | %% and semantics, convertAudio handles the buildCVT and other things 149 | %% SDL requires. 150 | %% convertAudio converts Buffer (in 'FromAudioSpec' format) and 151 | %% returns a new audio buffer (in 'ToAudioSpec' format) 152 | %% Don't forget to call freeWav with old Buffer 153 | 154 | convertAudio(FromAS, ToAS, #audiop{ptr=Ptr,size=Size}) -> 155 | Res = call(?SDL_ConvertAudio, 156 | <<(FromAS#audiospec.format):16, 157 | (FromAS#audiospec.channels):8, 158 | (FromAS#audiospec.freq):32, 159 | (ToAS#audiospec.format):16, 160 | (ToAS#audiospec.channels):8, 161 | (ToAS#audiospec.freq):32, 162 | Ptr:?_PTR, 163 | Size:32>>), 164 | case Res of 165 | <> when NBufferPtr /= 0 -> 166 | #audiop{ptr=NBufferPtr,size=NBufferLen}; 167 | _ -> 168 | erlang:error({error, Res}) 169 | end. 170 | -------------------------------------------------------------------------------- /include/sdl_events.hrl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_events.hrl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : Event definitions 12 | %%% Created : 7 Jul 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | 16 | -define(SDL_QUERY, -1). %% Arg to eventState function 17 | -define(SDL_IGNORE, 0). 18 | -define(SDL_ENABLE, 1). 19 | 20 | -define(SDL_ADDEVENT, 0). %% Arg to peepEvents function 21 | -define(SDL_PEEKEVENT, 1). 22 | -define(SDL_GETEVENT, 2). 23 | 24 | -define(SDL_PRESSED, 1). 25 | -define(SDL_RELEASED, 0). 26 | 27 | -define(SDL_ALL_HOTKEYS, 16#FFFFFFFF). 28 | 29 | %% Events (are defined by the following records) 30 | -record(active, %% SDL_ActiveEvent 31 | {gain, %% Whether given states were gained or lost (1/0) 32 | state}). %% A mask of the focus states 33 | 34 | -record(keyboard, %% SDL_KeyboardEvent 35 | {which, %% The keyboard device index 36 | state, %% SDL_PRESSED or SDL_RELEASED 37 | scancode, %% hardware specific scancode 38 | sym, %% SDL virtual keysym see sdl_keyboard.hrl 39 | mod, %% current key modifiers see sdl_keyboard.hrl 40 | unicode}). %% translated character 41 | 42 | -record(mousemotion,%% SDL_MouseMotionEvent 43 | {which, %% The mouse device index 44 | state, %% The current button state 45 | mod=0, %% Current key modifiers 46 | x, y, %% The X/Y coordinates of the mouse 47 | xrel, %% The relative motion in the X direction 48 | yrel}). %% The relative motion in the Y direction 49 | 50 | -record(mousebutton,%% SDL_MouseButtonEvent 51 | {which, %% The mouse device index 52 | button, %% The mouse button index 53 | state, %% SDL_PRESSED or SDL_RELEASED 54 | mod=0, %% Current key modifiers 55 | x, y}). %% The X/Y coordinates of the mouse at press time 56 | 57 | -record(joyaxis, %% SDL_JoyAxisEvent 58 | {which, %% the joystick device index 59 | axis, %% The joystick axis index 60 | value}). %% The axis value (range: -32768 to 32767) 61 | 62 | -record(joyball, %% SDL_JoyBallEvent 63 | {which, %% The joystick device index 64 | ball, %% The joystick trackball index 65 | xrel, %% The relative motion in the X direction 66 | yrel}). %% The relative motion in the Y direction 67 | 68 | -record(joyhat, %% SDL_JoyHatEvent 69 | {which, %% The joystick device index 70 | hat, %% The joystick hat index 71 | value}). %% The hat position value: 72 | %%% 8 1 2 73 | %%% 7 0 3 74 | %%% 6 5 4 75 | %%% Note that zero means the POV is centered. 76 | 77 | -record(joybutton, %% SDL_JoyButtonEvent 78 | {which, %% The joystick device index 79 | button, %% The joystick button index 80 | state}). %% SDL_PRESSED or SDL_RELEASED 81 | 82 | -record(resize, %%SDL_ResizeEvent 83 | {w, %% New width 84 | h}). %% New height 85 | 86 | -record(expose, %%SDL_ExposeEvent The "screen redraw" event 87 | {}). %% 88 | 89 | -record(quit, {}). %%SDL_QuitEvent 90 | 91 | %-record(userevent, %%SDL_USEREVENT 92 | % int code, User defined event code 93 | % void *data1, User defined data pointer 94 | % void *data2, User defined data pointer 95 | 96 | %-record(syswme, %%SDL_SysWMEvent 97 | % {msg}). 98 | 99 | %%% 100 | %% EVENT TYPES and their masks 101 | -define(SDL_NOEVENT, 0). %% No (new) event 102 | -define(SDL_ACTIVEEVENT,1). %% Application loses/gains visibility 103 | -define(SDL_ACTIVEEVENTMASK, (1 bsl ?SDL_ACTIVEEVENT)). 104 | -define(SDL_KEYDOWN, 2). %% Keys pressed 105 | -define(SDL_KEYDOWNMASK, (1 bsl ?SDL_KEYDOWN)). 106 | -define(SDL_KEYUP, 3). %% Keys released 107 | -define(SDL_KEYUPMASK, (1 bsl ?SDL_KEYUP)). 108 | -define(SDL_MOUSEMOTION,4). %% Mouse moved 109 | -define(SDL_MOUSEMOTIONMASK, (1 bsl ?SDL_MOUSEMOTION)). 110 | -define(SDL_MOUSEBUTTONDOWN,5).%% Mouse button pressed 111 | -define(SDL_MOUSEBUTTONDOWNMASK,(1 bsl ?SDL_MOUSEBUTTONDOWN)). 112 | -define(SDL_MOUSEBUTTONUP,6). %% Mouse button released 113 | -define(SDL_MOUSEBUTTONUPMASK, (1 bsl ?SDL_MOUSEBUTTONUP)). 114 | -define(SDL_JOYAXISMOTION,7). %% Joystick axis motion 115 | -define(SDL_JOYAXISMOTIONMASK, (1 bsl ?SDL_JOYAXISMOTION)). 116 | -define(SDL_JOYBALLMOTION,8). %% Joystick trackball motion 117 | -define(SDL_JOYBALLMOTIONMASK, (1 bsl ?SDL_JOYBALLMOTION)). 118 | -define(SDL_JOYHATMOTION,9). %% Joystick hat position change 119 | -define(SDL_JOYHATMOTIONMASK, (1 bsl ?SDL_JOYHATMOTION)). 120 | -define(SDL_JOYBUTTONDOWN,10). %% Joystick button pressed 121 | -define(SDL_JOYBUTTONDOWNMASK, (1 bsl ?SDL_JOYBUTTONDOWN)). 122 | -define(SDL_JOYBUTTONUP,11). %% Joystick button released 123 | -define(SDL_JOYBUTTONUPMASK, (1 bsl ?SDL_JOYBUTTONUP)). 124 | -define(SDL_QUIT,12). %% User-requested quit 125 | -define(SDL_QUITMASK, (1 bsl ?SDL_QUIT)). 126 | -define(SDL_SYSWMEVENT,13). %% System specific event 127 | -define(SDL_SYSWMEVENTMASK, (1 bsl ?SDL_SYSWMEVENT)). 128 | %%-define(SDL_EVENT_RESERVEDA, Reserved for future use.. 129 | %%-define(SDL_EVENT_RESERVEDB, Reserved for future use.. 130 | -define(SDL_VIDEORESIZE,16). %% User resized video mode 131 | -define(SDL_VIDEORESIZEMASK, (1 bsl ?SDL_VIDEORESIZE)). 132 | -define(SDL_VIDEOEXPOSE,17). %% User resized video mode 133 | -define(SDL_VIDEOEXPOSEMASK, (1 bsl ?SDL_VIDEOEXPOSE)). 134 | 135 | 136 | -define(SDL_MOUSEEVENTMASK, (?SDL_MOUSEBUTTONUPMASK bor 137 | ?SDL_MOUSEBUTTONDOWNMASK bor 138 | ?SDL_MOUSEMOTIONMASK)). 139 | 140 | -define(SDL_JOYEVENTMASK, (?SDL_JOYAXISMOTIONMASK bor 141 | ?SDL_JOYBALLMOTIONMASK bor 142 | ?SDL_JOYHATMOTIONMASK bor 143 | ?SDL_JOYBUTTONDOWNMASK bor 144 | ?SDL_JOYBUTTONUPMASK)). 145 | 146 | -define(SDL_KEYBOARDMASK, (?SDL_KEYDOWNMASK bor 147 | ?SDL_KEYUPMASK)). 148 | -define(SDL_MOUSEBUTTONMASK, (?SDL_MOUSEBUTTONDOWNMASK bor 149 | ?SDL_MOUSEBUTTONUPMASK)). 150 | -define(SDL_JOYBUTTONMASK, (?SDL_JOYBUTTONDOWNMASK bor 151 | ?SDL_JOYBUTTONUPMASK)). 152 | 153 | -define(SDL_ALLEVENTS, 16#FFFFFFFF). 154 | 155 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 156 | 157 | -------------------------------------------------------------------------------- /src/sdl_events.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% 3 | %% See the file "license.terms" for information on usage and redistribution 4 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | %% 6 | %% $Id$ 7 | %% 8 | %%%---------------------------------------------------------------------- 9 | %%% File : sdl_events.erl 10 | %%% Author : Dan Gudmundsson 11 | %%% Purpose : Provides the sdl_events API 12 | %%% Created : 7 Jul 2000 by Dan Gudmundsson 13 | %%%---------------------------------------------------------------------- 14 | 15 | -module(sdl_events). 16 | -include("esdl.hrl"). 17 | -include("sdl_events.hrl"). 18 | 19 | -export([eventState/2, 20 | peepEvents/0, 21 | peepEvents/2, 22 | peepEvents/3, 23 | pollEvent/0, 24 | pumpEvents/0, 25 | waitEvent/0]). 26 | 27 | -export([decode_events/1]). 28 | 29 | -import(sdl, [call/2,cast/2]). 30 | 31 | %%% Available Functions 32 | -define(SDL_PumpEvents, ?SDL_EVENTS_HRL + 1). 33 | -define(SDL_PeepEvents, ?SDL_PumpEvents +1). 34 | -define(SDL_PollEvent, ?SDL_PeepEvents +1). 35 | -define(SDL_WaitEvent, ?SDL_PollEvent +1). 36 | -define(SDL_EventState, ?SDL_WaitEvent +1). 37 | 38 | %%%%%%%%%%%%%%% GENERAL EVENT FUNCTIONS %%%%%%%%%%%%%%% 39 | 40 | %% Func: pumpEvents 41 | %% Args: none 42 | %% Returns: ok 43 | %% C-API func: void SDL_PumpEvents(void); 44 | pumpEvents() -> 45 | cast(?SDL_PumpEvents, []). 46 | 47 | %% Func: peepEvents/0 48 | %% Args: None 49 | %% Returns: {NumOfEvents, [Events]} 50 | %% C-API func: int SDL_PeepEvents(SDL_Event *events, int numevents, 51 | %% SDL_eventaction action, Uint32 mask) 52 | %% Desc: Get up to to 16 events of all types. 53 | peepEvents() -> 54 | peepEvents(16, ?SDL_GETEVENT, ?SDL_ALLEVENTS). 55 | 56 | 57 | %% Func: peepEvents/2 58 | %% Args: NumEvents (might be 0) 59 | %% Mask (32 bits event mask) 60 | %% Returns: {NumOfEvents, [Events]} 61 | %% C-API func: int SDL_PeepEvents(SDL_Event *events, int numevents, 62 | %% SDL_eventaction action, Uint32 mask) 63 | %% Desc: Exits if error (NumEvents < 256) 64 | peepEvents(NumEvents, Mask) when NumEvents < 256 -> 65 | peepEvents(NumEvents, ?SDL_GETEVENT, Mask). 66 | 67 | %% Func: peepEvents/2 68 | %% Args: NumEvents (might be 0) 69 | %% ?SDL_GETEVENT 70 | %% Mask (32 bits event mask) 71 | %% Returns: {NumOfEvents, [Events]} 72 | %% C-API func: int SDL_PeepEvents(SDL_Event *events, int numevents, 73 | %% SDL_eventaction action, Uint32 mask) 74 | %% Desc: Exits if error (NumEvents < 256) 75 | peepEvents(NumEvents, ?SDL_GETEVENT, Mask) when NumEvents < 256 -> 76 | call(?SDL_PeepEvents, <>), 77 | receive 78 | {'_esdl_result_', <<>>} -> 79 | []; 80 | {'_esdl_result_', Events} -> 81 | decode_events(Events, []) 82 | end. 83 | 84 | %% Func: pollEvent 85 | %% Args: none 86 | %% Returns: no_event | Event (one of the event records) 87 | %% C-API func: int SDL_PollEvent(SDL_Event *event); 88 | %% Desc: 89 | pollEvent() -> 90 | call(?SDL_PollEvent, []), 91 | receive 92 | {'_esdl_result_', <<>>} -> 93 | no_event; 94 | {'_esdl_result_', Events} -> 95 | hd(decode_events(Events, [])) 96 | end. 97 | 98 | %% Func: waitEvent 99 | %% Args: none 100 | %% Returns: Event (one of the event records) 101 | %% C-API func: int SDL_WaitEvent(SDL_Event *event); 102 | %% Desc: 103 | waitEvent() -> 104 | call(?SDL_WaitEvent, []), 105 | receive 106 | {'_esdl_result_', <<>>} -> 107 | []; 108 | {'_esdl_result_', Events} -> 109 | hd(decode_events(Events, [])) 110 | end. 111 | 112 | %% Func: eventState 113 | %% Args: EventType (see sdl_events.hrl), State (SDL_QUERY | SDL_IGNORE |SDL_ENABLE) 114 | %% Returns: State (?SDL_ENABLE | ?SDL_IGNORE) 115 | %% C-API func: Uint8 SDL_EventState(Uint8 type, int state); 116 | %% Desc: 117 | eventState(Type, State) -> 118 | <> = call(?SDL_EventState, <>), 119 | Res. 120 | 121 | %%%%%%%%%%%%%%% Internals %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 122 | 123 | decode_events(Bin) -> 124 | decode_events(Bin, []). 125 | 126 | decode_events(<<>>, Acc) -> 127 | lists:reverse(Acc); 128 | decode_events(<>, Acc) -> 129 | decode_events(Rest, [no_event | Acc]); 130 | decode_events(<>, Acc) -> 131 | Event = #active{gain = Gain, state = State}, 132 | decode_events(Rest, [Event | Acc]); 133 | decode_events(<>, Acc) -> 135 | Event = #keyboard{which=Which,state=State, 136 | scancode=Scancode,sym=Sym,mod=Mod,unicode=Unicode}, 137 | decode_events(Rest, [Event | Acc]); 138 | decode_events(<>, Acc) -> 140 | Event = #mousemotion{which = Which, state = State, 141 | mod = Mod, x = X, y = Y, xrel = Xrel, yrel = Yrel}, 142 | decode_events(Rest, [Event | Acc]); 143 | decode_events(<>, Acc) -> 146 | Event = #mousebutton{which = Which, button = Button, state = State, 147 | mod = Mod, x = X, y = Y}, 148 | decode_events(Rest, [Event | Acc]); 149 | decode_events(<>, Acc) -> 150 | Event = #joyaxis{which = Which, axis = Axis, value = Value}, 151 | decode_events(Rest, [Event | Acc]); 152 | decode_events(<>, Acc) -> 154 | Event = #joyball{which = Which, ball = Ball, xrel =Xrel, yrel=Yrel}, 155 | decode_events(Rest, [Event | Acc]); 156 | decode_events(<>,Acc) -> 157 | Event = #joyhat{which = Which, hat = Hat, value = Value}, 158 | decode_events(Rest, [Event | Acc]); 159 | decode_events(<>, Acc) -> 160 | Event = #joybutton{which = Which, button = Button, state = State}, 161 | decode_events(Rest, [Event | Acc]); 162 | decode_events(<>, Acc) -> 163 | Event = #joybutton{which = Which, button = Button, state = State}, 164 | decode_events(Rest, [Event | Acc]); 165 | decode_events(<>, Acc) -> 166 | Event = #quit{}, 167 | decode_events(Rest, [Event | Acc]); 168 | decode_events(<>, Acc) -> 169 | Event = #resize{w = W, h = H}, 170 | decode_events(Rest, [Event | Acc]); 171 | decode_events(<>, Acc) -> 172 | Event = #expose{}, 173 | decode_events(Rest, [Event | Acc]). 174 | -------------------------------------------------------------------------------- /woggle/c_src/woggle_driver.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | 9 | #ifdef _WIN32 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "woggle_win.h" 16 | #include "woggle_driver.h" 17 | #include "woggle_compat_if.h" 18 | #else 19 | #include 20 | #include 21 | #include 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "woggle_driver.h" 30 | 31 | #define TEMP_BINARY_SIZE 512 32 | 33 | static ErlDrvData wog_driver_start(ErlDrvPort port, char *buff); 34 | static void wog_driver_stop(ErlDrvData handle); 35 | static void wog_driver_finish(void); 36 | static int wog_driver_control(ErlDrvData handle, unsigned int command, 37 | char* buf, int count, char** res, int res_size); 38 | static void standard_outputv(ErlDrvData drv_data, ErlIOVec *ev); 39 | 40 | /* 41 | ** The driver struct 42 | */ 43 | static ErlDrvEntry wog_driver_entry = { 44 | NULL, /* F_PTR init, N/A */ 45 | wog_driver_start, /* L_PTR start, called when port is opened */ 46 | wog_driver_stop, /* F_PTR stop, called when port is closed */ 47 | NULL, /* F_PTR output, called when erlang has sent */ 48 | NULL, /* F_PTR ready_input, called when input descriptor 49 | ready */ 50 | NULL, /* F_PTR ready_output, called when output 51 | descriptor ready */ 52 | "woggle_driver", /* char *driver_name, the argument to open_port */ 53 | wog_driver_finish, /* F_PTR finish, called when unloaded */ 54 | NULL, /* void * that is not used (BC) */ 55 | wog_driver_control, /* F_PTR control, port_control callback */ 56 | NULL, /* F_PTR timeout, reserved */ 57 | standard_outputv, /* F_PTR outputv, reserved */ 58 | }; 59 | 60 | DRIVER_INIT(wog_driver) 61 | { 62 | return &wog_driver_entry; 63 | } 64 | 65 | static ErlDrvData wog_driver_start(ErlDrvPort port, char *buff) 66 | { 67 | sdl_data *data; 68 | 69 | data = malloc(sizeof(sdl_data)); 70 | 71 | if (data == NULL) { 72 | fprintf(stderr, " Couldn't alloc mem\r\n"); 73 | return(ERL_DRV_ERROR_GENERAL); /* ENOMEM */ 74 | } else { 75 | set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY); 76 | data->driver_data = port; 77 | data->op = 0; 78 | data->len = 0; 79 | data->buff = NULL; 80 | 81 | data->temp_bin = driver_alloc_binary(TEMP_BINARY_SIZE); 82 | 83 | data->next_bin = 0; 84 | #ifdef WIN32 85 | /* wgl stuff */ 86 | data->qh = NULL; 87 | memset(&(data->wd),0,sizeof(WogWindowData)); 88 | #endif 89 | data->save_x = data->save_y = -1; 90 | data->saved_event = NULL; 91 | init_fps(data); 92 | data->extensions_loaded = 0; 93 | } 94 | return (ErlDrvData) data; 95 | } 96 | 97 | static void 98 | wog_driver_stop(ErlDrvData handle) 99 | { 100 | sdl_data *sd = ((sdl_data *)handle); 101 | 102 | if (sd->saved_event != NULL) { 103 | wog_free_event_message(sd->saved_event); 104 | } 105 | wog_close_window(&(sd->wd)); 106 | #ifdef HARDDEBUG 107 | FreeConsole(); 108 | #endif 109 | free(sd->fun_tab); 110 | free(sd->str_tab); 111 | 112 | free(handle); 113 | } 114 | 115 | static void 116 | wog_driver_finish(void) 117 | { 118 | } 119 | 120 | static int 121 | wog_driver_control(ErlDrvData handle, unsigned op, 122 | char* buf, int count, char** res, int res_size) 123 | { 124 | sdl_data* sd = (sdl_data *) handle; 125 | sdl_fun func; 126 | 127 | sd->buff = NULL; 128 | sd->len = 0; 129 | sd->op = op; 130 | func = sd->fun_tab[op]; 131 | func(sd, count, buf); 132 | (*res) = sd->buff; 133 | return sd->len; 134 | } 135 | 136 | static int 137 | wog_driver_debug_control(ErlDrvData handle, unsigned op, 138 | char* buf, int count, char** res, int res_size) 139 | { 140 | sdl_data* sd = (sdl_data *) handle; 141 | sdl_fun func; 142 | int len; 143 | 144 | sd->buff = NULL; 145 | sd->len = 0; 146 | sd->op = op; 147 | fprintf(stderr, "Command:%d:%s: ", op, sd->str_tab[op]); 148 | func = sd->fun_tab[op]; 149 | 150 | func(sd, count, buf); 151 | if ((len = sd->len) >= 0) { 152 | fprintf(stderr, "ok\r\n"); 153 | (*res) = sd->buff; 154 | return len; 155 | } else { 156 | fprintf(stderr, "error\r\n"); 157 | *res = 0; 158 | return -1; 159 | } 160 | } 161 | 162 | void sdl_send(sdl_data *sd, int len) 163 | { 164 | if (sd->buff == NULL) { 165 | fprintf(stderr, "EWOG INTERNAL ERROR: sdl_send in %s sent NULL buffer: %d\r\n", 166 | sd->str_tab[sd->op], len); 167 | abort(); 168 | } 169 | if (len > sd->len) { 170 | fprintf(stderr, "EWOG INTERNAL ERROR: sdl_send in %s allocated %d sent %d\r\n", 171 | sd->str_tab[sd->op], sd->len, len); 172 | abort(); 173 | } 174 | 175 | /* Workaround that driver_control doesn't check length */ 176 | ((ErlDrvBinary *) sd->buff)->orig_size = len; 177 | sd->len = len; 178 | } 179 | 180 | char* sdl_getbuff(sdl_data *sd, int size) 181 | { 182 | ErlDrvBinary* bin; 183 | sd->len = size; 184 | bin = driver_alloc_binary(size); 185 | sd->buff = bin; 186 | /* And return the pointer to the bytes */ 187 | return bin->orig_bytes; 188 | } 189 | 190 | #ifdef DANGEROUS 191 | char* sdl_get_temp_buff(sdl_data* sd, int size) 192 | { 193 | if (size > TEMP_BINARY_SIZE) { 194 | return sdl_getbuff(sd, size); 195 | } else { 196 | ErlDrvBinary* bin = (ErlDrvBinary *) sd->temp_bin; 197 | bin->refc++; 198 | sd->buff = bin; 199 | sd->len = size; 200 | return bin->orig_bytes; 201 | } 202 | } 203 | #else 204 | char* sdl_get_temp_buff(sdl_data* sd, int size) 205 | { 206 | return sdl_getbuff(sd, size); 207 | } 208 | #endif 209 | 210 | void 211 | sdl_util_debug(sdl_data *sd, int len, char* bp) 212 | { 213 | if (*bp) { 214 | wog_driver_entry.control = wog_driver_debug_control; 215 | } else { 216 | wog_driver_entry.control = wog_driver_control; 217 | } 218 | } 219 | 220 | static void 221 | standard_outputv(ErlDrvData drv_data, ErlIOVec* ev) 222 | { 223 | sdl_data* sd = (sdl_data *) drv_data; 224 | ErlDrvBinary* bin; 225 | 226 | if (ev->vsize == 2) { 227 | int i = sd->next_bin; 228 | 229 | sd->bin[i].base = ev->iov[1].iov_base; 230 | sd->bin[i].size = ev->iov[1].iov_len; 231 | bin = ev->binv[1]; 232 | bin->refc++; /* Otherwise it could get deallocated */ 233 | sd->bin[i].bin = bin; 234 | sd->next_bin++; 235 | } 236 | } 237 | 238 | void 239 | sdl_free_binaries(sdl_data* sd) 240 | { 241 | int i; 242 | 243 | for (i = sd->next_bin - 1; i >= 0; i--) { 244 | driver_free_binary(sd->bin[i].bin); 245 | } 246 | sd->next_bin = 0; 247 | } 248 | -------------------------------------------------------------------------------- /test/test_ttf.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2007 Klas Johansson 2 | %% See the file "license.terms" for information on usage and redistribution 3 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | %% 5 | %% $Id$ 6 | %% 7 | %%%---------------------------------------------------------------------- 8 | %%% File : test_ttf.erl 9 | %%% Author : Klas Johansson 10 | %%% Purpose : Testing; this code test various functions of the sdl_ttf API. 11 | %%% Created : 29 Jan 2007 by Klas Johansson 12 | %%%---------------------------------------------------------------------- 13 | 14 | -module(test_ttf). 15 | -author('klajo at users.sourceforge.net'). 16 | 17 | -compile(export_all). 18 | -include("sdl.hrl"). 19 | -include("sdl_events.hrl"). 20 | -include("sdl_video.hrl"). 21 | -include("sdl_keyboard.hrl"). 22 | -include("sdl_ttf.hrl"). 23 | 24 | go(FontFile, FontSize) -> 25 | go(FontFile, FontSize, []). 26 | go(FontFile, FontSize, Config) -> 27 | FontStyle = ?SDL_TTF_STYLE_NORMAL, 28 | FgColor = #sdl_color{r=0,g=153,b=255}, 29 | BgColor = #sdl_color{r=0,g=0,b=0}, 30 | 31 | TextStr = "The quick brown fox jumped over the lazy dog", 32 | Utf8Str = "The quick brown fox jumped over the lazy dog", 33 | UnicodeStr = 34 | "If you have a compatible font you'll see a Unicode fi-ligature here: " 35 | ++ [16#fb01], 36 | 37 | %% initialization 38 | sdl:init(?SDL_INIT_VIDEO), 39 | sdl_ttf:init(), 40 | sdl_util:debug(1), 41 | listen_to_keypress_events(), 42 | 43 | 1 = sdl_ttf:wasInit(), 44 | 45 | Flags = 46 | case lists:member(fullscreen, Config) of 47 | true -> 48 | ?SDL_ANYFORMAT bor ?SDL_FULLSCREEN bor ?SDL_RESIZABLE; 49 | _ -> 50 | ?SDL_ANYFORMAT bor ?SDL_RESIZABLE 51 | end, 52 | ScreenRef = sdl_video:setVideoMode(640, 480, 8, Flags), 53 | Screen = sdl_video:getSurface(ScreenRef), 54 | 55 | %% non-existing font 56 | {'EXIT', _} = (catch sdl_ttf:openFont("/tmp/no-such-font.ttf", 18)), 57 | [_|_] = sdl_ttf:getError(), 58 | 59 | %% the user-specified font 60 | F = case (catch sdl_ttf:openFont(FontFile, FontSize)) of 61 | {'EXIT', {openFont, returned_null_pointer}} -> 62 | exit({error, {failed_to_open_font, sdl_ttf:getError()}}); 63 | F0 -> 64 | F0 65 | end, 66 | 67 | %% run the getters (and a couple of setters) 68 | io:format("Vsn=~p~n", [sdl_ttf:linkedVersion()]), 69 | sdl_ttf:byteSwappedUNICODE(0), 70 | sdl_ttf:setFontStyle(F, FontStyle), 71 | io:format("getFontStyle=0x~.16b~n", [sdl_ttf:getFontStyle(F)]), 72 | io:format("fontHeight=~p~n", [sdl_ttf:fontHeight(F)]), 73 | io:format("fontAscent=~p~n", [sdl_ttf:fontAscent(F)]), 74 | io:format("fontDescent=~p~n", [sdl_ttf:fontDescent(F)]), 75 | io:format("fontLineSkip=~p~n", [sdl_ttf:fontLineSkip(F)]), 76 | io:format("fontFaces=~p~n", [sdl_ttf:fontFaces(F)]), 77 | io:format("fontFaceIsFixedWidth=~p~n",[sdl_ttf:fontFaceIsFixedWidth(F)]), 78 | io:format("fontFaceFamilyName=~p~n", [sdl_ttf:fontFaceFamilyName(F)]), 79 | io:format("fontFaceStyleName=~p~n", [sdl_ttf:fontFaceStyleName(F)]), 80 | io:format("glyphMetrics=~p~n", [sdl_ttf:glyphMetrics(F, $A)]), 81 | io:format("sizeText=~p~n", [sdl_ttf:sizeText(F, "abcd")]), 82 | io:format("sizeUTF8=~p~n", [sdl_ttf:sizeUTF8(F, "abcd")]), 83 | io:format("sizeUNICODE=~p~n", [sdl_ttf:sizeUNICODE(F, "abcd")]), 84 | 85 | %% draw some text 86 | print_at(Screen, F, TextStr, FgColor, BgColor, latin1, solid, 10, 10), 87 | print_at(Screen, F, Utf8Str, FgColor, BgColor, utf8, shaded, 20, 40), 88 | print_at(Screen, F, UnicodeStr, FgColor, BgColor, unicode, shaded, 30, 70), 89 | 90 | %% quit at keypress 91 | await_keypress(), 92 | sdl_ttf:closeFont(F), 93 | sdl:quit(). 94 | 95 | 96 | print_at(Screen, Font, TextStr, FgColor, BgColor, TextEnc, RenderMode, X, Y)-> 97 | TextRef = mk_text_surface(Font,TextStr,FgColor,BgColor,TextEnc,RenderMode), 98 | Text = sdl_video:getSurface(TextRef), 99 | blit_text(Screen, Text, BgColor, X, Y), 100 | %% save an image containing the text, just for fun 101 | sdl_video:saveBMP(Text, "/tmp/sdl-ttf-test.bmp"), 102 | %% set the text free :-) 103 | sdl_video:freeSurface(Text). 104 | 105 | 106 | mk_text_surface(Font, TextStr, FgColor, BgColor, TextEnc, RenderMode) -> 107 | TextRef = render_text(Font,TextStr,FgColor,BgColor,TextEnc,RenderMode), 108 | Text = sdl_video:getSurface(TextRef), 109 | PFmt = sdl_video:getPixelFormat(TextRef), 110 | case PFmt#sdl_pixelformat.palette of 111 | null -> 112 | io:format("No Palette found ~n"), 113 | ignore; 114 | _Palette -> 115 | <> = sdl_video:getPixels(Text, #sdl_rect{x = 0, y = 0, 116 | w = 1, h = 1}), 117 | io:format("Palette found set key ~p to transparent ~n", 118 | [Pixel]), 119 | true = sdl_video:setColorKey(Text, 120 | ?SDL_SRCCOLORKEY bor ?SDL_RLEACCEL, 121 | Pixel) 122 | end, 123 | case sdl_video:displayFormat(Text) of 124 | null -> 125 | sdl_video:freeSurface(Text), 126 | io:format("Failed to convert background~n"), 127 | exit({error, convert_failed}); 128 | ConvS -> 129 | sdl_video:freeSurface(Text), 130 | ConvS 131 | end. 132 | 133 | 134 | render_text(Font, Text, FgColor, _BgColor, latin1, solid) -> 135 | sdl_ttf:renderTextSolid(Font, Text, FgColor); 136 | render_text(Font, Text, FgColor, BgColor, latin1, shaded) -> 137 | sdl_ttf:renderTextShaded(Font, Text, FgColor, BgColor); 138 | render_text(Font, Text, FgColor, _BgColor, latin1, blended) -> 139 | sdl_ttf:renderTextBlended(Font, Text, FgColor); 140 | render_text(Font, Text, FgColor, _BgColor, utf8, solid) -> 141 | sdl_ttf:renderUTF8Solid(Font, Text, FgColor); 142 | render_text(Font, Text, FgColor, BgColor, utf8, shaded) -> 143 | sdl_ttf:renderUTF8Shaded(Font, Text, FgColor, BgColor); 144 | render_text(Font, Text, FgColor, _BgColor, utf8, blended) -> 145 | sdl_ttf:renderUTF8Blended(Font, Text, FgColor); 146 | render_text(Font, Text, FgColor, _BgColor, unicode, solid) -> 147 | sdl_ttf:renderUNICODESolid(Font, Text, FgColor); 148 | render_text(Font, Text, FgColor, BgColor, unicode, shaded) -> 149 | sdl_ttf:renderUNICODEShaded(Font, Text, FgColor, BgColor); 150 | render_text(Font, Text, FgColor, _BgColor, unicode, blended) -> 151 | sdl_ttf:renderUNICODEBlended(Font, Text, FgColor). 152 | 153 | 154 | blit_text(Screen, Text, BgColor, X, Y) -> 155 | Background = sdl_video:mapRGB(Screen, 156 | BgColor#sdl_color.r, 157 | BgColor#sdl_color.g, 158 | BgColor#sdl_color.b), 159 | Rect = #sdl_rect{x = X, 160 | y = Y, 161 | w = Text#sdl_surface.w, 162 | h = Text#sdl_surface.h}, 163 | true = sdl_video:fillRect(Screen, null, Background), 164 | {null, ClippedRect} = sdl_video:blitSurface(Text, null, Screen, Rect), 165 | sdl_video:updateRects(Screen, [ClippedRect]), 166 | sdl_video:getSurface(Text). 167 | 168 | 169 | listen_to_keypress_events() -> 170 | sdl_events:eventState(?SDL_ALLEVENTS ,?SDL_IGNORE), 171 | sdl_events:eventState(?SDL_KEYDOWN ,?SDL_ENABLE), 172 | sdl_events:eventState(?SDL_QUIT ,?SDL_ENABLE), 173 | ?printError(). 174 | 175 | await_keypress() -> 176 | sdl_events:waitEvent(). 177 | -------------------------------------------------------------------------------- /c_src/esdl_audio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | /* 9 | Map erl esdl_events calls to C sdl calls 10 | */ 11 | 12 | #include "esdl.h" 13 | #include 14 | #include 15 | 16 | 17 | struct { 18 | Uint8 *sound; /* Pointer to wave data */ 19 | Uint32 soundlen; /* Length of wave data */ 20 | int repeat; /* Play sample 'repeat' times */ 21 | int soundpos; /* Current play position */ 22 | 23 | Uint8 silence; 24 | } wave; 25 | 26 | void play_audio(sdl_data *sd, int len, char *buff) 27 | { 28 | char *bp, *start; 29 | int sendlen; 30 | void * sbuff; 31 | bp = buff; 32 | 33 | SDL_LockAudio(); 34 | 35 | POPGLPTR(sbuff, bp); 36 | wave.sound = sbuff; 37 | wave.soundlen = get32be(bp); 38 | wave.repeat = get32be(bp); 39 | wave.soundpos = 0; 40 | 41 | SDL_UnlockAudio(); 42 | bp = start = sdl_getbuff(sd, 0); 43 | sendlen = (int) (bp - start); 44 | sdl_send(sd, sendlen); 45 | } 46 | 47 | void myaudiomixer(void *mydata, Uint8 *stream, int len) 48 | { 49 | Uint8 *waveptr; 50 | int waveleft; 51 | 52 | if(wave.sound != NULL && wave.repeat != 0) 53 | { 54 | /* Set up the pointers */ 55 | waveptr = wave.sound + wave.soundpos; 56 | waveleft = wave.soundlen - wave.soundpos; 57 | /* fprintf(stderr, "ED1 0x%X %d 0x%X %d repeat %d\n\r", 58 | stream, len, waveptr, waveleft, wave.repeat); */ 59 | /* Go! */ 60 | while( waveleft < len ) { 61 | memcpy(stream, waveptr, waveleft); 62 | /* SDL_MixAudio(stream, waveptr, waveleft, SDL_MIX_MAXVOLUME); */ 63 | stream += waveleft; 64 | len -= waveleft; 65 | waveptr = wave.sound; 66 | waveleft = wave.soundlen; 67 | wave.soundpos = 0; 68 | if((wave.repeat -= 1) == 0) { 69 | memset(stream, wave.silence, len); 70 | break; 71 | } 72 | } 73 | if(wave.repeat != 0) { 74 | /* fprintf(stderr, "ED2 0x%X %d 0x%X %d repeat %d\n\r", 75 | stream, len, waveptr, waveleft, wave.repeat); */ 76 | memcpy(stream, waveptr, len); 77 | /* SDL_MixAudio(stream, waveptr, len, SDL_MIX_MAXVOLUME); */ 78 | wave.soundpos += len; 79 | } 80 | } 81 | else { 82 | memset(stream, wave.silence, len); 83 | } 84 | } 85 | 86 | /* API */ 87 | void es_audioDriverName(sdl_data *sd, int len, char *bp) 88 | { 89 | int sendlen = 0; 90 | 91 | bp = sdl_get_temp_buff(sd, 256); 92 | if (SDL_AudioDriverName(bp, 256) != NULL) { 93 | sendlen = (int) strlen(bp); 94 | } 95 | sdl_send(sd, sendlen); 96 | } 97 | 98 | void es_openAudio(sdl_data *sd, int len, char *buff) 99 | { 100 | int sendlen; 101 | char *bp, *start; 102 | int ff; 103 | SDL_AudioSpec desired, obtained, *obptr; 104 | bp = buff; 105 | ff = get8(bp); 106 | desired.freq = get32be(bp); 107 | desired.format = get16be(bp); 108 | desired.channels = get8(bp); 109 | desired.samples = get16be(bp); 110 | desired.padding = get16be(bp); 111 | desired.callback = myaudiomixer; 112 | 113 | /* Init the global data structures */ 114 | wave.sound = NULL; 115 | wave.soundpos = 0; 116 | wave.soundlen = 0; 117 | 118 | if(ff == 1) /* Force the requested format */ 119 | obptr = NULL; 120 | else 121 | obptr = &obtained; 122 | 123 | bp = start = sdl_getbuff(sd, 16); 124 | if( SDL_OpenAudio(&desired, obptr) < 0 ) { 125 | fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); 126 | } else { 127 | if(ff == 1) 128 | obptr = &desired; 129 | put32be(bp, obptr->freq); 130 | put16be(bp, obptr->format); 131 | put8(bp, obptr->channels); 132 | put8(bp, obptr->silence); 133 | put16be(bp, obptr->samples); 134 | put16be(bp, obptr->padding); 135 | put32be(bp, obptr->size); 136 | wave.silence = obptr->silence; 137 | } 138 | 139 | sendlen = (int) (bp - start); 140 | sdl_send(sd, sendlen); 141 | } 142 | 143 | void es_getAudioStatus(sdl_data *sd, int len, char *buff) 144 | { 145 | int sendlen; 146 | char *bp, *start; 147 | SDL_audiostatus s; 148 | 149 | s = SDL_GetAudioStatus(); 150 | start = bp = sdl_getbuff(sd, 1); 151 | put8(bp, s); 152 | sendlen = (int) (bp - start); 153 | sdl_send(sd, sendlen); 154 | } 155 | 156 | void es_pauseAudio(sdl_data *sd, int len, char *buff) 157 | { 158 | char *bp; 159 | int pause; 160 | bp = buff; 161 | pause = get8(bp); 162 | SDL_PauseAudio(pause); 163 | } 164 | 165 | void es_loadWAV(sdl_data *sd, int len, char *bp) 166 | { 167 | int sendlen; 168 | char *name, *start; 169 | SDL_AudioSpec obtained; 170 | Uint8 * ptr; 171 | Uint32 blen; 172 | 173 | name = bp; 174 | bp = start = sdl_get_temp_buff(sd, 28); 175 | if(NULL != SDL_LoadWAV(name, &obtained, &ptr, &blen)) { 176 | put32be(bp, obtained.freq); 177 | put16be(bp, obtained.format); 178 | put8(bp, obtained.channels); 179 | put8(bp, obtained.silence); 180 | put16be(bp, obtained.samples); 181 | put16be(bp, obtained.padding); 182 | put32be(bp, obtained.size); 183 | PUSHGLPTR(ptr, bp); 184 | put32be(bp, blen); 185 | } 186 | sendlen = (int) (bp - start); 187 | sdl_send(sd, sendlen); 188 | } 189 | 190 | void es_loadWAVRW(sdl_data *sd, int len, char *buff) 191 | { 192 | error(); 193 | } 194 | 195 | void es_freeWAV(sdl_data *sd, int len, char *buff) 196 | { 197 | char *bp; 198 | void *ptr; 199 | bp = buff; 200 | POPGLPTR(ptr, bp); 201 | SDL_FreeWAV(ptr); 202 | } 203 | 204 | void es_buildAudioCVT(sdl_data *sd, int len, char *buff) 205 | { 206 | error(); 207 | } 208 | 209 | void es_convertAudio(sdl_data *sd, int len, char *buff) 210 | { 211 | char *bp, *start; 212 | void *mptr; 213 | Uint16 oformat, nformat; 214 | Uint8 ochannels, nchannels; 215 | int ofreq, nfreq, osize, nsize; 216 | SDL_AudioCVT wav_cvt; 217 | int sendlen; 218 | 219 | bp = buff; 220 | oformat = get16be(bp); 221 | ochannels = get8(bp); 222 | ofreq = get32be(bp); 223 | nformat = get16be(bp); 224 | nchannels = get8(bp); 225 | nfreq = get32be(bp); 226 | POPGLPTR(mptr, bp); 227 | osize = get32be(bp); 228 | 229 | bp = start = sdl_getbuff(sd, 12); 230 | 231 | /* Build AudioCVT */ 232 | if(SDL_BuildAudioCVT(&wav_cvt,oformat, ochannels, ofreq, 233 | nformat, nchannels, nfreq) >= 0) { 234 | /* Setup for conversion */ 235 | nsize = osize*wav_cvt.len_mult; 236 | wav_cvt.buf=(Uint8 *)malloc(nsize); 237 | if(wav_cvt.buf != NULL) { 238 | wav_cvt.len=osize; 239 | memcpy(wav_cvt.buf, mptr, osize); 240 | if (SDL_ConvertAudio(&wav_cvt) >= 0) { 241 | PUSHGLPTR(wav_cvt.buf, bp); 242 | put32be(bp, nsize); 243 | } 244 | } 245 | } 246 | sendlen = (int) (bp - start); 247 | sdl_send(sd, sendlen); 248 | } 249 | void es_mixAudio(sdl_data *sd, int len, char *buff) 250 | { 251 | error(); 252 | } 253 | 254 | void es_lockAudio(sdl_data *sd, int len, char *buff) 255 | { 256 | error(); 257 | } 258 | 259 | void es_unlockAudio(sdl_data *sd, int len, char *buff) 260 | { 261 | error(); 262 | } 263 | 264 | void es_closeAudio(sdl_data *sd, int len, char *buff) 265 | { 266 | SDL_CloseAudio(); 267 | } 268 | -------------------------------------------------------------------------------- /woggle/c_src/woggle.h: -------------------------------------------------------------------------------- 1 | #ifndef _WOGGLE_H 2 | #define _WOGGLE_H 3 | 4 | #ifdef WIN32 5 | #include 6 | #include 7 | #define WOG_WIN_HANDLE HANDLE 8 | #else 9 | /* X11 */ 10 | #include 11 | #define WOG_WIN_HANDLE void* 12 | #endif 13 | 14 | /* Graphic/OpenGL attributes */ 15 | #define WOG_ATTR_RED_SIZE 1 16 | #define WOG_ATTR_GREEN_SIZE 2 17 | #define WOG_ATTR_BLUE_SIZE 3 18 | #define WOG_ATTR_DEPTH_SIZE 4 19 | #define WOG_ATTR_DOUBLEBUFFER 5 20 | #define WOG_ATTR_ALPHA_SIZE 6 21 | #define WOG_ATTR_BUFFER_SIZE 7 22 | 23 | /* Window system related attributes */ 24 | #define WOG_WMATTR_MAXIMIZED 1 25 | 26 | typedef enum { 27 | WogWindowCreated, 28 | WogMouseDown, 29 | WogMouseUp, 30 | WogMouseWheel, 31 | WogChar, 32 | WogKeyDown, 33 | WogKeyUp, 34 | WogMouseMove, 35 | WogMouseDelta, 36 | WogResize, 37 | WogActivate, 38 | WogClose, 39 | WogGoodbye, 40 | WogPaint 41 | } WogEventTag; 42 | 43 | typedef enum { 44 | WogListenMouseDown, 45 | WogListenMouseUp, 46 | WogListenMouseWheel, 47 | WogListenMouseMove, 48 | WogListenKeyUp, 49 | WogListenKeyDown, 50 | WogListenChar, 51 | WogListenResize, 52 | WogListenPaint, 53 | WogListenActivate, 54 | WogListenClose, 55 | WogListenAll, 56 | WogDeltaMouse, 57 | WogCloseWindow, 58 | WogGrabMouse 59 | } WogCommandTag; 60 | 61 | typedef enum { 62 | WogMouseLeft, 63 | WogMouseMiddle, 64 | WogMouseRight 65 | } WogMouseButton; 66 | 67 | #define WOG_MODIFIER_SHIFT 1 68 | #define WOG_MODIFIER_CTRL 2 69 | #define WOG_MODIFIER_ALT 4 70 | #define WOG_MODIFIER_MOUSE_LEFT 8 71 | #define WOG_MODIFIER_MOUSE_MIDDLE 16 72 | #define WOG_MODIFIER_MOUSE_RIGHT 32 73 | 74 | typedef unsigned int WogModifiers; 75 | 76 | typedef void * WogWindowToken; 77 | 78 | typedef struct { 79 | WogEventTag tag; 80 | WogWindowToken token; 81 | #ifdef WIN32 82 | HWND window; 83 | #endif 84 | } WogEvWindowCreated; 85 | 86 | typedef struct { 87 | WogEventTag tag; 88 | WogWindowToken token; 89 | WogMouseButton button; 90 | int x; 91 | int y; 92 | WogModifiers modifiers; 93 | } WogEvMouseUpDown; 94 | 95 | typedef struct { 96 | WogEventTag tag; 97 | WogWindowToken token; 98 | int delta; 99 | int x; 100 | int y; 101 | WogModifiers modifiers; 102 | } WogEvMouseWheel; 103 | 104 | typedef struct { 105 | WogEventTag tag; 106 | WogWindowToken token; 107 | int code; 108 | int scancode; 109 | int repeat; 110 | WogModifiers modifiers; /* Typical Alt */ 111 | } WogEvKeyUpDown; 112 | 113 | typedef struct { 114 | WogEventTag tag; 115 | WogWindowToken token; 116 | int code; 117 | int scancode; 118 | int ch; 119 | int repeat; 120 | WogModifiers modifiers; /* Typical Alt */ 121 | } WogEvChar; 122 | 123 | typedef struct { 124 | WogEventTag tag; 125 | WogWindowToken token; 126 | int x; 127 | int y; 128 | WogModifiers modifiers; 129 | } WogEvMouseMove; 130 | 131 | typedef struct { 132 | WogEventTag tag; 133 | WogWindowToken token; 134 | int x; 135 | int y; 136 | WogModifiers modifiers; 137 | } WogEvMouseDelta; 138 | 139 | typedef struct { 140 | WogEventTag tag; 141 | WogWindowToken token; 142 | int width; 143 | int height; 144 | } WogEvResize; 145 | 146 | typedef struct { 147 | WogEventTag tag; 148 | WogWindowToken token; 149 | int active; 150 | int iconic; 151 | } WogEvActivate; 152 | 153 | typedef struct { 154 | WogEventTag tag; 155 | WogWindowToken token; 156 | } WogEvClose; 157 | 158 | typedef struct { 159 | WogEventTag tag; 160 | WogWindowToken token; 161 | } WogEvGoodbye; 162 | 163 | typedef struct { 164 | WogEventTag tag; 165 | WogWindowToken token; 166 | int x1; 167 | int y1; 168 | int x2; 169 | int y2; 170 | } WogEvPaint; 171 | 172 | typedef struct { 173 | WogEventTag tag; 174 | WogWindowToken token; 175 | } WogEvAny; 176 | 177 | typedef union { 178 | WogEvAny any; 179 | WogEvWindowCreated window_created; 180 | WogEvMouseUpDown mouse_up_down; 181 | WogEvMouseWheel mouse_wheel; 182 | WogEvKeyUpDown key_up_down; 183 | WogEvChar a_char; 184 | WogEvMouseMove mouse_move; 185 | WogEvMouseDelta mouse_delta; 186 | WogEvResize resize; 187 | WogEvPaint paint; 188 | WogEvActivate activate; 189 | WogEvClose close; 190 | WogEvGoodbye goodbye; 191 | } WogEventMessage; 192 | 193 | typedef struct { 194 | WogCommandTag tag; 195 | int onoff; 196 | } WogCommandMessage; 197 | 198 | typedef struct wog_event_item { 199 | WogEventMessage msg; 200 | struct wog_event_item *next; 201 | } WogEventItem; 202 | 203 | typedef struct wog_command_item { 204 | WogCommandMessage cmd; 205 | struct wog_command_item *next; 206 | } WogCommandItem; 207 | 208 | typedef struct { 209 | WogEventItem *event_que_first; 210 | WogEventItem *event_que_last; 211 | #ifdef WIN32 212 | CRITICAL_SECTION event_crit; 213 | HANDLE message_in_event_que; /* Event Handle */ 214 | #endif 215 | } WogEventQue; 216 | 217 | typedef struct { 218 | WogCommandItem *command_que_first; 219 | WogCommandItem *command_que_last; 220 | #ifdef WIN32 221 | CRITICAL_SECTION command_crit; 222 | HANDLE message_in_command_que; /* Event Handle */ 223 | #endif 224 | } WogCommandQue; 225 | 226 | typedef struct { 227 | WogWindowToken token; 228 | WogCommandQue *comq; 229 | WogEventQue *ackq; 230 | unsigned thrdid; 231 | #ifdef WIN32 232 | HANDLE hThrd; 233 | HANDLE hWindow; 234 | HDC hdc; 235 | HGLRC hrc; 236 | #else /* X11 */ 237 | Display* display; 238 | int screen; 239 | Window window; 240 | XVisualInfo* vinfo; 241 | GLXContext ctx; 242 | Atom deleteAtom; 243 | #endif 244 | } WogWindowData; 245 | 246 | typedef struct { 247 | unsigned char cdepth; 248 | unsigned freq; 249 | unsigned short w; 250 | unsigned short h; 251 | } WogRes; 252 | 253 | #define WOG_COMMAND_QUE(PWogWindowData) \ 254 | ((PWogWindowData)->comq) 255 | #define WOG_ACK_QUE(PWogWindowData) \ 256 | ((PWogWindowData)->ackq) 257 | #define WOG_ACK_HANDLE(PWogWindowData) \ 258 | ((PWogWindowData)->ackq->message_in_event_que) 259 | 260 | /* The real event que is global and slightly opaque */ 261 | extern WogEventQue *wog_global_event_que; 262 | 263 | #define WOG_GLOBAL_EVENT_QUE() \ 264 | (NULL) 265 | #define WOG_GLOBAL_EVENT_HANDLE() \ 266 | (wog_global_event_que->message_in_event_que) 267 | 268 | void wog_init_instance(WOG_WIN_HANDLE instance); 269 | WogCommandMessage *wog_alloc_command_message(void); 270 | void wog_free_event_message(WogEventMessage *msg); 271 | void wog_free_command_message(WogCommandMessage *msg); 272 | WogEventMessage *wog_get_event_message(WogEventQue *eq); 273 | void wog_post_command_message(WogCommandQue *cq, WogCommandMessage *msg); 274 | WOG_WIN_HANDLE wog_create_window(WogWindowToken token, const char *title, 275 | int width, int height, int depth, 276 | WogWindowData *wd); 277 | void wog_close_window(WogWindowData *wd); 278 | void wog_swap_buffers(WogWindowData *wd); 279 | unsigned wog_get_tick(void); 280 | int wog_list_modes(WogRes **res); 281 | void wog_set_current_window(WogWindowData *wd); 282 | int wog_get_attr(const WogWindowData *wd, int item); 283 | int wog_get_wmattr(const WogWindowData *wd, int item); 284 | int wog_listen(const WogWindowData *wd, WogCommandTag tag, int onoff); 285 | 286 | #endif 287 | -------------------------------------------------------------------------------- /test/testjoy.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% See the file "license.terms" for information on usage and redistribution 3 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | %%%---------------------------------------------------------------------- 5 | %%% File : testjoy.erl 6 | %%% Author : 7 | %%% Purpose : Test joystick handling 8 | %%% Created : 20 Apr 2001 by 9 | %%%---------------------------------------------------------------------- 10 | 11 | -module(testjoy). 12 | -author('dgud@erix.ericsson.se'). 13 | 14 | -compile(export_all). 15 | %%-export([Function/Arity, ...]). 16 | -include_lib("wx/include/gl.hrl"). 17 | -include("sdl.hrl"). 18 | -include("sdl_video.hrl"). 19 | -include("sdl_keyboard.hrl"). 20 | -include("sdl_events.hrl"). 21 | -include("sdl_joystick.hrl"). 22 | 23 | -define(CUBE, {{ 10.0, 10.0, -10.0}, %1 24 | { 10.0, -10.0, -10.0}, %2 25 | {-10.0, -10.0, -10.0}, 26 | {-10.0, 10.0, -10.0}, %4 27 | {-10.0, 10.0, 10.0}, 28 | { 10.0, 10.0, 10.0}, %6 29 | { 10.0, -10.0, 10.0}, 30 | {-10.0, -10.0, 10.0}}). %8 31 | 32 | go() -> go([]). 33 | go(Flags) -> 34 | init(Flags), 35 | Nr = sdl_joystick:numJoysticks(), 36 | io:format("Found ~p joysticks ~n", [Nr]), 37 | if 38 | Nr > 0 -> ok; 39 | true -> exit(no_josticks_found) 40 | end, 41 | PrintName = fun(Index) -> 42 | io:format("Joystick ~p: ~s~n", 43 | [Index, sdl_joystick:name(Index)]) 44 | end, 45 | for(PrintName, Nr - 1), 46 | JoyI = case lists:keysearch(joystick, 1, Flags) of 47 | {value, {joystick, N}} when N < Nr, 48 | N >= 0 -> 49 | N; 50 | _ -> 51 | 0 52 | end, 53 | Joy = sdl_joystick:open(JoyI), 54 | %% sdl_util:debug(19), 55 | io:format("Testing joystick ~p: ~n", [JoyI]), 56 | io:format("Number of axis ~p: ~n", [sdl_joystick:numAxes(Joy)]), 57 | io:format("Number of balls ~p: ~n", [sdl_joystick:numBalls(Joy)]), 58 | io:format("Number of hats ~p: ~n", [sdl_joystick:numHats(Joy)]), 59 | io:format("Number of buttons ~p: ~n", [sdl_joystick:numButtons(Joy)]), 60 | init_video(Flags), 61 | Res = (catch test(Joy, {0.0, 0.0, 0.0}, [])), 62 | io:format("~p ~n", [Res]), 63 | sdl_joystick:close(Joy), 64 | sdl:quit(). 65 | 66 | test(Joy, Pos, Buttons) -> 67 | {_, Evs} = sdl_events:peepEvents(sune, 10, ?SDL_GETEVENT, 16#FFFF), 68 | {Npos = {NX, NY, NZ}, Nbuttons} = check_joy(Evs, Pos, Buttons), 69 | %% io:format("Pressed buttons ~p ~n", [Nbuttons]), 70 | gl:loadIdentity(), 71 | gl:clear(?GL_COLOR_BUFFER_BIT bor ?GL_DEPTH_BUFFER_BIT), 72 | drawButtons(Nbuttons), 73 | gl:loadIdentity(), 74 | gl:translatef(-5.0, -5.0, -50.0), 75 | draw_cube(), 76 | gl:color3f(0.0, 0.0, 1.0), 77 | gl:translatef(NX, NY, NZ), 78 | gl:'begin'(?GL_LINES), % Draw Cross 79 | gl:vertex3f(-1.0, 0.0, 0.0), 80 | gl:vertex3f(1.0, 0.0, 0.0), 81 | gl:vertex3f(0.0, -1.0, 0.0), 82 | gl:vertex3f(0.0, 1.0, 0.0), 83 | gl:'end'(), 84 | gl:swapBuffers(), 85 | case {gl:getError(), sdl:getError()} of 86 | {0, ""} -> 87 | ok; 88 | {GL, SDL} -> 89 | io:format("Errors Reported ~p ~s~n", [GL, SDL]) 90 | end, 91 | timer:sleep(5), 92 | test(Joy, Npos, Nbuttons). 93 | 94 | drawButtons([]) -> 95 | ok; 96 | drawButtons([H|R]) -> 97 | Size = 1.0, 98 | X1 = Size * H, 99 | X2 = X1 + Size, 100 | Y1 = 5.0, Y2 = Y1*2, 101 | gl:'begin'(?GL_QUADS), 102 | gl:vertex3f(X1 -10, Y1, -20.0), 103 | gl:vertex3f(X1 -10, Y2, -20.0), 104 | gl:vertex3f(X2 -10, Y2, -20.0), 105 | gl:vertex3f(X2 -10, Y1, -20.0), 106 | gl:'end'(), 107 | drawButtons(R). 108 | 109 | check_joy([], Pos, B) -> 110 | {Pos, B}; 111 | check_joy([Ev|R], Pos = {X, Y, Z}, B) -> 112 | case Ev of 113 | JA when is_record(JA, joyaxis) -> 114 | %% io:format("Got ~p ~n", [JA]), 115 | NewA = 10 / 32767 * JA#joyaxis.value, 116 | case JA#joyaxis.axis of 117 | 0 -> check_joy(R, {NewA, Y, Z},B); 118 | 1 -> check_joy(R, {X, -NewA, Z},B); 119 | 3 -> check_joy(R, {X, Y, -NewA},B); 120 | _ -> check_joy(R, Pos, B) %% Ignore 121 | end; 122 | JB when is_record(JB, joybutton) -> 123 | Butt = JB#joybutton.button, 124 | %% io:format("Button ~w changed ~n", [Butt]), 125 | case JB#joybutton.state of 126 | ?SDL_PRESSED -> 127 | check_joy(R, Pos, [Butt|B]); 128 | ?SDL_RELEASED -> 129 | check_joy(R, Pos, lists:delete(Butt, B)) 130 | end; 131 | #quit{} -> 132 | throw(quit); 133 | no_event -> 134 | check_joy(R, Pos, B); 135 | Quit when is_record(Quit, keyboard) -> 136 | if 137 | Quit#keyboard.sym == ?SDLK_ESCAPE -> 138 | throw(quit); 139 | Quit#keyboard.sym == ?SDLK_q -> 140 | throw(quit); 141 | true -> 142 | io:format("Got event ~p~n", [Quit]), 143 | check_joy(R, Pos, B) 144 | end; 145 | 146 | Event -> 147 | io:format("Got ~p ~n", [Event]), 148 | check_joy(R, Pos, B) 149 | end. 150 | 151 | draw_cube() -> 152 | gl:'begin'(?GL_LINES), 153 | gl:color3f(1.0, 0.0, 0.0), 154 | gl:vertex3fv(element(1, ?CUBE)), 155 | gl:vertex3fv(element(2, ?CUBE)), 156 | gl:vertex3fv(element(2, ?CUBE)), 157 | gl:vertex3fv(element(3, ?CUBE)), 158 | gl:vertex3fv(element(3, ?CUBE)), 159 | gl:vertex3fv(element(4, ?CUBE)), 160 | 161 | gl:vertex3fv(element(4, ?CUBE)), 162 | gl:vertex3fv(element(5, ?CUBE)), 163 | gl:vertex3fv(element(5, ?CUBE)), 164 | gl:vertex3fv(element(8, ?CUBE)), 165 | gl:vertex3fv(element(8, ?CUBE)), 166 | gl:vertex3fv(element(3, ?CUBE)), 167 | 168 | gl:vertex3fv(element(1, ?CUBE)), 169 | gl:vertex3fv(element(6, ?CUBE)), 170 | gl:vertex3fv(element(6, ?CUBE)), 171 | gl:vertex3fv(element(7, ?CUBE)), 172 | gl:vertex3fv(element(7, ?CUBE)), 173 | gl:vertex3fv(element(2, ?CUBE)), 174 | 175 | gl:vertex3fv(element(6, ?CUBE)), 176 | gl:vertex3fv(element(5, ?CUBE)), 177 | gl:vertex3fv(element(5, ?CUBE)), 178 | gl:vertex3fv(element(8, ?CUBE)), 179 | gl:vertex3fv(element(8, ?CUBE)), 180 | gl:vertex3fv(element(7, ?CUBE)), 181 | 182 | gl:vertex3fv(element(6, ?CUBE)), 183 | gl:vertex3fv(element(1, ?CUBE)), 184 | gl:vertex3fv(element(1, ?CUBE)), 185 | gl:vertex3fv(element(4, ?CUBE)), 186 | gl:vertex3fv(element(4, ?CUBE)), 187 | gl:vertex3fv(element(5, ?CUBE)), 188 | 189 | gl:vertex3fv(element(7, ?CUBE)), 190 | gl:vertex3fv(element(2, ?CUBE)), 191 | gl:vertex3fv(element(3, ?CUBE)), 192 | gl:vertex3fv(element(8, ?CUBE)), 193 | 194 | gl:'end'(). 195 | 196 | 197 | for(Fun, N) when N < 0 -> 198 | ok; 199 | for(Fun, N) -> 200 | Fun(N), 201 | for(Fun, N-1). 202 | 203 | init(Config) -> 204 | Wrapper = 205 | sdl:init(?SDL_INIT_JOYSTICK bor 206 | ?SDL_INIT_VIDEO bor 207 | ?SDL_INIT_ERLDRIVER), 208 | ok. 209 | 210 | init_video(Config) -> 211 | Flags = 212 | case lists:member(fullscreen, Config) of 213 | true -> 214 | ?SDL_OPENGL bor ?SDL_FULLSCREEN; 215 | _ -> 216 | ?SDL_OPENGL 217 | end, 218 | sdl_video:setVideoMode(640, 480, 16, Flags), 219 | gl:viewport(0,0,640,480), 220 | gl:matrixMode(?GL_PROJECTION), 221 | gl:loadIdentity(), 222 | glu:perspective(40.0, 640/480, 10.0, 80.0), 223 | gl:matrixMode(?GL_MODELVIEW), 224 | gl:loadIdentity(), 225 | gl:enable(?GL_DEPTH_TEST), 226 | gl:depthFunc(?GL_LESS), 227 | gl:clearColor(0.9,0.9,0.9,0.0). 228 | 229 | -------------------------------------------------------------------------------- /c_src/esdl_video.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001 Dan Gudmundsson 3 | * See the file "license.terms" for information on usage and redistribution 4 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 5 | * 6 | * $Id$ 7 | */ 8 | /* The video functions */ 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #define SDL_VideoDriverNameFunc (VIDEO_H + 1) 15 | void es_videoDriverName(sdl_data *, int, char *); 16 | #define SDL_GetVideoSurfaceFunc (SDL_VideoDriverNameFunc + 1) 17 | void es_getVideoSurface(sdl_data *, int len, char *buff); 18 | #define SDL_GetVideoInfoFunc (SDL_GetVideoSurfaceFunc + 1) 19 | void es_getVideoInfo(sdl_data *, int len, char*buff); 20 | #define SDL_VideoModeOKFunc (SDL_GetVideoInfoFunc + 1) 21 | void es_videoModeOK(sdl_data *, int len, char*buff); 22 | void es_videoModeOK2(ErlDrvPort, ErlDrvTermData, char *); 23 | #define SDL_ListModesFunc (SDL_VideoModeOKFunc + 1) 24 | void es_listModes(sdl_data *, int len, char *buff); 25 | #define SDL_SetVideoModeFunc (SDL_ListModesFunc + 1) 26 | void es_setVideoMode(sdl_data *, int len, char * buff); 27 | void es_setVideoMode2(ErlDrvPort, ErlDrvTermData, char * buff); 28 | #define SDL_UpdateRectFunc (SDL_SetVideoModeFunc + 1) 29 | /* Done from erlang using UpdateRectsFunc */ 30 | #define SDL_UpdateRectsFunc (SDL_UpdateRectFunc + 1) 31 | void es_updateRects(sdl_data *, int len, char * buff); 32 | #define SDL_FlipFunc (SDL_UpdateRectsFunc + 1) 33 | void es_flip(sdl_data *, int len, char *buff); 34 | #define SDL_SetColorsFunc (SDL_FlipFunc + 1) 35 | void es_setColors(sdl_data *, int, char *); 36 | #define SDL_MapRGBFunc (SDL_SetColorsFunc + 1) 37 | void es_mapRGB(sdl_data *, int len, char *buff); 38 | #define SDL_GetRGBFunc (SDL_MapRGBFunc + 1) 39 | void es_getRGB(sdl_data *, int len, char *buff); 40 | #define SDL_CreateRGBSurfaceFunc (SDL_GetRGBFunc + 1) 41 | void es_createRGBSurface(sdl_data *, int, char *); 42 | #define SDL_CreateRGBSurfaceFromFunc (SDL_CreateRGBSurfaceFunc + 1) 43 | void es_createRGBSurfaceFrom(sdl_data *, int, char *); 44 | #define SDL_FreeSurfaceFunc (SDL_CreateRGBSurfaceFromFunc + 1) 45 | void es_freeSurface(sdl_data *, int len, char * buff); 46 | 47 | #define SDL_MUSTLOCKFunc (0) /* Needed ? */ 48 | #define SDL_LockSurfaceFunc (SDL_FreeSurfaceFunc + 1) 49 | void es_lockSurface(sdl_data *, int len, char * buff); 50 | #define SDL_UnlockSurfaceFunc (SDL_LockSurfaceFunc + 1) 51 | void es_unlockSurface(sdl_data *, int len, char * buff); 52 | 53 | #define SDL_LoadBMP_RWFunc (SDL_UnlockSurfaceFunc + 1) 54 | #define SDL_LoadBMPFunc (SDL_LoadBMP_RWFunc + 1) 55 | void es_loadBMP(sdl_data *, int len, char * buff); 56 | 57 | #define SDL_SaveBMP_RWFunc (SDL_LoadBMPFunc + 1) 58 | #define SDL_SaveBMPFunc (SDL_SaveBMP_RWFunc + 1) 59 | void es_saveBMP(sdl_data *, int len, char * buff); 60 | 61 | #define SDL_SetColorKeyFunc (SDL_SaveBMPFunc + 1) 62 | void es_setColorKey(sdl_data *, int len, char * buff); 63 | 64 | #define SDL_SetAlphaFunc (SDL_SetColorKeyFunc + 1) 65 | void es_setAlpha(sdl_data *, int len, char *buff); 66 | #define SDL_SetClippingFunc (SDL_SetAlphaFunc + 1) 67 | /* void es_setClipping(sdl_data *, int len, char *buff); removed */ 68 | 69 | #define SDL_ConvertSurfaceFunc (SDL_SetClippingFunc + 1 ) /* SDL_internal */ 70 | #define SDL_BlitSurfaceFunc (SDL_ConvertSurfaceFunc + 1) 71 | void es_blitSurface(sdl_data *, int len, char * buff); 72 | #define SDL_UpperBlitFunc (SDL_BlitSurfaceFunc + 1) 73 | /* blitSurface is just a macro that does upperblit */ 74 | #define SDL_LowerBlitFunc (SDL_UpperBlitFunc + 1 ) /* SDL_semi private */ 75 | #define SDL_FillRectFunc (SDL_LowerBlitFunc + 1) 76 | void es_fillRect(sdl_data *, int len, char * buff); 77 | 78 | #define SDL_DisplayFormatFunc (SDL_FillRectFunc + 1) 79 | void es_displayFormat(sdl_data *, int len, char * buff); 80 | 81 | #define SDL_WM_SetCaptionFunc (SDL_DisplayFormatFunc +1) 82 | void es_wm_setCaption(sdl_data *, int len, char *buff); 83 | void es_wm_setCaption2(char *buff); 84 | #define SDL_WM_GetCaptionFunc (SDL_WM_SetCaptionFunc +1) 85 | void es_wm_getCaption(sdl_data *, int len, char *buff); 86 | #define SDL_WM_SetIconFunc (SDL_WM_GetCaptionFunc +1) 87 | void es_wm_setIcon(sdl_data *, int len, char *buff); 88 | #define SDL_WM_IconifyWindowFunc (SDL_WM_SetIconFunc +1) 89 | void es_wm_iconifyWindow(sdl_data *, int len, char *buff); 90 | #define SDL_WM_ToggleFullScreenFunc (SDL_WM_IconifyWindowFunc +1) 91 | void es_wm_toggleFullScreen(sdl_data *, int len, char *buff); 92 | void es_wm_toggleFullScreen2(ErlDrvPort, ErlDrvTermData, char *); 93 | #define SDL_WM_GrabInputFunc (SDL_WM_ToggleFullScreenFunc +1) 94 | void es_wm_grabInput(sdl_data *, int len, char *buff); 95 | #define SDL_WM_GetInfoFunc (SDL_WM_GrabInputFunc +1) 96 | void es_wm_getInfo(sdl_data *, int len, char *buff); 97 | void es_wm_getInfo2(ErlDrvPort, ErlDrvTermData, char *); 98 | 99 | #define SDL_GL_SetAttributeFunc (SDL_WM_GetInfoFunc + 1) 100 | void es_gl_setAttribute(sdl_data *, int, char *); 101 | void es_gl_setAttribute2(ErlDrvPort, ErlDrvTermData, char *); 102 | #define SDL_GL_GetAttributeFunc (SDL_GL_SetAttributeFunc + 1) 103 | void es_gl_getAttribute(sdl_data *, int, char *); 104 | void es_gl_getAttribute2(ErlDrvPort, ErlDrvTermData, char *); 105 | #define SDL_GL_SwapBuffersFunc (SDL_GL_GetAttributeFunc + 1) 106 | void es_gl_swapBuffers(sdl_data *, int, char *); 107 | 108 | /* Erl sdl special functions */ 109 | #define ESDL_getSurfaceFunc (SDL_GL_SwapBuffersFunc +1) 110 | void es_getSurface(sdl_data *, int len, char * buff); 111 | #define ESDL_getPaletteFunc (ESDL_getSurfaceFunc + 1) 112 | void es_getPalette(sdl_data *, int len, char * buff); 113 | #define ESDL_getPixelFormatFunc (ESDL_getPaletteFunc +1) 114 | void es_getPixelFormat(sdl_data *, int len, char * buff); 115 | #define ESDL_getPixelsFunc (ESDL_getPixelFormatFunc +1) 116 | void es_getPixels(sdl_data *, int len, char * buff); 117 | #define SDL_WM_IsMaximizedFunc (ESDL_getPixelsFunc +1) 118 | void es_wm_isMaximized(sdl_data *, int len, char * buff); 119 | /* SDL additions since SDL 1.1 */ 120 | #define SDL_SetGammaFunc (SDL_WM_IsMaximizedFunc +1) 121 | void es_setGamma(sdl_data *, int len, char * buff); 122 | #define SDL_SetGammaRampFunc (SDL_SetGammaFunc +1) 123 | void es_setGammaRamp(sdl_data *, int len, char * buff); 124 | #define SDL_GetGammaRampFunc (SDL_SetGammaRampFunc +1) 125 | void es_getGammaRamp(sdl_data *, int len, char * buff); 126 | 127 | #define SDL_MapRGBAFunc (SDL_GetGammaRampFunc + 1) 128 | void es_mapRGBA(sdl_data *, int len, char *buff); 129 | #define SDL_GetRGBAFunc (SDL_MapRGBAFunc + 1) 130 | void es_getRGBA(sdl_data *, int len, char *buff); 131 | #define SDL_GetClipRectFunc (SDL_GetRGBAFunc + 1) 132 | void es_getClipRect(sdl_data *, int len, char *buff); 133 | #define SDL_SetClipRectFunc (SDL_GetClipRectFunc + 1) 134 | void es_setClipRect(sdl_data *, int len, char *buff); 135 | #define SDL_DisplayFormatAlphaFunc (SDL_SetClipRectFunc + 1) 136 | void es_displayFormatAlpha(sdl_data *, int len, char * buff); 137 | 138 | #define SDL_WM_MaximizeFunc (SDL_DisplayFormatAlphaFunc + 1) 139 | void es_wm_maximize(sdl_data *, int len, char * buff); 140 | void es_wm_maximize2(ErlDrvPort, ErlDrvTermData, char *); 141 | #define SDL_WM_MacFileDialog (SDL_WM_MaximizeFunc + 1) 142 | void es_wm_mac_file_dialog(sdl_data *, int len, char * buff); 143 | void es_wm_mac_file_dialog2(ErlDrvPort, ErlDrvTermData, char *); 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | 150 | -------------------------------------------------------------------------------- /woggle/tools/cc.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Icky cl wrapper that does it's best to behave like a Unixish cc. 3 | # Made to work for Erlang builds and to make configure happy, not really 4 | # general I suspect. 5 | # set -x 6 | # Save the command line for debug outputs 7 | SAVE="$@" 8 | 9 | LD_SH=`echo $0 | sed 's,cc.sh$,ld.sh,g'` 10 | 11 | # Constants 12 | COMMON_CFLAGS="-nologo -D_WIN32_WINNT=0x400 -D__WIN32__ -DWIN32 -DWINDOWS -D_WIN32 -DNT" 13 | 14 | # Variables 15 | # The stdout and stderr for the compiler 16 | MSG_FILE=/tmp/cl.exe.$$.1 17 | ERR_FILE=/tmp/cl.exe.$$.2 18 | 19 | # "Booleans" determined during "command line parsing" 20 | # If the stdlib option is explicitly passed to this program 21 | MD_FORCED=false 22 | # If we're preprocession (only) i.e. -E 23 | PREPROCESSING=false 24 | # If this is supposed to be a debug build 25 | DEBUG_BUILD=false 26 | # If this is supposed to be an optimized build (there can only be one...) 27 | OPTIMIZED_BUILD=false 28 | # If we're linking or only compiling 29 | LINKING=true 30 | 31 | # This data is accumulated during command line "parsing" 32 | # The stdlibrary option, default multithreaded dynamic 33 | MD=-MD 34 | # Flags for debug compilation 35 | DEBUG_FLAGS="" 36 | # Flags for optimization 37 | OPTIMIZE_FLAGS="" 38 | # The specified output filename (if any), may be either object or exe. 39 | OUTFILE="" 40 | # Unspe3cified command line options for the compiler 41 | CMD="" 42 | # All the c source files, in unix style 43 | SOURCES="" 44 | # All the options to pass to the linker, kept in Unix style 45 | LINKCMD="" 46 | 47 | 48 | # Loop through the parameters and set the above variables accordingly 49 | # Also convert some cygwin filenames to "mixed style" dito (understood by the 50 | # compiler very well), except for anything passed to the linker, that script 51 | # handles those and the sources, which are also kept unixish for now 52 | 53 | while test -n "$1" ; do 54 | x="$1" 55 | case "$x" in 56 | -Wall) 57 | ;; 58 | -c) 59 | LINKING=false;; 60 | #CMD="$CMD -c";; 61 | -E) 62 | PREPROCESSING=true; 63 | LINKING=false;; # Obviously... 64 | #CMD="$CMD -E";; 65 | -O*) 66 | # Optimization hardcoded, needs to disable debugging too 67 | OPTIMIZE_FLAGS="-Ox"; 68 | DEBUG_FLAGS=""; 69 | DEBUG_BUILD=false; 70 | if [ $MD_FORCED = false ]; then 71 | MD=-MD; 72 | fi 73 | OPTIMIZED_BUILD=true;; 74 | -g|-ggdb) 75 | if [ $OPTIMIZED_BUILD = false ];then 76 | # Hardcoded windows debug flags 77 | DEBUG_FLAGS="-Z7"; 78 | if [ $MD_FORCED = false ]; then 79 | MD=-MDd; 80 | fi 81 | LINKCMD="$LINKCMD -g"; 82 | DEBUG_BUILD=true; 83 | fi;; 84 | # Allow forcing of stdlib 85 | -mt|-MT) 86 | MD="-MT"; 87 | MD_FORCED=true;; 88 | -md|-MD) 89 | MD="-MD"; 90 | MD_FORCED=true;; 91 | -mdd|-MDD|-MDd) 92 | MD="-MDd"; 93 | MD_FORCED=true;; 94 | -mtd|-MTD|-MTd) 95 | MD="-MTd"; 96 | MD_FORCED=true;; 97 | -o) 98 | shift; 99 | OUTFILE="$1";; 100 | -o*) 101 | y=`echo $x | sed 's,^-[Io]\(.*\),\1,g'`; 102 | OUTFILE="$y";; 103 | -I/*) 104 | y=`echo $x | sed 's,^-[Io]\(/.*\),\1,g'`; 105 | z=`echo $x | sed 's,^-\([Io]\)\(/.*\),\1,g'`; 106 | MPATH=`cygpath -m $y`; 107 | CMD="$CMD -$z\"$MPATH\"";; 108 | -I*) 109 | y=`echo $x | sed 's,",\\\",g'`; 110 | CMD="$CMD $y";; 111 | -D*) 112 | y=`echo $x | sed 's,",\\\",g'`; 113 | CMD="$CMD $y";; 114 | -l*) 115 | y=`echo $x | sed 's,^-l\(.*\),\1,g'`; 116 | LINKCMD="$LINKCMD $x";; 117 | /*.c) 118 | SOURCES="$SOURCES $x";; 119 | *.c) 120 | SOURCES="$SOURCES $x";; 121 | /*.o) 122 | LINKCMD="$LINKCMD $x";; 123 | *.o) 124 | LINKCMD="$LINKCMD $x";; 125 | *) 126 | # Try to quote uninterpreted options 127 | y=`echo $x | sed 's,",\\\",g'`; 128 | LINKCMD="$LINKCMD $y";; 129 | esac 130 | shift 131 | done 132 | 133 | #Return code from compiler, linker.sh and finally this script... 134 | RES=0 135 | 136 | # Accumulated object names 137 | ACCUM_OBJECTS="" 138 | 139 | # A temporary object file location 140 | TMPOBJDIR=/tmp/tmpobj$$ 141 | mkdir $TMPOBJDIR 142 | 143 | # Compile 144 | for x in $SOURCES; do 145 | # Compile each source 146 | if [ $LINKING = false ]; then 147 | # We should have an output defined, which is a directory 148 | # or an object file 149 | case $OUTFILE in 150 | /*.o) 151 | # Simple output, SOURCES should be one single 152 | n=`echo $SOURCES | wc -w`; 153 | if [ $n -gt 1 ]; then 154 | echo "cc.sh:Error, multiple sources, one object output."; 155 | exit 1; 156 | else 157 | output_filename=`cygpath -m $OUTFILE`; 158 | fi;; 159 | *.o) 160 | # Relative path needs no translation 161 | n=`echo $SOURCES | wc -w` 162 | if [ $n -gt 1 ]; then 163 | echo "cc.sh:Error, multiple sources, one object output." 164 | exit 1 165 | else 166 | output_filename=$OUTFILE 167 | fi;; 168 | /*) 169 | # Absolute directory 170 | o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'` 171 | output_filename=`cygpath -m $OUTFILE` 172 | output_filename="$output_filename/${o}";; 173 | *) 174 | # Relative_directory or empty string (.//x.o is valid) 175 | o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'` 176 | output_filename="./${OUTFILE}/${o}";; 177 | esac 178 | else 179 | # We are linking, which means we build objects in a temporary 180 | # directory and link from there. We should retain the basename 181 | # of each source to make examining the exe easier... 182 | o=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.o,'` 183 | output_filename=$TMPOBJDIR/$o 184 | ACCUM_OBJECTS="$ACCUM_OBJECTS $output_filename" 185 | fi 186 | # Now we know enough, lets try a compilation... 187 | MPATH=`cygpath -m $x` 188 | if [ $PREPROCESSING = true ]; then 189 | output_flag="-E" 190 | else 191 | output_flag="-c -Fo`cygpath -m ${output_filename}`" 192 | fi 193 | params="$COMMON_CFLAGS $MD $DEBUG_FLAGS $OPTIMIZE_FLAGS \ 194 | $CMD ${output_flag} $MPATH" 195 | if [ "X$CC_SH_DEBUG_LOG" != "X" ]; then 196 | echo cc.sh "$SAVE" >>$CC_SH_DEBUG_LOG 197 | echo cl.exe $params >>$CC_SH_DEBUG_LOG 198 | fi 199 | eval cl.exe $params >$MSG_FILE 2>$ERR_FILE 200 | RES=$? 201 | if test $PREPROCESSING = false; then 202 | cat $ERR_FILE >&2 203 | tail +2 $MSG_FILE 204 | else 205 | tail +2 $ERR_FILE >&2 206 | cat $MSG_FILE 207 | fi 208 | rm -f $ERR_FILE $MSG_FILE 209 | if [ $RES != 0 ]; then 210 | rm -rf $TMPOBJDIR 211 | exit $RES 212 | fi 213 | done 214 | 215 | # If we got here, we succeeded in compiling (if there were anything to compile) 216 | # The output filename should name an executable if we're linking 217 | if [ $LINKING = true ]; then 218 | case $OUTFILE in 219 | "") 220 | # Use the first source name to name the executable 221 | first_source="" 222 | for x in $SOURCES; do first_source=$x; break; done; 223 | if [ -n "$first_source" ]; then 224 | e=`echo $x | sed 's,.*/,,' | sed 's,\.c$,.exe,'`; 225 | out_spec="-o $e"; 226 | else 227 | out_spec=""; 228 | fi;; 229 | *) 230 | out_spec="-o $OUTFILE";; 231 | esac 232 | # Descide which standard library to link against 233 | case $MD in 234 | -MD) 235 | stdlib="-lMSVCRT";; 236 | -MDd) 237 | stdlib="-lMSVCRTD";; 238 | -MT) 239 | stdlib="-lLIBCMT";; 240 | -MTd) 241 | stdlib="-lLIBMTD";; 242 | esac 243 | # And finally call the next script to do the linking... 244 | params="$out_spec $LINKCMD $stdlib" 245 | eval $LD_SH $ACCUM_OBJECTS $params 246 | RES=$? 247 | fi 248 | rm -rf $TMPOBJDIR 249 | 250 | exit $RES 251 | -------------------------------------------------------------------------------- /woggle/test/compat_testgl.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% See the file "license.terms" for information on usage and redistribution 3 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | %% 5 | %% $Id$ 6 | %% 7 | %%%---------------------------------------------------------------------- 8 | %%% File : testgl.erl 9 | %%% Author : Dan Gudmundsson 10 | %%% Purpose : 11 | %%% Created : 11 Sep 2000 by Dan Gudmundsson 12 | %%%---------------------------------------------------------------------- 13 | 14 | -module(compat_testgl). 15 | -author('dgud@erix.ericsson.se'). 16 | -include("sdl.hrl"). 17 | -include("sdl_events.hrl"). 18 | -include("sdl_video.hrl"). 19 | -include("sdl_keyboard.hrl"). 20 | -include("gl.hrl"). 21 | 22 | 23 | -export([go/0, go/1]). 24 | 25 | go() -> 26 | go([]). 27 | go(Config) -> 28 | %% Init 29 | sdl:init(?SDL_INIT_VIDEO bor ?SDL_INIT_ERLDRIVER bor 30 | ?SDL_INIT_NOPARACHUTE), 31 | sdl_util:debug(1), 32 | Flags = 33 | case lists:member(fullscreen, Config) of 34 | true -> 35 | ?SDL_OPENGL bor ?SDL_FULLSCREEN; 36 | _ -> 37 | ?SDL_OPENGL bor ?SDL_RESIZABLE 38 | end, 39 | sdl_video:gl_setAttribute(?SDL_GL_DOUBLEBUFFER, 1), 40 | 41 | AvailableWindowedSzs = sdl_video:listModes(null, Flags bor ?SDL_FULLSCREEN), 42 | DriverName = sdl_video:videoDriverName(), 43 | 44 | io:format("Driver ~p ~n", [DriverName]), 45 | io:format("Available WindowSizes ~p ~n", [AvailableWindowedSzs]), 46 | 47 | case AvailableWindowedSzs of 48 | [{_, 0,0,W,H}|_] -> 49 | Res = [Test || Test <- [32,24,16,15], 50 | true == sdl_video:videoModeOK(W,H,Test,Flags)], 51 | io:format("A guess at max video res is ~px~p:~p ~n", [W,H, hd(Res)]); 52 | _ -> 53 | io:format("Can't guess max resolution~n", []) 54 | end, 55 | 56 | SR = sdl_video:setVideoMode(640, 480, 16, Flags), 57 | Rs= sdl_video:gl_getAttribute(?SDL_GL_RED_SIZE), 58 | Gs= sdl_video:gl_getAttribute(?SDL_GL_GREEN_SIZE), 59 | Bs= sdl_video:gl_getAttribute(?SDL_GL_BLUE_SIZE), 60 | Ds= sdl_video:gl_getAttribute(?SDL_GL_DEPTH_SIZE), 61 | Db= (1 == sdl_video:gl_getAttribute(?SDL_GL_DOUBLEBUFFER)), 62 | io:format("OpenGL attributes ~n"), 63 | io:format("Sizes in bits Red ~p Green ~p Blue ~p Depth ~p Doublebuffered ~p~n", 64 | [Rs, Gs, Bs, Ds, Db]), 65 | io:format("Vendor: ~s~n", [gl:getString(?GL_VENDOR)]), 66 | io:format("Renderer: ~s~n", [gl:getString(?GL_RENDERER)]), 67 | io:format("Version: ~s~n", [gl:getString(?GL_VERSION)]), 68 | io:format("GL AUX BUFFERS ~p~n", [gl:getIntegerv(?GL_AUX_BUFFERS)]), 69 | io:format("SDL Version ~p~n", [sdl_video:wm_getInfo()]), 70 | 71 | io:format("Extensions: ~s~n", [gl:getString(?GL_EXTENSIONS)]), 72 | io:format("Maximized: ~p~n", [sdl_video:wm_isMaximized()]), 73 | 74 | io:format("~p", [catch gl:getConvolutionParameterfv(16#8011, 16#801A)]), 75 | 76 | sdl_events:eventState(?SDL_ALLEVENTS ,?SDL_IGNORE), 77 | sdl_events:eventState(?SDL_KEYDOWN ,?SDL_ENABLE), 78 | sdl_events:eventState(?SDL_QUIT ,?SDL_ENABLE), 79 | sdl_events:eventState(?SDL_VIDEORESIZE, ?SDL_ENABLE), 80 | ?printError(), 81 | 82 | initWin(), 83 | sdl_util:debug(00), 84 | Cube = {{ 0.5, 0.5, -0.5}, 85 | { 0.5, -0.5, -0.5}, 86 | {-0.5, -0.5, -0.5}, 87 | {-0.5, 0.5, -0.5}, 88 | {-0.5, 0.5, 0.5}, 89 | { 0.5, 0.5, 0.5}, 90 | { 0.5, -0.5, 0.5}, 91 | {-0.5, -0.5, 0.5}}, 92 | Colors = {{ 1.0, 1.0, 0.0}, 93 | { 1.0, 0.0, 0.0}, 94 | { 0.0, 0.0, 0.0}, 95 | { 0.0, 1.0, 0.0}, 96 | { 0.0, 1.0, 1.0}, 97 | { 1.0, 1.0, 1.0}, 98 | { 1.0, 0.0, 1.0}, 99 | { 0.0, 0.0, 1.0}}, 100 | 101 | drawBox(Cube, Colors), 102 | sdl:quit(), 103 | ok. 104 | 105 | initWin() -> 106 | gl:viewport(0,0,640,480), 107 | gl:matrixMode(?GL_PROJECTION), 108 | gl:loadIdentity(), 109 | gl:ortho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0), 110 | gl:matrixMode(?GL_MODELVIEW), 111 | gl:loadIdentity(), 112 | gl:enable(?GL_DEPTH_TEST), 113 | gl:depthFunc(?GL_LESS), 114 | gl:clearColor(0.0,0.0,0.0,1.0). 115 | 116 | drawBox(Cube, Colors) -> 117 | %%timer:sleep(30), 118 | gl:clear(?GL_COLOR_BUFFER_BIT bor ?GL_DEPTH_BUFFER_BIT), 119 | gl:glBegin(?GL_QUADS), 120 | 121 | gl:color3fv(element(1, Colors)), 122 | gl:vertex3fv(element(1, Cube)), 123 | gl:color3fv(element(2, Colors)), 124 | gl:vertex3fv(element(2, Cube)), 125 | gl:color3fv(element(3, Colors)), 126 | gl:vertex3fv(element(3, Cube)), 127 | gl:color3fv(element(4, Colors)), 128 | gl:vertex3fv(element(4, Cube)), 129 | 130 | gl:color3fv(element(4, Colors)), 131 | gl:vertex3fv(element(4, Cube)), 132 | gl:color3fv(element(5, Colors)), 133 | gl:vertex3fv(element(5, Cube)), 134 | gl:color3fv(element(8, Colors)), 135 | gl:vertex3fv(element(8, Cube)), 136 | gl:color3fv(element(3, Colors)), 137 | gl:vertex3fv(element(3, Cube)), 138 | 139 | gl:color3fv(element(1, Colors)), 140 | gl:vertex3fv(element(1, Cube)), 141 | gl:color3fv(element(6, Colors)), 142 | gl:vertex3fv(element(6, Cube)), 143 | gl:color3fv(element(7, Colors)), 144 | gl:vertex3fv(element(7, Cube)), 145 | gl:color3fv(element(2, Colors)), 146 | gl:vertex3fv(element(2, Cube)), 147 | 148 | gl:color3fv(element(6, Colors)), 149 | gl:vertex3fv(element(6, Cube)), 150 | gl:color3fv(element(5, Colors)), 151 | gl:vertex3fv(element(5, Cube)), 152 | gl:color3fv(element(8, Colors)), 153 | gl:vertex3fv(element(8, Cube)), 154 | gl:color3fv(element(7, Colors)), 155 | gl:vertex3fv(element(7, Cube)), 156 | 157 | gl:color3fv(element(6, Colors)), 158 | gl:vertex3fv(element(6, Cube)), 159 | gl:color3fv(element(1, Colors)), 160 | gl:vertex3fv(element(1, Cube)), 161 | gl:color3fv(element(4, Colors)), 162 | gl:vertex3fv(element(4, Cube)), 163 | gl:color3fv(element(5, Colors)), 164 | gl:vertex3fv(element(5, Cube)), 165 | 166 | gl:color3fv(element(7, Colors)), 167 | gl:vertex3fv(element(7, Cube)), 168 | gl:color3fv(element(2, Colors)), 169 | gl:vertex3fv(element(2, Cube)), 170 | gl:color3fv(element(3, Colors)), 171 | gl:vertex3fv(element(3, Cube)), 172 | gl:color3fv(element(8, Colors)), 173 | gl:vertex3fv(element(8, Cube)), 174 | 175 | gl:glEnd(), 176 | 177 | gl:matrixMode(?GL_MODELVIEW), 178 | gl:rotatef(5.0, 1.0, 1.0, 1.0), 179 | case {gl:getError(), sdl:getError()} of 180 | {0, ""} -> 181 | ok; 182 | {GL, ""} -> 183 | io:format("Errors Reported ~p => ~n", [GL]), 184 | io:format("~s~n", [glu:errorString(GL)]); 185 | {GL, SDL} -> 186 | io:format("Errors Reported ~p ~s~n", [GL, SDL]) 187 | end, 188 | gl:swapBuffers(), 189 | case check_event() of 190 | ok -> 191 | timer:sleep(10), 192 | drawBox(Cube, Colors); 193 | quit -> 194 | ok 195 | end. 196 | 197 | check_event() -> 198 | case sdl_events:pollEvent() of 199 | #quit{} -> 200 | quit; 201 | #resize{} -> 202 | io:format("Maximized: ~p~n", [sdl_video:wm_isMaximized()]), 203 | ok; 204 | no_event -> 205 | ok; 206 | #keyboard{sym=$f} -> 207 | Surface = sdl_video:getVideoSurface(), 208 | io:format("~p\n", [sdl_video:wm_toggleFullScreen(Surface)]), 209 | ok; 210 | #keyboard{sym=?SDLK_q} -> 211 | quit; 212 | #keyboard{sym=?SDLK_ESCAPE} -> 213 | quit; 214 | Event -> 215 | io:format("Got event ~p~n", [Event]), 216 | ok 217 | end. 218 | 219 | -------------------------------------------------------------------------------- /test/testgl.erl: -------------------------------------------------------------------------------- 1 | %% Copyright (c) 2001 Dan Gudmundsson 2 | %% See the file "license.terms" for information on usage and redistribution 3 | %% of this file, and for a DISCLAIMER OF ALL WARRANTIES. 4 | %% 5 | %% $Id$ 6 | %% 7 | %%%---------------------------------------------------------------------- 8 | %%% File : testgl.erl 9 | %%% Author : Dan Gudmundsson 10 | %%% Purpose : 11 | %%% Created : 11 Sep 2000 by Dan Gudmundsson 12 | %%%---------------------------------------------------------------------- 13 | 14 | -module(testgl). 15 | -author('dgud@erix.ericsson.se'). 16 | -include_lib("wx/include/gl.hrl"). 17 | -include("sdl.hrl"). 18 | -include("sdl_events.hrl"). 19 | -include("sdl_video.hrl"). 20 | -include("sdl_keyboard.hrl"). 21 | 22 | -export([go/0, go/1]). 23 | 24 | go() -> 25 | go([]). 26 | go(Config) -> 27 | %% Init 28 | sdl:init(?SDL_INIT_VIDEO bor ?SDL_INIT_ERLDRIVER bor 29 | ?SDL_INIT_NOPARACHUTE), 30 | sdl_util:debug(2), 31 | Flags = 32 | case lists:member(fullscreen, Config) of 33 | true -> 34 | ?SDL_OPENGL bor ?SDL_FULLSCREEN; 35 | _ -> 36 | ?SDL_OPENGL bor ?SDL_RESIZABLE 37 | end, 38 | sdl_video:gl_setAttribute(?SDL_GL_DOUBLEBUFFER, 1), 39 | 40 | AvailableWindowedSzs = sdl_video:listModes(null, Flags bor ?SDL_FULLSCREEN), 41 | DriverName = sdl_video:videoDriverName(), 42 | 43 | io:format("Driver ~p ~n", [DriverName]), 44 | io:format("Available WindowSizes ~p ~n", [AvailableWindowedSzs]), 45 | 46 | case AvailableWindowedSzs of 47 | [{_, 0,0,W,H}|_] -> 48 | Res = [Test || Test <- [32,24,16,15], 49 | true == sdl_video:videoModeOK(W,H,Test,Flags)], 50 | io:format("A guess at max video res is ~px~p:~p ~n", [W,H, hd(Res)]); 51 | _ -> 52 | io:format("Can't guess max resolution~n", []) 53 | end, 54 | 55 | SR = sdl_video:setVideoMode(640, 480, 16, Flags), 56 | Rs= sdl_video:gl_getAttribute(?SDL_GL_RED_SIZE), 57 | Gs= sdl_video:gl_getAttribute(?SDL_GL_GREEN_SIZE), 58 | Bs= sdl_video:gl_getAttribute(?SDL_GL_BLUE_SIZE), 59 | Ds= sdl_video:gl_getAttribute(?SDL_GL_DEPTH_SIZE), 60 | Db= (1 == sdl_video:gl_getAttribute(?SDL_GL_DOUBLEBUFFER)), 61 | io:format("OpenGL attributes ~n"), 62 | io:format("Sizes in bits Red ~p Green ~p Blue ~p Depth ~p Doublebuffered ~p~n", 63 | [Rs, Gs, Bs, Ds, Db]), 64 | io:format("Vendor: ~s~n", [gl:getString(?GL_VENDOR)]), 65 | io:format("Renderer: ~s~n", [gl:getString(?GL_RENDERER)]), 66 | io:format("Version: ~s~n", [gl:getString(?GL_VERSION)]), 67 | io:format("GL AUX BUFFERS ~p~n", [hd(gl:getIntegerv(?GL_AUX_BUFFERS))]), 68 | io:format("SDL Version ~p~n", [sdl_video:wm_getInfo()]), 69 | 70 | io:format("Extensions: ~s~n", [gl:getString(?GL_EXTENSIONS)]), 71 | io:format("Maximized: ~p~n", [sdl_video:wm_isMaximized()]), 72 | 73 | io:format("~p~n~n", [catch gl:getConvolutionParameterfv(16#8011, 16#801A)]), 74 | 75 | sdl_events:eventState(?SDL_ALLEVENTS ,?SDL_IGNORE), 76 | sdl_events:eventState(?SDL_KEYDOWN ,?SDL_ENABLE), 77 | sdl_events:eventState(?SDL_QUIT ,?SDL_ENABLE), 78 | sdl_events:eventState(?SDL_VIDEORESIZE, ?SDL_ENABLE), 79 | ?printError(), 80 | 81 | initWin(), 82 | sdl_util:debug(00), 83 | Cube = {{ 0.5, 0.5, -0.5}, 84 | { 0.5, -0.5, -0.5}, 85 | {-0.5, -0.5, -0.5}, 86 | {-0.5, 0.5, -0.5}, 87 | {-0.5, 0.5, 0.5}, 88 | { 0.5, 0.5, 0.5}, 89 | { 0.5, -0.5, 0.5}, 90 | {-0.5, -0.5, 0.5}}, 91 | Colors = {{ 1.0, 1.0, 0.0}, 92 | { 1.0, 0.0, 0.0}, 93 | { 0.0, 0.0, 0.0}, 94 | { 0.0, 1.0, 0.0}, 95 | { 0.0, 1.0, 1.0}, 96 | { 1.0, 1.0, 1.0}, 97 | { 1.0, 0.0, 1.0}, 98 | { 0.0, 0.0, 1.0}}, 99 | 100 | drawBox(Cube, Colors), 101 | sdl:quit(), 102 | ok. 103 | 104 | initWin() -> 105 | gl:viewport(0,0,640,480), 106 | gl:matrixMode(?GL_PROJECTION), 107 | gl:loadIdentity(), 108 | gl:ortho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0), 109 | gl:matrixMode(?GL_MODELVIEW), 110 | gl:loadIdentity(), 111 | gl:enable(?GL_DEPTH_TEST), 112 | gl:depthFunc(?GL_LESS), 113 | gl:clearColor(0.0,0.0,0.0,1.0). 114 | 115 | drawBox(Cube, Colors) -> 116 | %%timer:sleep(30), 117 | gl:clear(?GL_COLOR_BUFFER_BIT bor ?GL_DEPTH_BUFFER_BIT), 118 | gl:'begin'(?GL_QUADS), 119 | 120 | gl:color3fv(element(1, Colors)), 121 | gl:vertex3fv(element(1, Cube)), 122 | gl:color3fv(element(2, Colors)), 123 | gl:vertex3fv(element(2, Cube)), 124 | gl:color3fv(element(3, Colors)), 125 | gl:vertex3fv(element(3, Cube)), 126 | gl:color3fv(element(4, Colors)), 127 | gl:vertex3fv(element(4, Cube)), 128 | 129 | gl:color3fv(element(4, Colors)), 130 | gl:vertex3fv(element(4, Cube)), 131 | gl:color3fv(element(5, Colors)), 132 | gl:vertex3fv(element(5, Cube)), 133 | gl:color3fv(element(8, Colors)), 134 | gl:vertex3fv(element(8, Cube)), 135 | gl:color3fv(element(3, Colors)), 136 | gl:vertex3fv(element(3, Cube)), 137 | 138 | gl:color3fv(element(1, Colors)), 139 | gl:vertex3fv(element(1, Cube)), 140 | gl:color3fv(element(6, Colors)), 141 | gl:vertex3fv(element(6, Cube)), 142 | gl:color3fv(element(7, Colors)), 143 | gl:vertex3fv(element(7, Cube)), 144 | gl:color3fv(element(2, Colors)), 145 | gl:vertex3fv(element(2, Cube)), 146 | 147 | gl:color3fv(element(6, Colors)), 148 | gl:vertex3fv(element(6, Cube)), 149 | gl:color3fv(element(5, Colors)), 150 | gl:vertex3fv(element(5, Cube)), 151 | gl:color3fv(element(8, Colors)), 152 | gl:vertex3fv(element(8, Cube)), 153 | gl:color3fv(element(7, Colors)), 154 | gl:vertex3fv(element(7, Cube)), 155 | 156 | gl:color3fv(element(6, Colors)), 157 | gl:vertex3fv(element(6, Cube)), 158 | gl:color3fv(element(1, Colors)), 159 | gl:vertex3fv(element(1, Cube)), 160 | gl:color3fv(element(4, Colors)), 161 | gl:vertex3fv(element(4, Cube)), 162 | gl:color3fv(element(5, Colors)), 163 | gl:vertex3fv(element(5, Cube)), 164 | 165 | gl:color3fv(element(7, Colors)), 166 | gl:vertex3fv(element(7, Cube)), 167 | gl:color3fv(element(2, Colors)), 168 | gl:vertex3fv(element(2, Cube)), 169 | gl:color3fv(element(3, Colors)), 170 | gl:vertex3fv(element(3, Cube)), 171 | gl:color3fv(element(8, Colors)), 172 | gl:vertex3fv(element(8, Cube)), 173 | 174 | gl:'end'(), 175 | 176 | gl:matrixMode(?GL_MODELVIEW), 177 | gl:rotatef(5.0, 1.0, 1.0, 1.0), 178 | case {gl:getError(), sdl:getError()} of 179 | {0, ""} -> 180 | ok; 181 | {GL, ""} -> 182 | io:format("Errors Reported ~p => ~n", [GL]), 183 | io:format("~s~n", [glu:errorString(GL)]); 184 | {GL, SDL} -> 185 | io:format("Errors Reported ~p ~s~n", [GL, SDL]) 186 | end, 187 | sdl_video:gl_swapBuffers(), 188 | case check_event() of 189 | ok -> 190 | timer:sleep(10), 191 | drawBox(Cube, Colors); 192 | quit -> 193 | ok 194 | end. 195 | 196 | check_event() -> 197 | case sdl_events:pollEvent() of 198 | #quit{} -> 199 | quit; 200 | #resize{} -> 201 | io:format("Maximized: ~p~n", [sdl_video:wm_isMaximized()]), 202 | ok; 203 | no_event -> 204 | ok; 205 | #keyboard{sym=$f} -> 206 | Surface = sdl_video:getVideoSurface(), 207 | io:format("~p\n", [sdl_video:wm_toggleFullScreen(Surface)]), 208 | ok; 209 | #keyboard{sym=?SDLK_q} -> 210 | quit; 211 | #keyboard{sym=?SDLK_ESCAPE} -> 212 | quit; 213 | Event -> 214 | io:format("Got event ~p~n", [Event]), 215 | ok 216 | end. 217 | 218 | --------------------------------------------------------------------------------