/* * 2D Physic Engine * graphics.h: header for the utilities to display stuff. * Based on pikuma.com Learn Game Physics Engine Programming course. * Copyright (c) 2022 986-Studio. All rights reserved. * * Created by Manoƫl Trapier on 07/06/2022. */ #ifndef PHYSICENGINE_GRAPHICS_H #define PHYSICENGINE_GRAPHICS_H #include #include #include #include #include class graphics { private: static int windowWidth; static int windowHeight; static int windowFlags; static SDL_Window* window; static SDL_Renderer* renderer; static TTF_Font *font; public: static int width() { return graphics::windowWidth; } static int height() { return graphics::windowHeight; } static bool openWindow(bool fullScreen = true); static void closeWindow(); static void clearScreen(uint32_t color); static void renderFrame(); static SDL_Texture *loadTexture(const char *filename); static uint32_t makeColour(uint8_t r, uint8_t g, uint8_t b) { return 0xFF000000 | (r << 16) | (g << 8) | (b << 0); } static uint32_t makeColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { return (a << 24) | (r << 16) | (g << 8) | (b << 0); } struct draw { static void line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t color); static void circle(int16_t x, int16_t y, int16_t radius, double angle, uint32_t color); static void arrow(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color); static void fillCircle(int16_t x, int16_t y, int16_t radius, uint32_t color); static void rect(int16_t x, int16_t y, int16_t width, int16_t height, uint32_t color); static void fillRect(int16_t x, int16_t y, int16_t width, int16_t height, uint32_t color); static void polygon(int16_t x, int16_t y, const std::vector& vertices, uint32_t color); static void fillPolygon(int16_t x, int16_t y, const std::vector &vertices, uint32_t color); static void texture(int16_t x, int16_t y, int16_t width, int16_t height, double rotation, SDL_Texture *texture); static void text(int16_t x, int16_t y, uint32_t colour, const char *format, ...); }; }; #endif /* PHYSICENGINE_GRAPHICS_H */