aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/sprite.c
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 /src/graphics/sprite.c
parentdf2e6771c5bf6f09e62f9d6b86d83a2631ea365f (diff)
Allow rendering vertices directly
Diffstat (limited to 'src/graphics/sprite.c')
-rw-r--r--src/graphics/sprite.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/graphics/sprite.c b/src/graphics/sprite.c
index 7bc9db1..231b554 100644
--- a/src/graphics/sprite.c
+++ b/src/graphics/sprite.c
@@ -9,6 +9,10 @@ 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_texture(mgl_sprite *self, mgl_texture *texture) {
+ self->texture = texture;
+}
+
void mgl_sprite_set_position(mgl_sprite *self, mgl_vec2f position) {
self->position = position;
}
@@ -19,6 +23,9 @@ void mgl_sprite_set_color(mgl_sprite *self, mgl_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) {
+ if(!sprite->texture)
+ return;
+
context->gl.glColor4ub(sprite->color.r, sprite->color.g, sprite->color.b, sprite->color.a);
context->gl.glBindTexture(GL_TEXTURE_2D, sprite->texture->id);
context->gl.glBegin(GL_QUADS);