aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/vertex.c
blob: 92a6e93b7c68fec7c64b69896e17de0fe4aff4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "../../include/mgl/graphics/vertex.h"
#include "../../include/mgl/graphics/texture.h"
#include "../../include/mgl/window/window.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) {
    if(vertex_count == 0)
        return;

    mgl_window_set_texture_blend_func(context->current_window);

    context->gl.glPushMatrix();

    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);
    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();

    mgl_window_set_render_blend_func(context->current_window);
}