display.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <SDL.h>
  12. /***********************************************************************************************************************
  13. * Constants
  14. **********************************************************************************************************************/
  15. #define FPS (30)
  16. #define FRAME_TARGET_TIME (1000 / FPS)
  17. /***********************************************************************************************************************
  18. * Global variables
  19. **********************************************************************************************************************/
  20. extern SDL_Window *window;
  21. extern SDL_Renderer *renderer;
  22. extern uint32_t *frameBuffer;
  23. extern SDL_Texture *frameBufferTexture;
  24. extern int32_t windowWidth;
  25. extern int32_t windowHeight;
  26. /***********************************************************************************************************************
  27. * Prototypes
  28. **********************************************************************************************************************/
  29. /* --- Window functions --- */
  30. bool initialiseWindow(bool fullScreen);
  31. void destroyWindow();
  32. void renderFrameBuffer();
  33. /* --- Drawing functions --- */
  34. void drawPixel(int32_t x, int32_t y, uint32_t colour);
  35. void clearFrameBuffer(int32_t colour);
  36. void drawGrid(int spacing, uint32_t colour);
  37. void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t colour);
  38. void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour);
  39. void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour);
  40. void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t colour);
  41. void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t colour);
  42. static inline void intSwap(int *a, int *b)
  43. {
  44. int tmp = *a;
  45. *a = *b;
  46. *b = tmp;
  47. }
  48. #endif /* THREEDENGINE_SOURCE_INCLUDE_DISPLAY_H */