diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-08-21 21:57:31 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-08-21 21:57:31 +0200 |
commit | 7a80f0de04c3b07d88ba2ab3e51544d38fe924f6 (patch) | |
tree | 4e67621a944e3686ba724fa953a52eddc8610fe7 | |
parent | ffb6d86c557b2327b2a6363c0d805d717695dce4 (diff) |
Attempt to fix vertex draw when using texcoords without a texture (such as when using a shader)
-rw-r--r-- | include/mgl/graphics/texture.h | 1 | ||||
-rw-r--r-- | src/graphics/texture.c | 7 | ||||
-rw-r--r-- | src/graphics/vertex.c | 10 |
3 files changed, 15 insertions, 3 deletions
diff --git a/include/mgl/graphics/texture.h b/include/mgl/graphics/texture.h index 61ac273..387a977 100644 --- a/include/mgl/graphics/texture.h +++ b/include/mgl/graphics/texture.h @@ -41,6 +41,7 @@ int mgl_texture_update(mgl_texture *self, const unsigned char *data, int offset_ int mgl_texture_resize(mgl_texture *self, int new_width, int new_height, mgl_texture_load_options *load_options); /* If |texture| is NULL then no texture is used */ void mgl_texture_use(const mgl_texture *texture); +const mgl_texture* mgl_texture_current_texture(void); void mgl_texture_unload(mgl_texture *self); #endif /* MGL_TEXTURE_H */ diff --git a/src/graphics/texture.c b/src/graphics/texture.c index 7d8fdcf..fb8c1e5 100644 --- a/src/graphics/texture.c +++ b/src/graphics/texture.c @@ -5,6 +5,8 @@ /* TODO: Check for glTexImage2D/glTexSubImage2D failure */ +static const mgl_texture *current_texture = NULL; + static int mgl_texture_format_to_opengl_format(mgl_texture_format format) { switch(format) { case MGL_TEXTURE_FORMAT_ALPHA: return GL_ALPHA8; @@ -153,6 +155,7 @@ int mgl_texture_resize(mgl_texture *self, int new_width, int new_height, mgl_tex void mgl_texture_use(const mgl_texture *texture) { mgl_context *context = mgl_get_context(); + current_texture = texture; if(texture) { float matrix[16] = { 1.0f, 0.0f, 0.0f, 0.0f, @@ -176,6 +179,10 @@ void mgl_texture_use(const mgl_texture *texture) { } } +const mgl_texture* mgl_texture_current_texture(void) { + return current_texture; +} + void mgl_texture_unload(mgl_texture *self) { mgl_context *context = mgl_get_context(); if(self->id) { diff --git a/src/graphics/vertex.c b/src/graphics/vertex.c index b45f38c..e55c180 100644 --- a/src/graphics/vertex.c +++ b/src/graphics/vertex.c @@ -1,4 +1,5 @@ #include "../../include/mgl/graphics/vertex.h" +#include "../../include/mgl/graphics/texture.h" #include "../../include/mgl/mgl.h" void mgl_vertices_draw(mgl_context *context, const mgl_vertex *vertices, size_t vertex_count, mgl_primitive_type primitive_type, mgl_vec2f position) { @@ -6,11 +7,14 @@ void mgl_vertices_draw(mgl_context *context, const mgl_vertex *vertices, size_t return; context->gl.glPushMatrix(); - context->gl.glTranslatef(position.x, position.y, 0.0f); - context->gl.glMatrixMode(GL_TEXTURE); - context->gl.glLoadIdentity(); + if(!mgl_texture_current_texture()) { + context->gl.glMatrixMode(GL_TEXTURE); + context->gl.glLoadIdentity(); + } + context->gl.glMatrixMode(GL_MODELVIEW); + context->gl.glTranslatef(position.x, position.y, 0.0f); context->gl.glVertexPointer(2, GL_FLOAT, sizeof(mgl_vertex), (void*)&vertices[0].position); context->gl.glTexCoordPointer(2, GL_FLOAT, sizeof(mgl_vertex), (void*)&vertices[0].texcoords); |