From 97f1b1c735775d1e22412bbcf98ef403f9ee2275 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 16 Oct 2021 07:04:34 +0200 Subject: Add rectangle and sprite, use pixel coordinates, remote opengl dependency from test --- include/mgl/graphics/color.h | 8 ++++++++ include/mgl/graphics/rectangle.h | 17 +++++++++++++++++ include/mgl/graphics/sprite.h | 21 +++++++++++++++++++++ include/mgl/graphics/texture.h | 6 ++++-- include/mgl/graphics/vec.h | 8 ++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 include/mgl/graphics/color.h create mode 100644 include/mgl/graphics/rectangle.h create mode 100644 include/mgl/graphics/sprite.h create mode 100644 include/mgl/graphics/vec.h (limited to 'include/mgl/graphics') diff --git a/include/mgl/graphics/color.h b/include/mgl/graphics/color.h new file mode 100644 index 0000000..62ded72 --- /dev/null +++ b/include/mgl/graphics/color.h @@ -0,0 +1,8 @@ +#ifndef MGL_COLOR_H +#define MGL_COLOR_H + +typedef struct { + float r, g, b, a; +} mgl_color; + +#endif /* MGL_COLOR_H */ diff --git a/include/mgl/graphics/rectangle.h b/include/mgl/graphics/rectangle.h new file mode 100644 index 0000000..7c2403b --- /dev/null +++ b/include/mgl/graphics/rectangle.h @@ -0,0 +1,17 @@ +#ifndef MGL_RECTANGLE_H +#define MGL_RECTANGLE_H + +#include "color.h" +#include "vec.h" + +typedef struct mgl_context mgl_context; + +typedef struct { + mgl_color color; + mgl_vec2f position; + mgl_vec2f size; +} mgl_rectangle; + +void mgl_rectangle_draw(mgl_context *context, mgl_rectangle *rect); + +#endif /* MGL_RECTANGLE_H */ diff --git a/include/mgl/graphics/sprite.h b/include/mgl/graphics/sprite.h new file mode 100644 index 0000000..045da19 --- /dev/null +++ b/include/mgl/graphics/sprite.h @@ -0,0 +1,21 @@ +#ifndef MGL_SPRITE_H +#define MGL_SPRITE_H + +#include "color.h" +#include "vec.h" + +typedef struct mgl_context mgl_context; +typedef struct mgl_texture mgl_texture; + +typedef struct { + mgl_texture *texture; + mgl_color color; + mgl_vec2f position; + mgl_vec2f scale; +} mgl_sprite; + +void mgl_sprite_init(mgl_sprite *self, mgl_texture *texture, float x, float y); +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/texture.h b/include/mgl/graphics/texture.h index 669be1e..7048c20 100644 --- a/include/mgl/graphics/texture.h +++ b/include/mgl/graphics/texture.h @@ -1,6 +1,8 @@ #ifndef MGL_TEXTURE_H #define MGL_TEXTURE_H +typedef struct mgl_texture mgl_texture; + typedef enum { MGL_TEXTURE_GRAY = 1, MGL_TEXTURE_GRAY_ALPHA = 2, @@ -8,12 +10,12 @@ typedef enum { MGL_TEXTURE_RGB_ALPHA = 4 } mgl_texture_format; -typedef struct { +struct mgl_texture { unsigned int id; int width; int height; mgl_texture_format format; -} mgl_texture; +}; int mgl_texture_load_from_file(mgl_texture *self, const char *filepath); void mgl_texture_unload(mgl_texture *self); diff --git a/include/mgl/graphics/vec.h b/include/mgl/graphics/vec.h new file mode 100644 index 0000000..562f560 --- /dev/null +++ b/include/mgl/graphics/vec.h @@ -0,0 +1,8 @@ +#ifndef MGL_VEC_H +#define MGL_VEC_H + +typedef struct { + float x, y; +} mgl_vec2f; + +#endif /* MGL_VEC_H */ -- cgit v1.2.3