1
0

Mesh.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_line_segment_coords_set(SEMesh *const mesh, const vec2 a, const vec2 b);
  49. SEMesh SEMesh_line_segment_color_alloc(const vec2 a, const vec2 b, const vec4 color);
  50. void SEMesh_bbox_render_2d(const SEMesh *const mesh);
  51. void SEMesh_bbox_get_2d(
  52. const SEMesh *const mesh,
  53. float *left,
  54. float *right,
  55. float *top,
  56. float *bottom
  57. );
  58. bool SEMesh_rect_is_pos_inside(const SEMesh *const mesh, const float x, const float y);
  59. SEMesh SEMesh_rect_color_alloc(vec4 color);
  60. SEMesh SEMesh_string_alloc(
  61. const char *text,
  62. const float scale,
  63. const vec3 color
  64. );
  65. void SEMesh_render_multiple_2d(SEMesh *const *const meshes, const size_t meshes_n);
  66. // void SEShape_transform_apply(SEShape *const shape);
  67. #endif // SCUFENG_SHAPE_H_