| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #ifndef SCUFENG_SHAPE_H_
- #define SCUFENG_SHAPE_H_
- #include <stdbool.h>
- #include <stddef.h>
- #include "cglm/types.h"
- #include "scufcont/DString.h"
- #include "scufeng/engine.h"
- #define SEMesh_string_c_str(mesh_ptr) SCDString_c_str(&mesh_ptr->string.text)
- 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,
- SE_MESH_STRING
- } SEMeshType;
- typedef struct {
- unsigned int id;
- float w;
- float h;
- } SEMeshTexture;
- typedef struct {
- SEMeshTexture texture;
- SCDString text;
- vec3 color;
- } SEMeshString;
- typedef struct {
- unsigned int vao;
- unsigned int vbo;
- size_t verts_n;
- int draw_mode;
- SETransform transform;
- SEMeshType type;
- union {
- SEMeshString string;
- SEMeshTexture texture;
- vec4 color;
- };
- } SEMesh;
- 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_color_set(SEMesh *const mesh, const vec4 color);
- void SEMesh_rect_dims_get(const SEMesh *const mesh, vec2 dims);
- void SEMesh_scale_set_to_texture_size(SEMesh *const mesh);
- /**
- Set x or y to 0 to automatically calculate that value based on the
- w/h ratio of the rect's texture. Setting both to 0 will result in
- scale being { 0, 0 }.
- */
- void SEMesh_rect_textured_scale_set(SEMesh *const mesh, float x, float y);
- void SEMesh_textured_replace(
- SEMesh *const mesh,
- const unsigned int id,
- const float w,
- const float h
- );
- void SEMesh_line_segment_coords_set(SEMesh *const mesh, const vec2 a, const vec2 b);
- SEMesh SEMesh_line_segment_color_alloc(const vec2 a, const vec2 b, const vec4 color);
- void SEMesh_bbox_render_2d(const SEMesh *const mesh);
- void SEMesh_bbox_get_2d(
- const SEMesh *const mesh,
- float *const left,
- float *const top,
- float *const right,
- float *const bottom
- );
- /**
- @param bbox Returns the bbox in order: { left, top, right, bottom }.
- */
- void SEMesh_bbox_get_2d_v(const SEMesh *const mesh, vec4 bbox);
- bool SEMesh_rect_is_pos_inside(const SEMesh *const mesh, const float x, const float y);
- SEMesh SEMesh_rect_color_alloc(vec4 color);
- /**
- @return SE_OUT_OF_MEMORY
- @return SE_SUCCESS
- */
- SEResult SEMesh_string_alloc(
- SEMesh *const mesh,
- const char *text,
- const size_t text_len,
- const vec3 color
- );
- /**
- @return SE_OUT_OF_MEMORY
- @return SE_SUCCESS
- */
- SEResult SEMesh_string_text_replace(
- SEMesh *const mesh,
- const char *text,
- const size_t text_len,
- const vec3 color
- );
- void SEMesh_render_multiple_2d(SEMesh *const *const meshes, const size_t meshes_n);
- #endif // SCUFENG_SHAPE_H_
|