From 898b8c95f1f904307c02e978b57301cf1cb0560f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 23 Oct 2021 01:39:57 +0200 Subject: Allow rendering vertices directly --- include/mgl/graphics/primitive_type.h | 18 ++++++++++++++++++ include/mgl/graphics/sprite.h | 3 +++ include/mgl/graphics/text.h | 2 ++ include/mgl/graphics/vertex.h | 6 ++++++ include/mgl/graphics/vertex_buffer.h | 12 ------------ 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 include/mgl/graphics/primitive_type.h (limited to 'include/mgl/graphics') diff --git a/include/mgl/graphics/primitive_type.h b/include/mgl/graphics/primitive_type.h new file mode 100644 index 0000000..0621a8d --- /dev/null +++ b/include/mgl/graphics/primitive_type.h @@ -0,0 +1,18 @@ +#ifndef MGL_PRIMITIVE_TYPE_H +#define MGL_PRIMITIVE_TYPE_H + +typedef enum { + MGL_PRIMITIVE_POINTS, + MGL_PRIMITIVE_LINES, + MGL_PRIMITIVE_LINE_STRIP, + MGL_PRIMITIVE_TRIANGLES, + MGL_PRIMITIVE_TRIANGLE_STRIP, + MGL_PRIMITIVE_TRIANGLE_FAN, + MGL_PRIMITIVE_QUADS, + MGL_PRIMITIVE_QUAD_STRIP, + MGL_PRIMITIVE_POLYGON, +} mgl_primitive_type; + +unsigned int mgl_primitive_type_to_gl_mode(mgl_primitive_type primitive_type); + +#endif /* MGL_PRIMITIVE_TYPE_H */ diff --git a/include/mgl/graphics/sprite.h b/include/mgl/graphics/sprite.h index 9f0fc51..8c84153 100644 --- a/include/mgl/graphics/sprite.h +++ b/include/mgl/graphics/sprite.h @@ -14,8 +14,11 @@ typedef struct { mgl_vec2f scale; } mgl_sprite; +/* |texture| may be NULL */ void mgl_sprite_init(mgl_sprite *self, mgl_texture *texture, float x, float y); +/* |texture| may be NULL */ +void mgl_sprite_set_texture(mgl_sprite *self, mgl_texture *texture); void mgl_sprite_set_position(mgl_sprite *self, mgl_vec2f position); void mgl_sprite_set_color(mgl_sprite *self, mgl_color color); void mgl_sprite_draw(mgl_context *context, mgl_sprite *sprite); diff --git a/include/mgl/graphics/text.h b/include/mgl/graphics/text.h index 0356e82..33c75d0 100644 --- a/include/mgl/graphics/text.h +++ b/include/mgl/graphics/text.h @@ -18,6 +18,8 @@ typedef struct { int mgl_text_init(mgl_text *self, mgl_font *font, const char *text, float x, float y); void mgl_text_deinit(mgl_text *self); +/* Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used. */ +void mgl_text_set_string(mgl_text *self, const char *str); void mgl_text_set_position(mgl_text *self, mgl_vec2f position); void mgl_text_set_color(mgl_text *self, mgl_color color); void mgl_text_draw(mgl_context *context, mgl_text *text); diff --git a/include/mgl/graphics/vertex.h b/include/mgl/graphics/vertex.h index 69400b4..e4fef34 100644 --- a/include/mgl/graphics/vertex.h +++ b/include/mgl/graphics/vertex.h @@ -1,8 +1,12 @@ #ifndef MGL_VERTEX_H #define MGL_VERTEX_H +#include "primitive_type.h" #include "color.h" #include "../system/vec.h" +#include + +typedef struct mgl_context mgl_context; typedef struct { mgl_vec2f position; @@ -10,4 +14,6 @@ typedef struct { mgl_color color; } mgl_vertex; +void mgl_vertices_draw(mgl_context *context, const mgl_vertex *vertices, size_t vertex_count, mgl_primitive_type primitive_type); + #endif /* MGL_VERTEX_H */ diff --git a/include/mgl/graphics/vertex_buffer.h b/include/mgl/graphics/vertex_buffer.h index 2a32d3d..5cdadfa 100644 --- a/include/mgl/graphics/vertex_buffer.h +++ b/include/mgl/graphics/vertex_buffer.h @@ -7,18 +7,6 @@ typedef struct mgl_context mgl_context; typedef struct mgl_texture mgl_texture; -typedef enum { - MGL_PRIMITIVE_POINTS, - MGL_PRIMITIVE_LINES, - MGL_PRIMITIVE_LINE_STRIP, - MGL_PRIMITIVE_TRIANGLES, - MGL_PRIMITIVE_TRIANGLE_STRIP, - MGL_PRIMITIVE_TRIANGLE_FAN, - MGL_PRIMITIVE_QUADS, - MGL_PRIMITIVE_QUAD_STRIP, - MGL_PRIMITIVE_POLYGON, -} mgl_primitive_type; - typedef enum { MGL_USAGE_STREAM, MGL_USAGE_DYNAMIC, -- cgit v1.2.3