1
0

Mesh.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef SCUFENG_SHAPE_H_
  2. #define SCUFENG_SHAPE_H_
  3. #include <stdbool.h>
  4. #include <stddef.h>
  5. #include "cglm/types.h"
  6. typedef enum {
  7. SE_TRIANGLES,
  8. SE_TRIANGLE_STRIP,
  9. SE_TRIANGLE_FAN,
  10. SE_LINES,
  11. SE_LINE_STRIP
  12. } SEDrawMode;
  13. typedef struct {
  14. vec3 pos;
  15. vec3 scale;
  16. vec3 rotation;
  17. } SETransform;
  18. typedef struct {
  19. float pos[3];
  20. float tex_coords[2];
  21. } SEVertex;
  22. typedef enum {
  23. SE_MESH_COLOR,
  24. SE_MESH_TEXTURE
  25. } SEMeshType;
  26. typedef struct {
  27. unsigned int id;
  28. float w;
  29. float h;
  30. } SEMeshTexture;
  31. typedef struct {
  32. unsigned int vao;
  33. unsigned int vbo;
  34. size_t verts_n;
  35. int draw_mode;
  36. SETransform transform;
  37. SEMeshType type;
  38. union {
  39. SEMeshTexture texture;
  40. vec4 color;
  41. };
  42. } SEMesh;
  43. void SEMesh_free(SEMesh *const mesh);
  44. void SEMesh_set_draw_mode(SEMesh *mesh, const SEDrawMode mode);
  45. void SEMesh_render(const SEMesh *const mesh);
  46. void SEMesh_color_set(SEMesh *const mesh, const vec4 color);
  47. void SEMesh_rect_dims_get(const SEMesh *const mesh, vec2 dims);
  48. void SEMesh_scale_set_to_texture_size(SEMesh *const mesh);
  49. /**
  50. Set x or y to 0 to automatically calculate that value based on the
  51. w/h ratio of the rect's texture. Setting both to 0 will result in
  52. scale being { 0, 0 }.
  53. */
  54. void SEMesh_rect_textured_scale_set(SEMesh *const mesh, float x, float y);
  55. void SEMesh_line_segment_coords_set(SEMesh *const mesh, const vec2 a, const vec2 b);
  56. SEMesh SEMesh_line_segment_color_alloc(const vec2 a, const vec2 b, const vec4 color);
  57. void SEMesh_bbox_render_2d(const SEMesh *const mesh);
  58. void SEMesh_bbox_get_2d(
  59. const SEMesh *const mesh,
  60. float *const left,
  61. float *const top,
  62. float *const right,
  63. float *const bottom
  64. );
  65. /**
  66. @param bbox Returns the bbox in order: { left, top, right, bottom }.
  67. */
  68. void SEMesh_bbox_get_2d_v(const SEMesh *const mesh, vec4 bbox);
  69. bool SEMesh_rect_is_pos_inside(const SEMesh *const mesh, const float x, const float y);
  70. SEMesh SEMesh_rect_color_alloc(vec4 color);
  71. SEMesh SEMesh_string_alloc(
  72. const char *text,
  73. const vec3 color
  74. );
  75. void SEMesh_render_multiple_2d(SEMesh *const *const meshes, const size_t meshes_n);
  76. #endif // SCUFENG_SHAPE_H_