triangle.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * 3D Engine
  3. * triangle.h:
  4. * Based on pikuma.com 3D software renderer in C
  5. * Copyright (c) 2021 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 04/03/2021.
  8. */
  9. #ifndef THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H
  10. #define THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H
  11. #include <stdint.h>
  12. #include <display.h>
  13. #include <vector.h>
  14. #include <texture.h>
  15. /***********************************************************************************************************************
  16. * Data types
  17. **********************************************************************************************************************/
  18. typedef struct face_t
  19. {
  20. int a, b, c;
  21. tex2_t a_uv, b_uv, c_uv;
  22. colour_t colour;
  23. } face_t;
  24. typedef struct triangle_t
  25. {
  26. vec2_t points[3];
  27. tex2_t textureCoordinates[3];
  28. colour_t colour;
  29. double averageDepth;
  30. uint32_t *texture;
  31. } triangle_t;
  32. /***********************************************************************************************************************
  33. * Prototypes
  34. **********************************************************************************************************************/
  35. void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour);
  36. void drawFilledTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, colour_t colour);
  37. void drawTextureTriangle(struct triangle_t *t);
  38. int compareTrianglesZOrder(const void *p1, const void *p2);
  39. #endif /* THREEDENGINE_SOURCE_INCLUDE_TRIANGLE_H */