gearlib/src/quad.c
2024-05-03 11:18:50 +12:00

43 lines
1.2 KiB
C

#include <gearlib.h>
vec3 quad_vertex_positions[6] = {
{ -0.5f, 0.5f, 0.0f },
{ -0.5f, -0.5f, 0.0f },
{ 0.5f, -0.5f, 0.0f },
{ -0.5f, 0.5f, 0.0f },
{ 0.5f, -0.5f, 0.0f },
{ 0.5f, 0.5f, 0.0f },
};
void draw_rectangle(RenderBatch* batch, mat4 transform, vec4 color) {
if(batch_needs_flush(batch, 6))
flush_batch(batch);
for(int i = 0; i < 6; i++) {
QuadVertex* vertex = batch->vertex_ptr;
vertex->Position = quad_vertex_positions[i];
vertex->Color = color;
batch->vertex_ptr += batch->vertex_size;
batch->vertex_count++;
}
}
void setup_quad() {
RenderBatch* quad_batch = create_batch(sizeof(QuadVertex), MAX_VERTICES);
quad_batch->shader = load_shader_program(
compile_shader("assets/quad.vert", GL_VERTEX_SHADER),
compile_shader("assets/quad.frag", GL_FRAGMENT_SHADER), 0);;
batch_add_attrib(quad_batch, (VertexAttrib){
.type = GL_FLOAT, .size = sizeof(float), .count = 3
}); // pos
batch_add_attrib(quad_batch, (VertexAttrib){
.type = GL_FLOAT, .size = sizeof(float), .count = 4
}); // color
batch_bind_attribs(quad_batch);
}