display.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * 3D Engine
  3. * display.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 01/03/2021.
  8. */
  9. #ifndef THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H
  10. #define THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H
  11. #include <stdbool.h>
  12. #include <SDL.h>
  13. #include <vector.h>
  14. #include <texture.h>
  15. #include <colour.h>
  16. /***********************************************************************************************************************
  17. * Data types
  18. **********************************************************************************************************************/
  19. typedef struct window_t
  20. {
  21. int32_t height, width;
  22. } window_t;
  23. /***********************************************************************************************************************
  24. * Constants
  25. **********************************************************************************************************************/
  26. #define FPS (60)
  27. #define FRAME_TARGET_TIME (1000 / FPS)
  28. /***********************************************************************************************************************
  29. * Prototypes
  30. **********************************************************************************************************************/
  31. /* --- Window functions --- */
  32. bool initialiseWindow(int32_t screenWidth, int32_t screenHeight, bool fullScreen);
  33. void destroyWindow();
  34. void renderFrameBuffer();
  35. void getWindowSize(int32_t *width, int32_t *height);
  36. void displayWindowClear();
  37. void displayWindowRender();
  38. /* --- Drawing functions --- */
  39. void clearZBuffer();
  40. void clearFrameBuffer(colour_t colour);
  41. void drawPixel(int32_t x, int32_t y, colour_t colour);
  42. void drawGrid(int spacing, colour_t colour);
  43. void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, colour_t colour);
  44. void drawVLine(int32_t x, int32_t y0, int32_t y1, colour_t colour);
  45. void drawHLine(int32_t x0, int32_t y, int32_t x1, colour_t colour);
  46. void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, colour_t colour);
  47. void drawText(int32_t x, int32_t y, colour_t colour, const char *format, ...);
  48. static inline void intSwap(int *a, int *b)
  49. {
  50. int tmp = *a;
  51. *a = *b;
  52. *b = tmp;
  53. }
  54. static inline void doubleSwap(double *a, double *b)
  55. {
  56. double tmp = *a;
  57. *a = *b;
  58. *b = tmp;
  59. }
  60. /* Other */
  61. void drawZPixel(int32_t x, int32_t y, vec4_t a, vec4_t b, vec4_t c, colour_t colour);
  62. void drawTexel(int32_t x, int32_t y, vec4_t a, vec4_t b, vec4_t c, tex2_t ta, tex2_t tb, tex2_t tc, texture_t *texture);
  63. #endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */