From ddb41086a294d20c28c04b9aa20900acf3624506 Mon Sep 17 00:00:00 2001 From: jsancho Date: Sat, 7 May 2011 11:52:22 +0000 Subject: [PATCH] --- src/Makefile.am | 2 +- src/gacela.c | 19 +++++ src/gacela_GL.c | 100 ++++++++++++++++++++++++ src/gacela_GL.h | 18 +++++ src/gacela_SDL.c | 195 +++++++++++++++++++++++++++++++++++++++-------- src/gacela_SDL.h | 17 +++++ 6 files changed, 317 insertions(+), 34 deletions(-) create mode 100644 src/gacela_GL.c create mode 100644 src/gacela_GL.h diff --git a/src/Makefile.am b/src/Makefile.am index 7411268..e050389 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ bin_PROGRAMS = gacela -gacela_SOURCES = gacela.c gacela_SDL.c +gacela_SOURCES = gacela.c gacela_SDL.c gacela_GL.c gacela_LDADD = -lSDL -lSDL_image -lSDL_mixer -lGL -lguile -lltdl -lgmp -lcrypt -lm -lltdl diff --git a/src/gacela.c b/src/gacela.c index 4517f48..c36d0a1 100644 --- a/src/gacela.c +++ b/src/gacela.c @@ -1,10 +1,29 @@ +/* Gacela, a GNU Guile extension for fast games development + Copyright (C) 2009 by Javier Sancho Fernandez + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #include #include "gacela_SDL.h" +#include "gacela_GL.h" static void* register_functions (void* data) { SDL_register_functions (NULL); + GL_register_functions (NULL); return NULL; } diff --git a/src/gacela_GL.c b/src/gacela_GL.c new file mode 100644 index 0000000..daf75f4 --- /dev/null +++ b/src/gacela_GL.c @@ -0,0 +1,100 @@ +/* Gacela, a GNU Guile extension for fast games development + Copyright (C) 2009 by Javier Sancho Fernandez + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include "gacela_GL.h" + +SCM +gacela_glBegin (SCM mode) +{ + glBegin (scm_to_int (mode)); + return SCM_UNSPECIFIED; +} + + +void* +GL_register_functions (void* data) +{ + // Data types + scm_c_define ("GL_UNSIGNED_BYTE", scm_from_int (GL_UNSIGNED_BYTE)); + + // Primitives + scm_c_define ("GL_POINTS", scm_from_int (GL_POINTS)); + scm_c_define ("GL_LINES", scm_from_int (GL_LINES)); + scm_c_define ("GL_LINE_LOOP", scm_from_int (GL_LINE_LOOP)); + scm_c_define ("GL_LINE_STRIP", scm_from_int (GL_LINE_STRIP)); + scm_c_define ("GL_TRIANGLES", scm_from_int (GL_TRIANGLES)); + scm_c_define ("GL_TRIANGLE_STRIP", scm_from_int (GL_TRIANGLE_STRIP)); + scm_c_define ("GL_TRIANGLE_FAN", scm_from_int (GL_TRIANGLE_FAN)); + scm_c_define ("GL_QUADS", scm_from_int (GL_QUADS)); + scm_c_define ("GL_QUAD_STRIP", scm_from_int (GL_QUAD_STRIP)); + scm_c_define ("GL_POLYGON", scm_from_int (GL_POLYGON)); + + // Matrix Mode + scm_c_define ("GL_MODELVIEW", scm_from_int (GL_MODELVIEW)); + scm_c_define ("GL_PROJECTION", scm_from_int (GL_PROJECTION)); + + // Depth buffer + scm_c_define ("GL_LEQUAL", scm_from_int (GL_LEQUAL)); + scm_c_define ("GL_DEPTH_TEST", scm_from_int (GL_DEPTH_TEST)); + + // Lighting + scm_c_define ("GL_LIGHTING", scm_from_int (GL_LIGHTING)); + scm_c_define ("GL_LIGHT1", scm_from_int (GL_LIGHT1)); + scm_c_define ("GL_AMBIENT", scm_from_int (GL_AMBIENT)); + scm_c_define ("GL_DIFFUSE", scm_from_int (GL_DIFFUSE)); + scm_c_define ("GL_POSITION", scm_from_int (GL_POSITION)); + scm_c_define ("GL_SMOOTH", scm_from_int (GL_SMOOTH)); + + // Blending + scm_c_define ("GL_BLEND", scm_from_int (GL_BLEND)); + scm_c_define ("GL_ONE", scm_from_int (GL_ONE)); + scm_c_define ("GL_SRC_ALPHA", scm_from_int (GL_SRC_ALPHA)); + + // Fog + scm_c_define ("GL_LINEAR", scm_from_int (GL_LINEAR)); + + // Buffers, Pixel Drawing/Reading + scm_c_define ("GL_RGB", scm_from_int (GL_RGB)); + scm_c_define ("GL_RGBA", scm_from_int (GL_RGBA)); + + // Hints + scm_c_define ("GL_PERSPECTIVE_CORRECTION_HINT", scm_from_int (GL_PERSPECTIVE_CORRECTION_HINT)); + scm_c_define ("GL_NICEST", scm_from_int (GL_NICEST)); + + // Texture mapping + scm_c_define ("GL_TEXTURE_2D", scm_from_int (GL_TEXTURE_2D)); + scm_c_define ("GL_TEXTURE_MAG_FILTER", scm_from_int (GL_TEXTURE_MAG_FILTER)); + scm_c_define ("GL_TEXTURE_MIN_FILTER", scm_from_int (GL_TEXTURE_MIN_FILTER)); + scm_c_define ("GL_LINEAR_MIPMAP_NEAREST", scm_from_int (GL_LINEAR_MIPMAP_NEAREST)); + scm_c_define ("GL_NEAREST", scm_from_int (GL_NEAREST)); + + // glPush/PopAttrib bits + scm_c_define ("GL_DEPTH_BUFFER_BIT", scm_from_int (GL_DEPTH_BUFFER_BIT)); + scm_c_define ("GL_COLOR_BUFFER_BIT", scm_from_int (GL_COLOR_BUFFER_BIT)); + + // OpenGL 1.2 + scm_c_define ("GL_BGR", scm_from_int (GL_BGR)); + scm_c_define ("GL_BGRA", scm_from_int (GL_BGRA)); + + + scm_c_define_gsubr ("glBegin", 1, 0, 0, gacela_glBegin); + + return NULL; +} diff --git a/src/gacela_GL.h b/src/gacela_GL.h new file mode 100644 index 0000000..634fc47 --- /dev/null +++ b/src/gacela_GL.h @@ -0,0 +1,18 @@ +/* Gacela, a GNU Guile extension for fast games development + Copyright (C) 2009 by Javier Sancho Fernandez + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +void* GL_register_functions (void* data); diff --git a/src/gacela_SDL.c b/src/gacela_SDL.c index 936308a..118825b 100644 --- a/src/gacela_SDL.c +++ b/src/gacela_SDL.c @@ -1,3 +1,20 @@ +/* Gacela, a GNU Guile extension for fast games development + Copyright (C) 2009 by Javier Sancho Fernandez + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + #include #include #include @@ -11,7 +28,7 @@ gacela_SDL_Init (SCM flags) } SCM -gacela_SDL_Quit () +gacela_SDL_Quit (void) { SDL_Quit (); return SCM_UNSPECIFIED; @@ -52,7 +69,7 @@ gacela_SDL_Delay (SCM ms) } SCM -gacela_SDL_GetTicks () +gacela_SDL_GetTicks (void) { return scm_from_int (SDL_GetTicks ()); } @@ -88,7 +105,7 @@ gacela_IMG_Load (SCM filename) } SCM -gacela_SDL_GetVideoInfo () +gacela_SDL_GetVideoInfo (void) { const SDL_VideoInfo *info; SCM vi; @@ -109,7 +126,7 @@ gacela_SDL_GL_SetAttribute (SCM attr, SCM value) } SCM -gacela_SDL_PollEvent () +gacela_SDL_PollEvent (void) { SDL_Event sdl_event; SCM event; @@ -129,44 +146,141 @@ gacela_SDL_PollEvent () return event; } +SCM +gacela_SDL_GL_SwapBuffers (void) +{ + SDL_GL_SwapBuffers (); + return SCM_UNSPECIFIED; +} -void* -SDL_register_functions (void* data) +SCM +gacela_SDL_EnableKeyRepeat (SCM delay, SCM interval) +{ + return scm_from_int (SDL_EnableKeyRepeat (scm_to_int (delay), scm_to_int (interval))); +} + +SCM +gacela_Mix_OpenAudio (SCM frequency, SCM format, SCM channels, SCM chunksize) { - scm_c_define ("SDL_INIT_TIMER", scm_from_int(SDL_INIT_TIMER)); - scm_c_define ("SDL_INIT_AUDIO", scm_from_int(SDL_INIT_AUDIO)); - scm_c_define ("SDL_INIT_VIDEO", scm_from_int(SDL_INIT_VIDEO)); - scm_c_define ("SDL_INIT_CDROM", scm_from_int(SDL_INIT_CDROM)); - scm_c_define ("SDL_INIT_JOYSTICK", scm_from_int(SDL_INIT_JOYSTICK)); - scm_c_define ("SDL_INIT_NOPARACHUTE", scm_from_int(SDL_INIT_NOPARACHUTE)); - scm_c_define ("SDL_INIT_EVENTTHREAD", scm_from_int(SDL_INIT_EVENTTHREAD)); - scm_c_define ("SDL_INIT_EVERYTHING", scm_from_int(SDL_INIT_EVERYTHING)); + return scm_from_int (Mix_OpenAudio (scm_to_int (frequency), scm_to_int (format), scm_to_int (channels), scm_to_int (chunksize))); +} - scm_c_define ("SDL_SWSURFACE", scm_from_int(SDL_SWSURFACE)); - scm_c_define ("SDL_HWSURFACE", scm_from_int(SDL_HWSURFACE)); - scm_c_define ("SDL_ASYNCBLIT", scm_from_int(SDL_ASYNCBLIT)); +SCM +gacela_Mix_LoadMUS (SCM file) +{ + return scm_from_int ((int)Mix_LoadMUS (scm_to_locale_string (file))); +} - scm_c_define ("SDL_ANYFORMAT", scm_from_int(SDL_ANYFORMAT)); - scm_c_define ("SDL_HWPALETTE", scm_from_int(SDL_HWPALETTE)); - scm_c_define ("SDL_DOUBLEBUF", scm_from_int(SDL_DOUBLEBUF)); - scm_c_define ("SDL_FULLSCREEN", scm_from_int(SDL_FULLSCREEN)); - scm_c_define ("SDL_OPENGL", scm_from_int(SDL_OPENGL)); - scm_c_define ("SDL_OPENGLBLIT", scm_from_int(SDL_OPENGLBLIT)); - scm_c_define ("SDL_RESIZABLE", scm_from_int(SDL_RESIZABLE)); - scm_c_define ("SDL_NOFRAME", scm_from_int(SDL_NOFRAME)); +SCM +gacela_Mix_LoadWAV (SCM file) +{ + return scm_from_int ((int)Mix_LoadWAV (scm_to_locale_string (file))); +} - scm_c_define ("SDL_HWACCEL", scm_from_int(SDL_HWACCEL)); - scm_c_define ("SDL_SRCCOLORKEY", scm_from_int(SDL_SRCCOLORKEY)); +SCM +gacela_Mix_PlayChannel (SCM channel, SCM chunk, SCM loops) +{ + return scm_from_int (Mix_PlayChannel (scm_to_int (channel), (Mix_Chunk *)scm_to_int (chunk), scm_to_int (loops))); +} - scm_c_define ("SDL_GL_DOUBLEBUFFER", scm_from_int(SDL_GL_DOUBLEBUFFER)); +SCM +gacela_Mix_PlayMusic (SCM music, SCM loops) +{ + return scm_from_int (Mix_PlayMusic ((Mix_Music *)scm_to_int (music), scm_to_int (loops))); +} - scm_c_define ("SDL_DEFAULT_REPEAT_DELAY", scm_from_int(SDL_DEFAULT_REPEAT_DELAY)); - scm_c_define ("SDL_DEFAULT_REPEAT_INTERVAL", scm_from_int(SDL_DEFAULT_REPEAT_INTERVAL)); +SCM +gacela_Mix_PlayingMusic (void) +{ + return scm_from_int (Mix_PlayingMusic ()); +} - scm_c_define ("SDL_LIL_ENDIAN", scm_from_int(SDL_LIL_ENDIAN)); - scm_c_define ("SDL_BIG_ENDIAN", scm_from_int(SDL_BIG_ENDIAN)); +SCM +gacela_Mix_PausedMusic (void) +{ + return scm_from_int (Mix_PausedMusic ()); +} - scm_c_define ("MIX_DEFAULT_FORMAT", scm_from_int(MIX_DEFAULT_FORMAT)); +SCM +gacela_Mix_PauseMusic (void) +{ + Mix_PauseMusic (); + return SCM_UNSPECIFIED; +} + +SCM +gacela_Mix_ResumeMusic (void) +{ + Mix_ResumeMusic (); + return SCM_UNSPECIFIED; +} + +SCM +gacela_Mix_HaltMusic (void) +{ + return scm_from_int (Mix_HaltMusic ()); +} + +SCM +gacela_Mix_FreeMusic (SCM music) +{ + Mix_FreeMusic ((Mix_Music *)scm_to_int (music)); + return SCM_UNSPECIFIED; +} + +SCM +gacela_Mix_FreeChunk (SCM chunk) +{ + Mix_FreeChunk ((Mix_Chunk *)scm_to_int (chunk)); + return SCM_UNSPECIFIED; +} + +SCM +gacela_Mix_CloseAudio (void) +{ + Mix_CloseAudio (); + return SCM_UNSPECIFIED; +} + + +void* +SDL_register_functions (void* data) +{ + scm_c_define ("SDL_INIT_TIMER", scm_from_int (SDL_INIT_TIMER)); + scm_c_define ("SDL_INIT_AUDIO", scm_from_int (SDL_INIT_AUDIO)); + scm_c_define ("SDL_INIT_VIDEO", scm_from_int (SDL_INIT_VIDEO)); + scm_c_define ("SDL_INIT_CDROM", scm_from_int (SDL_INIT_CDROM)); + scm_c_define ("SDL_INIT_JOYSTICK", scm_from_int (SDL_INIT_JOYSTICK)); + scm_c_define ("SDL_INIT_NOPARACHUTE", scm_from_int (SDL_INIT_NOPARACHUTE)); + scm_c_define ("SDL_INIT_EVENTTHREAD", scm_from_int (SDL_INIT_EVENTTHREAD)); + scm_c_define ("SDL_INIT_EVERYTHING", scm_from_int (SDL_INIT_EVERYTHING)); + + scm_c_define ("SDL_SWSURFACE", scm_from_int (SDL_SWSURFACE)); + scm_c_define ("SDL_HWSURFACE", scm_from_int (SDL_HWSURFACE)); + scm_c_define ("SDL_ASYNCBLIT", scm_from_int (SDL_ASYNCBLIT)); + + scm_c_define ("SDL_ANYFORMAT", scm_from_int (SDL_ANYFORMAT)); + scm_c_define ("SDL_HWPALETTE", scm_from_int (SDL_HWPALETTE)); + scm_c_define ("SDL_DOUBLEBUF", scm_from_int (SDL_DOUBLEBUF)); + scm_c_define ("SDL_FULLSCREEN", scm_from_int (SDL_FULLSCREEN)); + scm_c_define ("SDL_OPENGL", scm_from_int (SDL_OPENGL)); + scm_c_define ("SDL_OPENGLBLIT", scm_from_int (SDL_OPENGLBLIT)); + scm_c_define ("SDL_RESIZABLE", scm_from_int (SDL_RESIZABLE)); + scm_c_define ("SDL_NOFRAME", scm_from_int (SDL_NOFRAME)); + + scm_c_define ("SDL_HWACCEL", scm_from_int (SDL_HWACCEL)); + scm_c_define ("SDL_SRCCOLORKEY", scm_from_int (SDL_SRCCOLORKEY)); + + scm_c_define ("SDL_GL_DOUBLEBUFFER", scm_from_int (SDL_GL_DOUBLEBUFFER)); + + scm_c_define ("SDL_DEFAULT_REPEAT_DELAY", scm_from_int (SDL_DEFAULT_REPEAT_DELAY)); + scm_c_define ("SDL_DEFAULT_REPEAT_INTERVAL", scm_from_int (SDL_DEFAULT_REPEAT_INTERVAL)); + + scm_c_define ("SDL_LIL_ENDIAN", scm_from_int (SDL_LIL_ENDIAN)); + scm_c_define ("SDL_BIG_ENDIAN", scm_from_int (SDL_BIG_ENDIAN)); + scm_c_define ("SDL_BYTEORDER", scm_from_int (SDL_BYTEORDER)); + + scm_c_define ("MIX_DEFAULT_FORMAT", scm_from_int (MIX_DEFAULT_FORMAT)); scm_c_define_gsubr ("SDL_Init", 1, 0, 0, gacela_SDL_Init); scm_c_define_gsubr ("SDL_Quit", 0, 0, 0, gacela_SDL_Quit); @@ -184,6 +298,21 @@ SDL_register_functions (void* data) scm_c_define_gsubr ("SDL_GetVideoInfo", 0, 0, 0, gacela_SDL_GetVideoInfo); scm_c_define_gsubr ("SDL_GL_SetAttribute", 2, 0, 0, gacela_SDL_GL_SetAttribute); scm_c_define_gsubr ("SDL_PollEvent", 0, 0, 0, gacela_SDL_PollEvent); + scm_c_define_gsubr ("SDL_GL_SwapBuffers", 0, 0, 0, gacela_SDL_GL_SwapBuffers); + scm_c_define_gsubr ("SDL_EnableKeyRepeat", 2, 0, 0, gacela_SDL_EnableKeyRepeat); + scm_c_define_gsubr ("Mix_OpenAudio", 4, 0, 0, gacela_Mix_OpenAudio); + scm_c_define_gsubr ("Mix_LoadMUS", 1, 0, 0, gacela_Mix_LoadMUS); + scm_c_define_gsubr ("Mix_LoadWAV", 1, 0, 0, gacela_Mix_LoadWAV); + scm_c_define_gsubr ("Mix_PlayChannel", 3, 0, 0, gacela_Mix_PlayChannel); + scm_c_define_gsubr ("Mix_PlayMusic", 2, 0, 0, gacela_Mix_PlayMusic); + scm_c_define_gsubr ("Mix_PlayingMusic", 0, 0, 0, gacela_Mix_PlayingMusic); + scm_c_define_gsubr ("Mix_PausedMusic", 0, 0, 0, gacela_Mix_PausedMusic); + scm_c_define_gsubr ("Mix_PauseMusic", 0, 0, 0, gacela_Mix_PauseMusic); + scm_c_define_gsubr ("Mix_ResumeMusic", 0, 0, 0, gacela_Mix_ResumeMusic); + scm_c_define_gsubr ("Mix_HaltMusic", 0, 0, 0, gacela_Mix_HaltMusic); + scm_c_define_gsubr ("Mix_FreeMusic", 1, 0, 0, gacela_Mix_FreeMusic); + scm_c_define_gsubr ("Mix_FreeChunk", 1, 0, 0, gacela_Mix_FreeChunk); + scm_c_define_gsubr ("Mix_CloseAudio", 0, 0, 0, gacela_Mix_CloseAudio); return NULL; } diff --git a/src/gacela_SDL.h b/src/gacela_SDL.h index cf35f68..f3b0e67 100644 --- a/src/gacela_SDL.h +++ b/src/gacela_SDL.h @@ -1 +1,18 @@ +/* Gacela, a GNU Guile extension for fast games development + Copyright (C) 2009 by Javier Sancho Fernandez + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + void* SDL_register_functions (void* data); -- 2.39.5