display.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. static inline void intSwap(int *a, int *b)
  47. {
  48. int tmp = *a;
  49. *a = *b;
  50. *b = tmp;
  51. }
  52. #define MAKE_RGB(_r, _g, _b) ((0xFF000000) | ((_r & 0xFF) << 16) | ((_g & 0xFF) << 8) | ((_b & 0xFF)))
  53. #define MAKE_ARGB(_a, _r, _g, _b) (((_a & 0xFF) << 24) | ((_r & 0xFF) << 16) | ((_g & 0xFF) << 8) | ((_b & 0xFF)))
  54. #endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */