display.h 2.0 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 <stdbool.h>
  12. #include <SDL.h>
  13. /***********************************************************************************************************************
  14. * Constants
  15. **********************************************************************************************************************/
  16. #define FPS (30)
  17. #define FRAME_TARGET_TIME (1000 / FPS)
  18. /***********************************************************************************************************************
  19. * Global variables
  20. **********************************************************************************************************************/
  21. extern SDL_Window *window;
  22. extern SDL_Renderer *renderer;
  23. extern uint32_t *frameBuffer;
  24. extern SDL_Texture *frameBufferTexture;
  25. extern int32_t windowWidth;
  26. extern int32_t windowHeight;
  27. /***********************************************************************************************************************
  28. * Prototypes
  29. **********************************************************************************************************************/
  30. /* --- Window functions --- */
  31. bool initialiseWindow(bool fullScreen);
  32. void destroyWindow();
  33. void renderFrameBuffer();
  34. /* --- Drawing functions --- */
  35. void drawPixel(int32_t x, int32_t y, uint32_t colour);
  36. void clearFrameBuffer(int32_t colour);
  37. void drawGrid(int spacing, uint32_t colour);
  38. void drawRectangle(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t colour);
  39. void drawVLine(int32_t x, int32_t y0, int32_t y1, uint32_t colour);
  40. void drawHLine(int32_t x0, int32_t y, int32_t x1, uint32_t colour);
  41. void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, 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 */