aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-18 01:39:47 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-18 01:39:47 +0200
commitfc98ecc0fb9461688a5f82515248f56f507080f2 (patch)
tree9b4f43cc75a4a3c2577f7fd23054d38f819bec9f
parent6083534cd846eda51cc8664447ba1490837fd5e3 (diff)
Add set_position and set_color to rectangle,sprite and text
-rw-r--r--include/mgl/graphics/sprite.h4
-rw-r--r--include/mgl/graphics/text.h2
-rw-r--r--src/graphics/sprite.c15
-rw-r--r--src/graphics/text.c8
-rw-r--r--src/window/window.c (renamed from src/window.c)4
-rw-r--r--tests/main.c2
6 files changed, 24 insertions, 11 deletions
diff --git a/include/mgl/graphics/sprite.h b/include/mgl/graphics/sprite.h
index ea40b21..9f0fc51 100644
--- a/include/mgl/graphics/sprite.h
+++ b/include/mgl/graphics/sprite.h
@@ -15,7 +15,9 @@ typedef struct {
} mgl_sprite;
void mgl_sprite_init(mgl_sprite *self, mgl_texture *texture, float x, float y);
+
+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);
-void mgl_sprite_set_color(mgl_sprite *self, float r, float g, float b, float a);
#endif /* MGL_SPRITE_H */
diff --git a/include/mgl/graphics/text.h b/include/mgl/graphics/text.h
index bb07675..0356e82 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);
+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);
#endif /* MGL_TEXT_H */
diff --git a/src/graphics/sprite.c b/src/graphics/sprite.c
index 274278c..2b290bb 100644
--- a/src/graphics/sprite.c
+++ b/src/graphics/sprite.c
@@ -9,6 +9,14 @@ void mgl_sprite_init(mgl_sprite *self, mgl_texture *texture, float x, float y) {
self->scale = (mgl_vec2f){ 1.0f, 1.0f };
}
+void mgl_sprite_set_position(mgl_sprite *self, mgl_vec2f position) {
+ self->position = position;
+}
+
+void mgl_sprite_set_color(mgl_sprite *self, mgl_color color) {
+ self->color = color;
+}
+
/* TODO: Cache texture bind to not bind texture if its already bound and do not bind texture 0 */
void mgl_sprite_draw(mgl_context *context, mgl_sprite *sprite) {
context->gl.glColor4f(sprite->color.r, sprite->color.g, sprite->color.b, sprite->color.a);
@@ -28,10 +36,3 @@ void mgl_sprite_draw(mgl_context *context, mgl_sprite *sprite) {
context->gl.glEnd();
context->gl.glBindTexture(GL_TEXTURE_2D, 0);
}
-
-void mgl_sprite_set_color(mgl_sprite *self, float r, float g, float b, float a) {
- self->color.r = r;
- self->color.g = g;
- self->color.b = b;
- self->color.a = a;
-}
diff --git a/src/graphics/text.c b/src/graphics/text.c
index 204d1e0..9afc204 100644
--- a/src/graphics/text.c
+++ b/src/graphics/text.c
@@ -14,6 +14,14 @@ void mgl_text_deinit(mgl_text *self) {
}
+void mgl_text_set_position(mgl_text *self, mgl_vec2f position) {
+ self->position = position;
+}
+
+void mgl_text_set_color(mgl_text *self, mgl_color color) {
+ self->color = color;
+}
+
static void mgl_text_draw_glyph(mgl_context *context, mgl_font_glyph *glyph, mgl_vec2f position) {
context->gl.glTexCoord2f(glyph->texture_position.x, glyph->texture_position.y);
context->gl.glVertex3f(position.x + glyph->position.x, position.y + glyph->position.y, 0.0f);
diff --git a/src/window.c b/src/window/window.c
index 8042ad3..3c5ce56 100644
--- a/src/window.c
+++ b/src/window/window.c
@@ -1,5 +1,5 @@
-#include "../include/mgl/window/window.h"
-#include "../include/mgl/mgl.h"
+#include "../../include/mgl/window/window.h"
+#include "../../include/mgl/mgl.h"
#include <X11/Xutil.h>
#include <errno.h>
#include <stdio.h>
diff --git a/tests/main.c b/tests/main.c
index bfc73ef..5841924 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -25,7 +25,7 @@ static void draw(mgl_window *window, void *userdata) {
mgl_sprite sprite;
mgl_sprite_init(&sprite, u->texture, 100.0f - 10.0f, 0.0f);
- mgl_sprite_set_color(&sprite, 1.0f, 1.0f, 1.0f, 0.5f);
+ mgl_sprite_set_color(&sprite, (mgl_color){1.0f, 1.0f, 1.0f, 0.5f});
mgl_sprite_draw(context, &sprite);
mgl_text text;