]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela_GL.c
No more events engine, map-mobs will do all the work
[gacela.git] / src / gacela_GL.c
index c261fa2a1d9e4a8238da59da12f973061544ff20..541e4abea16e17d4e1ce7f1ec72e55a78abd46ad 100644 (file)
 #include <GL/glu.h>
 #include "gacela_GL.h"
 
+
+struct glTexture
+{
+  GLuint texture_id;
+  int width, height;
+};
+
+static scm_t_bits glTexture_tag;
+
+SCM
+make_glTexture (GLuint texture_id)
+{
+  SCM smob;
+  struct glTexture *glTexture;
+
+  glTexture = (struct glTexture *) scm_gc_malloc (sizeof (struct glTexture), "glTexture");
+
+  glTexture->texture_id = 0;
+
+  SCM_NEWSMOB (smob, glTexture_tag, glTexture);
+
+  glTexture->texture_id = texture_id;
+
+  return smob;
+}
+
+GLuint
+get_glTexture_id (SCM glTexture_smob)
+{
+  struct glTexture *glTexture;
+
+  scm_assert_smob_type (glTexture_tag, glTexture_smob);
+  glTexture = (struct glTexture *) SCM_SMOB_DATA (glTexture_smob);
+  return glTexture->texture_id;
+}
+
+SCM
+get_glTexture_width (SCM glTexture_smob)
+{
+  struct glTexture *glTexture;
+
+  scm_assert_smob_type (glTexture_tag, glTexture_smob);
+  glTexture = (struct glTexture *) SCM_SMOB_DATA (glTexture_smob);
+  return scm_from_int (glTexture->width);
+}
+
+SCM
+get_glTexture_height (SCM glTexture_smob)
+{
+  struct glTexture *glTexture;
+
+  scm_assert_smob_type (glTexture_tag, glTexture_smob);
+  glTexture = (struct glTexture *) SCM_SMOB_DATA (glTexture_smob);
+  return scm_from_int (glTexture->height);
+}
+
+SCM
+set_glTexture_size (SCM glTexture_smob, SCM width, SCM height)
+{
+  struct glTexture *glTexture;
+
+  scm_assert_smob_type (glTexture_tag, glTexture_smob);
+  glTexture = (struct glTexture *) SCM_SMOB_DATA (glTexture_smob);
+  glTexture->width = scm_to_int (width);
+  glTexture->height = scm_to_int (height);
+  return SCM_UNSPECIFIED;
+}
+
+size_t
+free_glTexture (SCM glTexture_smob)
+{
+  struct glTexture *glTexture = (struct glTexture *) SCM_SMOB_DATA (glTexture_smob);
+  GLuint text[1];
+
+  text[0] = glTexture->texture_id;
+  glDeleteTextures (1, &text[0]);
+  scm_gc_free (glTexture, sizeof (struct glTexture), "glTexture");
+
+  return 0;
+}
+
+
 SCM
 gacela_glBegin (SCM mode)
 {
@@ -165,7 +247,7 @@ gacela_glGenTextures (SCM n)
   glGenTextures (nint, &text[0]);
 
   for (i = nint - 1; i >= 0; i--) {
-    textures = scm_cons (scm_from_int (text[i]), textures);
+    textures = scm_cons (make_glTexture (text[i]), textures);
   }
 
   return textures;
@@ -189,7 +271,7 @@ gacela_glDeleteTextures (SCM n, SCM textures)
 SCM
 gacela_glBindTexture (SCM target, SCM texture)
 {
-  glBindTexture (scm_to_int (target), scm_to_int (texture));
+  glBindTexture (scm_to_int (target), get_glTexture_id (texture));
   return SCM_UNSPECIFIED;
 }
 
@@ -295,6 +377,12 @@ gacela_gluLookAt (SCM eyeX, SCM eyeY, SCM eyeZ, SCM centerX, SCM centerY, SCM ce
 void*
 GL_register_functions (void* data)
 {
+  glTexture_tag = scm_make_smob_type ("glTexture", sizeof (struct glTexture));
+  scm_set_smob_free (glTexture_tag, free_glTexture);
+  scm_c_define_gsubr ("texture-w", 1, 0, 0, get_glTexture_width);
+  scm_c_define_gsubr ("texture-h", 1, 0, 0, get_glTexture_height);
+  scm_c_define_gsubr ("set-texture-size!", 3, 0, 0, set_glTexture_size);
+
   // Data types
   scm_c_define ("GL_UNSIGNED_BYTE", scm_from_int (GL_UNSIGNED_BYTE));
 
@@ -329,6 +417,7 @@ GL_register_functions (void* data)
   // 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_ONE_MINUS_SRC_ALPHA", scm_from_int (GL_ONE_MINUS_SRC_ALPHA));
   scm_c_define ("GL_SRC_ALPHA", scm_from_int (GL_SRC_ALPHA));
 
   // Fog