From 53eb2e2a517bbab176a9d7c0f2c1f86fd65cb5b8 Mon Sep 17 00:00:00 2001 From: T_chan Date: Tue, 1 Feb 2022 07:25:54 +0000 Subject: [PATCH] Add gluBuild2DMipmaps() --- GL/framebuffer.c | 12 ++++++++++++ include/GL/glu.h | 5 +++++ samples/mipmap/main.c | 8 +++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/GL/framebuffer.c b/GL/framebuffer.c index 01bd65a..1a893c6 100644 --- a/GL/framebuffer.c +++ b/GL/framebuffer.c @@ -320,6 +320,18 @@ void APIENTRY glGenerateMipmapEXT(GLenum target) { assert(_glIsMipmapComplete(tex)); } +/* generate mipmaps for any image provided by the user and then pass them to OpenGL */ +GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, + GLenum format, GLenum type, const void *data){ + /* 2d texture, level of detail 0 (normal), 3 components (red, green, blue), + width & height of the image, border 0 (normal), rgb color data, + unsigned byte data, and finally the data itself. */ + glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); + + glGenerateMipmapEXT(GL_TEXTURE_2D); +} + GLenum APIENTRY glCheckFramebufferStatusEXT(GLenum target) { if(target != GL_FRAMEBUFFER_EXT) { _glKosThrowError(GL_INVALID_ENUM, __func__); diff --git a/include/GL/glu.h b/include/GL/glu.h index 0c8420c..87842ae 100644 --- a/include/GL/glu.h +++ b/include/GL/glu.h @@ -34,6 +34,11 @@ GLAPI void APIENTRY gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy, GLfloat upz); +/* generate mipmaps for any image provided by the user and then pass them to OpenGL */ +GLAPI GLint APIENTRY gluBuild2DMipmaps(GLenum target, GLint internalFormat, + GLsizei width, GLsizei height, + GLenum format, GLenum type, const void *data); + GLAPI const GLubyte* APIENTRY gluErrorString(GLenum error); __END_DECLS diff --git a/samples/mipmap/main.c b/samples/mipmap/main.c index 3f8a785..ba65d5f 100644 --- a/samples/mipmap/main.c +++ b/samples/mipmap/main.c @@ -47,11 +47,9 @@ void LoadGLTextures() { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); // scale linearly when image smalled than texture - // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, - // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself. - glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); - - glGenerateMipmapEXT(GL_TEXTURE_2D); + // 2d texture, 3 components (red, green, blue), x size from image, y size from image, + // rgb color data, unsigned byte data, and finally the data itself. + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image1->sizeX, image1->sizeY, GL_RGB, GL_UNSIGNED_BYTE, image1->data); free(image1); };