[AD] Additional opengl functions

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hey guys,

I've been working with Allegro and OpenGL a bit lately, and I found that the following additions to allegro/src/opengl/ogl_bitmap.c and allegro/include/allegro5/allegro_opengl.h might be nice. Would you consider them for addition, and let me know if they need to be modified, or if they are suitable as is? If they're added, I will make a patch for the docs to document them. The al_get_opengl_texture_positionf is to get the u,v coordinates in fractional form, and the al_get_opengl_texture_coordinates* functions would be to retrieve the top left and bottom right coordinates, in pixels, and in fractional parts of the parent texture.

My patch is attached.

Edgar



 include/allegro5/allegro_opengl.h | 34 ++++++++++++----------
 src/opengl/ogl_bitmap.c           | 59 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 14 deletions(-)

diff --git a/include/allegro5/allegro_opengl.h b/include/allegro5/allegro_opengl.h
index 0f86a67..86954eb 100644
--- a/include/allegro5/allegro_opengl.h
+++ b/include/allegro5/allegro_opengl.h
@@ -164,20 +164,26 @@ typedef enum ALLEGRO_OPENGL_VARIANT {
    ALLEGRO_OPENGL_ES
 } ALLEGRO_OPENGL_VARIANT;
 
-AL_FUNC(uint32_t,              al_get_opengl_version,            (void));
-AL_FUNC(bool,                  al_have_opengl_extension,         (const char *extension));
-AL_FUNC(void*,                 al_get_opengl_proc_address,       (const char *name));
-AL_FUNC(ALLEGRO_OGL_EXT_LIST*, al_get_opengl_extension_list,     (void));
-AL_FUNC(GLuint,                al_get_opengl_texture,            (ALLEGRO_BITMAP *bitmap));
-AL_FUNC(void,                  al_remove_opengl_fbo,             (ALLEGRO_BITMAP *bitmap));
-AL_FUNC(GLuint,                al_get_opengl_fbo,                (ALLEGRO_BITMAP *bitmap));
-AL_FUNC(bool,                  al_get_opengl_texture_size,       (ALLEGRO_BITMAP *bitmap,
-                                                                  int *w, int *h));
-AL_FUNC(void,                  al_get_opengl_texture_position,   (ALLEGRO_BITMAP *bitmap,
-                                                                  int *u, int *v));
-AL_FUNC(GLuint,                al_get_opengl_program_object,     (ALLEGRO_SHADER *shader));
-AL_FUNC(void,                  al_set_current_opengl_context,    (ALLEGRO_DISPLAY *display));
-AL_FUNC(int,                   al_get_opengl_variant,            (void));
+AL_FUNC(uint32_t,              al_get_opengl_version,             (void));
+AL_FUNC(bool,                  al_have_opengl_extension,          (const char *extension));
+AL_FUNC(void*,                 al_get_opengl_proc_address,        (const char *name));
+AL_FUNC(ALLEGRO_OGL_EXT_LIST*, al_get_opengl_extension_list,      (void));
+AL_FUNC(GLuint,                al_get_opengl_texture,             (ALLEGRO_BITMAP *bitmap));
+AL_FUNC(void,                  al_remove_opengl_fbo,              (ALLEGRO_BITMAP *bitmap));
+AL_FUNC(GLuint,                al_get_opengl_fbo,                 (ALLEGRO_BITMAP *bitmap));
+AL_FUNC(bool,                  al_get_opengl_texture_size,        (ALLEGRO_BITMAP *bitmap,
+                                                                   int *w, int *h));
+AL_FUNC(void,                  al_get_opengl_texture_position,    (ALLEGRO_BITMAP *bitmap,
+                                                                   int *u, int *v));
+AL_FUNC(void,                  al_get_opengl_texture_positionf,   (ALLEGRO_BITMAP* bitmap,
+                                                                   float* u , float* v));
+AL_FUNC(void,                  al_get_opengl_texture_coordinates, (ALLEGRO_BITMAP* bitmap,
+                                                                   int* lx , int* ty , int* rx , int* by));
+AL_FUNC(void,                  al_get_opengl_texture_coordinatesf,(ALLEGRO_BITMAP* bitmap,
+                                                                   float* lx , float* ty , float* rx , float* by));
+AL_FUNC(GLuint,                al_get_opengl_program_object,      (ALLEGRO_SHADER *shader));
+AL_FUNC(void,                  al_set_current_opengl_context,     (ALLEGRO_DISPLAY *display));
+AL_FUNC(int,                   al_get_opengl_variant,             (void));
 
 #ifdef __cplusplus
    }
diff --git a/src/opengl/ogl_bitmap.c b/src/opengl/ogl_bitmap.c
index cf76a1c..45da897 100644
--- a/src/opengl/ogl_bitmap.c
+++ b/src/opengl/ogl_bitmap.c
@@ -1224,4 +1224,63 @@ void al_get_opengl_texture_position(ALLEGRO_BITMAP *bitmap, int *u, int *v)
    *v = bitmap->yofs;
 }
 
+/* Function: al_get_opengl_texture_positionf
+ */
+void al_get_opengl_texture_positionf(ALLEGRO_BITMAP* bitmap , float* u , float* v)
+{
+   int iu = 0;
+   int iv = 0;
+   int tw = 0;
+   int th = 0;
+
+   ASSERT(bitmap);
+   ASSERT(u);
+   ASSERT(v);
+   
+   al_get_opengl_texture_position(bitmap , &iu , &iv);
+   al_get_opengl_texture_size(bitmap , &tw , &th);
+   *u = (float)iu/tw;
+   *v = (float)iv/th;
+}
+
+/* Function: al_get_opengl_texture_coordinates
+ */
+void al_get_opengl_texture_coordinates(ALLEGRO_BITMAP* bitmap , int* lx , int* ty , int* rx , int* by)
+{
+   ASSERT(bitmap);
+   ASSERT(lx);
+   ASSERT(ty);
+   ASSERT(rx);
+   ASSERT(by);
+   
+   al_get_opengl_texture_position(bitmap , lx , ty);
+   *rx = *lx + al_get_bitmap_width(bitmap);
+   *by = *ty + al_get_bitmap_height(bitmap);
+}
+
+/* Function: al_get_opengl_texture_coordinatesf
+ */
+void al_get_opengl_texture_coordinatesf(ALLEGRO_BITMAP* bitmap , float* lx , float* ty , float* rx , float* by)
+{
+   int ilx = 0;
+   int ity = 0;
+   int irx = 0;
+   int iby = 0;
+   int tw = 0;
+   int th = 0;
+   
+   ASSERT(bitmap);
+   ASSERT(lx);
+   ASSERT(ty);
+   ASSERT(rx);
+   ASSERT(by);
+   
+   al_get_opengl_texture_coordinates(bitmap , &ilx , &ity , &irx , &iby);
+   al_get_opengl_texture_size(bitmap , &tw , &th);
+   *lx = (float)ilx/tw;
+   *ty = (float)ity/th;
+   *rx = (float)irx/tw;
+   *by = (float)iby/th;
+}
+
 /* vim: set sts=3 sw=3 et: */


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/