display.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /***********************************************************************************************************************
  14. * Data types
  15. **********************************************************************************************************************/
  16. typedef uint32_t colour_t;
  17. /***********************************************************************************************************************
  18. * Constants
  19. **********************************************************************************************************************/
  20. #define FPS (60)
  21. #define FRAME_TARGET_TIME (1000 / FPS)
  22. /***********************************************************************************************************************
  23. * Global variables
  24. **********************************************************************************************************************/
  25. extern SDL_Window *window;
  26. extern SDL_Renderer *renderer;
  27. extern uint32_t *frameBuffer;
  28. extern SDL_Texture *frameBufferTexture;
  29. extern int32_t windowWidth;
  30. extern int32_t windowHeight;
  31. /***********************************************************************************************************************
  32. * Prototypes
  33. **********************************************************************************************************************/
  34. /* --- Window functions --- */
  35. bool initialiseWindow(bool fullScreen);
  36. void destroyWindow();
  37. void renderFrameBuffer();
  38. /* --- Drawing functions --- */
  39. void drawPixel(int32_t x, int32_t y, colour_t colour);
  40. void clearFrameBuffer(colour_t colour);
  41. void drawGrid(int spacing, colour_t colour);
  42. void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, colour_t colour);
  43. void drawVLine(int32_t x, int32_t y0, int32_t y1, colour_t colour);
  44. void drawHLine(int32_t x0, int32_t y, int32_t x1, colour_t colour);
  45. void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, colour_t colour);
  46. void drawText(int32_t x, int32_t y, colour_t colour, const char *format, ...);
  47. static inline void intSwap(int *a, int *b)
  48. {
  49. int tmp = *a;
  50. *a = *b;
  51. *b = tmp;
  52. }
  53. static inline void doubleSwap(double *a, double *b)
  54. {
  55. double tmp = *a;
  56. *a = *b;
  57. *b = tmp;
  58. }
  59. #define MAKE_RGB(_r, _g, _b) ((0xFF000000) | ((_b & 0xFF) << 16) | ((_g & 0xFF) << 8) | ((_r & 0xFF)))
  60. #define MAKE_ARGB(_a, _r, _g, _b) (((_a & 0xFF) << 24) | ((_g & 0xFF) << 16) | ((_g & 0xFF) << 8) | ((_r & 0xFF)))
  61. #endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */