diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-10-29 14:29:24 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-10-29 14:29:24 +0200 |
commit | 275e851e8a2b11c2efe7c39787bf331dd3b75272 (patch) | |
tree | 940b5144cadd293b5684057f1f5ab0548262d9be /src/graphics/vertex.c | |
parent | 5476dd7d21875d68a4d957f441d34eee2a9e2b37 (diff) |
Use gl*Pointer and glDrawArrays to render vertices (in mgl_vertices_draw) instead of loop with glBegin/glEnd
Diffstat (limited to 'src/graphics/vertex.c')
-rw-r--r-- | src/graphics/vertex.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/graphics/vertex.c b/src/graphics/vertex.c index 629b421..dff9661 100644 --- a/src/graphics/vertex.c +++ b/src/graphics/vertex.c @@ -2,12 +2,11 @@ #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) { - context->gl.glBegin(mgl_primitive_type_to_gl_mode(primitive_type)); - for(size_t i = 0; i < vertex_count; ++i) { - const mgl_vertex *vertex = &vertices[i]; - context->gl.glColor4ub(vertex->color.r, vertex->color.g, vertex->color.b, vertex->color.a); - context->gl.glTexCoord2f(vertex->texcoords.x, vertex->texcoords.y); - context->gl.glVertex3f(vertex->position.x, vertex->position.y, 0.0f); - } - context->gl.glEnd(); + if(vertex_count == 0) + return; + + 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); } |