91 lines
2.0 KiB
C
91 lines
2.0 KiB
C
#ifndef SCUFENG_SHAPE_H_
|
|
#define SCUFENG_SHAPE_H_
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "cglm/types.h"
|
|
|
|
#include "scufeng/engine.h"
|
|
|
|
typedef enum {
|
|
SE_TRIANGLES,
|
|
SE_TRIANGLE_STRIP,
|
|
SE_TRIANGLE_FAN,
|
|
SE_LINES,
|
|
SE_LINE_STRIP
|
|
} SEDrawMode;
|
|
|
|
typedef struct {
|
|
vec3 pos;
|
|
vec3 scale;
|
|
vec3 rotation;
|
|
} SETransform;
|
|
|
|
typedef struct {
|
|
float pos[3];
|
|
float tex_coords[2];
|
|
} SEVertex;
|
|
|
|
typedef enum {
|
|
SE_MESH_COLOR,
|
|
SE_MESH_TEXTURE
|
|
} SEMeshType;
|
|
|
|
typedef struct {
|
|
unsigned int id;
|
|
float w;
|
|
float h;
|
|
} SEMeshTexture;
|
|
|
|
typedef struct {
|
|
unsigned int vao;
|
|
unsigned int vbo;
|
|
size_t verts_n;
|
|
int draw_mode;
|
|
|
|
SETransform transform;
|
|
|
|
SEMeshType type;
|
|
union {
|
|
SEMeshTexture texture;
|
|
vec4 color;
|
|
};
|
|
} SEMesh;
|
|
|
|
SEResult SEShape_alloc(
|
|
SETransform *const shape,
|
|
const SEVertex *const vertices,
|
|
const size_t vertices_n,
|
|
const vec4 color,
|
|
const SEDrawMode draw_mode
|
|
);
|
|
void SEMesh_free(SEMesh *const mesh);
|
|
void SEMesh_set_draw_mode(SEMesh *mesh, const SEDrawMode mode);
|
|
void SEMesh_render(const SEMesh *const mesh);
|
|
void SEMesh_bbox_get_2d(
|
|
const SEMesh *const mesh,
|
|
float *left,
|
|
float *right,
|
|
float *top,
|
|
float *bottom
|
|
);
|
|
bool SEMesh_rect_is_pos_inside(const SEMesh *const mesh, const float x, const float y);
|
|
void SEShape_rotation_set(SETransform *shape, vec3 rotation);
|
|
void SEShape_rotate_2d_center(SETransform *const shape, const float w, const float h, const float angle_rad);
|
|
void SEShape_scale_set(SETransform *shape, vec3 scale);
|
|
void SEShape_scale(SETransform *const shape, vec3 scale);
|
|
void SEShape_pos_set(SETransform *const shape, vec3 pos);
|
|
void SEShape_translate_2d_center(SETransform *const shape, const float w, const float h, const vec2 pos);
|
|
void SEShape_transform_reset(SETransform *shape);
|
|
|
|
SEMesh SEMesh_rect_color_alloc(vec4 color);
|
|
SEMesh SEMesh_string_alloc(
|
|
const char *text,
|
|
const float scale,
|
|
const vec3 color
|
|
);
|
|
// void SEShape_transform_apply(SEShape *const shape);
|
|
|
|
#endif // SCUFENG_SHAPE_H_
|