aboutsummaryrefslogtreecommitdiff
path: root/src/graphics
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-12-08 01:02:56 +0100
committerdec05eba <dec05eba@protonmail.com>2021-12-08 01:03:15 +0100
commitb7e3507a82d93b470d89f5cdf838f480bd7e4ab4 (patch)
treeac689868c0b0e6caa8a13038e2dd7f9b02e2ef50 /src/graphics
parent1739930d6f4b16eb5f3118412cddd20277ac5639 (diff)
Vertex translation, fix vertex texture use
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/texture.c1
-rw-r--r--src/graphics/vertex.c9
2 files changed, 6 insertions, 4 deletions
diff --git a/src/graphics/texture.c b/src/graphics/texture.c
index 9ea9b12..7d8fdcf 100644
--- a/src/graphics/texture.c
+++ b/src/graphics/texture.c
@@ -149,6 +149,7 @@ int mgl_texture_resize(mgl_texture *self, int new_width, int new_height, mgl_tex
return 0;
}
+/* TODO: Optimize. Do not set matrix if the current coordinate type was the same as the previous one */
void mgl_texture_use(const mgl_texture *texture) {
mgl_context *context = mgl_get_context();
diff --git a/src/graphics/vertex.c b/src/graphics/vertex.c
index 110c86d..8e9b5b9 100644
--- a/src/graphics/vertex.c
+++ b/src/graphics/vertex.c
@@ -1,16 +1,17 @@
#include "../../include/mgl/graphics/vertex.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) {
+void mgl_vertices_draw(mgl_context *context, const mgl_vertex *vertices, size_t vertex_count, mgl_primitive_type primitive_type, mgl_vec2f position) {
if(vertex_count == 0)
return;
- context->gl.glMatrixMode(GL_TEXTURE);
- context->gl.glLoadIdentity();
- context->gl.glMatrixMode(GL_MODELVIEW);
+ context->gl.glPushMatrix();
+ 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);
context->gl.glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(mgl_vertex), (void*)&vertices[0].color);
context->gl.glDrawArrays(mgl_primitive_type_to_gl_mode(primitive_type), 0, vertex_count);
+
+ context->gl.glPopMatrix();
}