1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /*
- * 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 <cstdint>
- #include <vector>
- #include <SDL.h>
- #include <SDL_ttf.h>
- #include <physics/vec2.h>
- 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 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<vec2>& vertices, uint32_t color);
- static void fillPolygon(int16_t x, int16_t y, const std::vector<vec2> &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 */
|