aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-23 01:39:57 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-23 01:39:57 +0200
commit898b8c95f1f904307c02e978b57301cf1cb0560f (patch)
treed0bf51298967533ffb3ca6565ee309948820cf3f /include
parentdf2e6771c5bf6f09e62f9d6b86d83a2631ea365f (diff)
Allow rendering vertices directly
Diffstat (limited to 'include')
-rw-r--r--include/mgl/graphics/primitive_type.h18
-rw-r--r--include/mgl/graphics/sprite.h3
-rw-r--r--include/mgl/graphics/text.h2
-rw-r--r--include/mgl/graphics/vertex.h6
-rw-r--r--include/mgl/graphics/vertex_buffer.h12
5 files changed, 29 insertions, 12 deletions
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 <stddef.h>
+
+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
@@ -8,18 +8,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,
MGL_USAGE_STATIC