From 492779760ff2cd0082d8221946c3e78b82215a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Mon, 1 Aug 2011 08:44:48 +0000 Subject: [PATCH] [GB.OPENGL] * BUG: Correctly specify the number of color components when using an Image in an OpenGL function: glTexImage1D, glTexImage2D, gluBuild2DMipmaps... git-svn-id: svn://localhost/gambas/trunk@3958 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.opengl/src/GLUtextureImage.c | 12 +++++++----- gb.opengl/src/GLtextureMapping.c | 4 ++-- gb.opengl/src/main.h | 3 +++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/gb.opengl/src/GLUtextureImage.c b/gb.opengl/src/GLUtextureImage.c index 58a208d0d..25339ddaa 100644 --- a/gb.opengl/src/GLUtextureImage.c +++ b/gb.opengl/src/GLUtextureImage.c @@ -34,7 +34,7 @@ BEGIN_METHOD(GLUBUILD1DMIPMAPS, GB_OBJECT Image) if (IMAGE_get(ARG(Image), &image, &format)) return; - status = gluBuild1DMipmaps(GL_TEXTURE_1D, 4, image->width, format, GL_UNSIGNED_BYTE, image->data); + status = gluBuild1DMipmaps(GL_TEXTURE_1D, IMAGE_get_ncolors(format), image->width, format, GL_UNSIGNED_BYTE, image->data); GB.ReturnInteger(status); @@ -42,11 +42,13 @@ END_METHOD BEGIN_METHOD(GLUBUILD2DMIPMAPS, GB_OBJECT Image) - GB_IMG *image = VARG(Image); - int status = 0; + GB_IMG *image; + int status; - status = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, image->width, image->height, IMAGE_get_pixel_format(image), GL_UNSIGNED_BYTE, - image->data); + if (IMAGE_get(ARG(Image), &image, &format)) + return; + + status = gluBuild2DMipmaps(GL_TEXTURE_2D, IMAGE_get_ncolors(format), image->width, image->height, format, GL_UNSIGNED_BYTE, image->data); GB.ReturnInteger(status); diff --git a/gb.opengl/src/GLtextureMapping.c b/gb.opengl/src/GLtextureMapping.c index 15727edb5..17b41b1d4 100644 --- a/gb.opengl/src/GLtextureMapping.c +++ b/gb.opengl/src/GLtextureMapping.c @@ -222,7 +222,7 @@ BEGIN_METHOD(GLTEXIMAGE1D, GB_OBJECT Image; GB_INTEGER Level; GB_INTEGER Border) if (IMAGE_get(ARG(Image), &image, &format)) return; - glTexImage1D(GL_TEXTURE_1D, VARGOPT(Level, 0), 4, image->width, VARGOPT(Border, 0), + glTexImage1D(GL_TEXTURE_1D, VARGOPT(Level, 0), IMAGE_get_ncolors(format), image->width, VARGOPT(Border, 0), format, GL_UNSIGNED_BYTE, image->data); END_METHOD @@ -235,7 +235,7 @@ BEGIN_METHOD(GLTEXIMAGE2D, GB_OBJECT Image; GB_INTEGER Level; GB_INTEGER Border) if (IMAGE_get(ARG(Image), &image, &format)) return; - glTexImage2D(GL_TEXTURE_2D, VARGOPT(Level, 0), 3, image->width, image->height, + glTexImage2D(GL_TEXTURE_2D, VARGOPT(Level, 0), IMAGE_get_ncolors(format), image->width, image->height, VARGOPT(Border, 0), format, GL_UNSIGNED_BYTE, image->data); END_METHOD diff --git a/gb.opengl/src/main.h b/gb.opengl/src/main.h index 68d7fa35e..aed35e8d9 100644 --- a/gb.opengl/src/main.h +++ b/gb.opengl/src/main.h @@ -40,5 +40,8 @@ extern IMAGE_INTERFACE IMAGE; int IMAGE_get_pixel_format(GB_IMG *image); bool IMAGE_get(GB_OBJECT *arg, GB_IMG **img, int *format); +#define IMAGE_get_ncolors(_format) (GB_IMAGE_FMT_IS_24_BITS(_format) ? 3 : 4) + + #endif