[AD] Additional opengl functions |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: Allegro Developers <allegro-developers@xxxxxxxxxx>
- Subject: [AD] Additional opengl functions
- From: Edgar Reynaldo <edgarreynaldo@xxxxxxxxxx>
- Date: Mon, 24 Oct 2016 13:44:14 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=members-allegro-cc.20150623.gappssmtp.com; s=20150623; h=from:to:subject:message-id:date:user-agent:mime-version; bh=2ATpy+pMx+LDM1hBu6YM/hRbpd5NTUj9Nf4iX07Iu2M=; b=wnJE3p6Obm0cStnwMNWZKXI3CKpTjrQTBHNhPLHdwZxb/hLn/J/bUZj5N8+ZjrM4Pu XrXiw8I/qFNiG78LlUQmB3ldlRnJwFoSV3CeAtSROQuHUw3Nn4tF+a8mjLTPvkfQkXip fbXQ6lHXx0rauv57XvSPsAAkoK6MCQZ2uHgExWYx2pswG63Cdnpg9zofb4eS3UjE/TwS wRJwJLEAMCHsN4HCR6wJnezBRGr8HOsTfEh6Vube7VrwUH9Raf4sUma8q8nzfgOqGFBR 3XXQIAQRcLAbW7eW9va1S4PcxVbfZYp7NkgggOR++90z+GJbdMPBP0cjdTQsLjlUtnf1 0a1A==
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: */