From 4ff98f34bbc3233f5eca61dfe07c2336c52918ce Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 27 Oct 2016 13:40:48 +0200 Subject: [PATCH] Function to set texture parameters -IN PROGRESS- --- src/rlgl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/rlgl.h | 11 +++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/rlgl.c b/src/rlgl.c index 806879586..0a7e35836 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -871,6 +871,48 @@ void rlDisableTexture(void) #endif } +// Set texture parameters +// TODO: Review this function to choose right filter/wrap value +void rlTextureParameters(unsigned int id, int param, int value) +{ +/* +// TextureWrapMode +#define GL_REPEAT 0x2901 +#define GL_CLAMP_TO_EDGE 0x812F + +// TextureMagFilter +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 + +// TextureMinFilter +#define GL_NEAREST 0x2600 +#define GL_LINEAR 0x2601 +#define GL_NEAREST_MIPMAP_NEAREST 0x2700 +#define GL_LINEAR_MIPMAP_NEAREST 0x2701 +#define GL_NEAREST_MIPMAP_LINEAR 0x2702 +#define GL_LINEAR_MIPMAP_LINEAR 0x2703 +*/ + + int glValue = 0; + + glBindTexture(GL_TEXTURE_2D, id); + + switch (value) + { + case FILTER_POINT: glValue = GL_NEAREST; break; + case FILTER_BILINEAR: glValue = GL_LINEAR; break; + case FILTER_TRILINEAR: glValue = GL_LINEAR; break; + //case WRAP_REPEAT: glValue = GL_REPEAT; break; + //case WRAP_CLAMP: glValue = GL_CLAMP_TO_EDGE; break; + //case WRAP_MIRROR: glValue = GL_NEAREST; break; + default: break; + } + + glTexParameteri(GL_TEXTURE_2D, param, glValue); + + glBindTexture(GL_TEXTURE_2D, 0); +} + // Enable rendering to texture (fbo) void rlEnableRenderTexture(unsigned int id) { diff --git a/src/rlgl.h b/src/rlgl.h index d5a39aaf7..b6679ef68 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -90,15 +90,21 @@ #define MAX_QUADS_BATCH 1024 // Be careful with text, every letter maps a quad #endif +// Texture parameters (equivalent to OpenGL defines) +#define RL_TEXTURE_MAG_FILTER 0x2800 +#define RL_TEXTURE_MIN_FILTER 0x2801 +#define RL_TEXTURE_WRAP_S 0x2802 +#define RL_TEXTURE_WRAP_T 0x2803 + //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- +typedef enum { OPENGL_11 = 1, OPENGL_21, OPENGL_33, OPENGL_ES_20 } GlVersion; + typedef enum { RL_PROJECTION, RL_MODELVIEW, RL_TEXTURE } MatrixMode; typedef enum { RL_LINES, RL_TRIANGLES, RL_QUADS } DrawMode; -typedef enum { OPENGL_11 = 1, OPENGL_21, OPENGL_33, OPENGL_ES_20 } GlVersion; - #if defined(RLGL_STANDALONE) #ifndef __cplusplus // Boolean type @@ -296,6 +302,7 @@ void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) //------------------------------------------------------------------------------------ void rlEnableTexture(unsigned int id); // Enable texture usage void rlDisableTexture(void); // Disable texture usage +void rlTextureParameters(unsigned int id, int param, int value); // Set texture parameters (filter, wrap) void rlEnableRenderTexture(unsigned int id); // Enable render texture (fbo) void rlDisableRenderTexture(void); // Disable render texture (fbo), return to default framebuffer void rlEnableDepthTest(void); // Enable depth test