diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-10-25 20:59:34 +0200 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-10-25 20:59:34 +0200 |
commit | 15a4c4a1cf67e13be53ef423c51c56488f332ea9 (patch) | |
tree | 661084fc8171089ce32bf779f2b3a85d634b38e4 /src/crepe/SDLApp.cpp | |
parent | f472e0ba3bf54fc5055cf9f08925bed3f98a1dbc (diff) | |
parent | b3b762a34e7ccb4a0dcd041a693ac7180af16002 (diff) |
merge conficts fixed
Diffstat (limited to 'src/crepe/SDLApp.cpp')
-rw-r--r-- | src/crepe/SDLApp.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/crepe/SDLApp.cpp b/src/crepe/SDLApp.cpp new file mode 100644 index 0000000..c6ddeaa --- /dev/null +++ b/src/crepe/SDLApp.cpp @@ -0,0 +1,71 @@ +#include <iostream> + +#include "SDLApp.h" + +SDLApp::SDLApp(int window_width, int window_height) + : window_width(window_width), window_height(window_height), window(nullptr), + renderer(nullptr) {} + +// FIXME: why is there clean_up and ~SDLApp? +SDLApp::~SDLApp() { clean_up(); } + +bool SDLApp::initialize() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + // FIXME: throw exception + std::cerr << "SDL Initialization Error: " << SDL_GetError() + << std::endl; + return false; + } + + window = SDL_CreateWindow("Particle System", SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, window_width, + window_height, SDL_WINDOW_SHOWN); + if (!window) { + // FIXME: throw exception + std::cerr << "Window Creation Error: " << SDL_GetError() << std::endl; + return false; + } + + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + // FIXME: throw exception + std::cerr << "Renderer Creation Error: " << SDL_GetError() << std::endl; + return false; + } + + return true; +} + +void SDLApp::handle_events(bool & running) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = false; + } + } +} + +void SDLApp::clear_screen() { + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); +} + +void SDLApp::present_screen() { SDL_RenderPresent(renderer); } + +void SDLApp::draw_square(int x, int y, int size) { + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_Rect rect = {x, y, size, size}; + SDL_RenderFillRect(renderer, &rect); +} + +SDL_Texture * square_texture = nullptr; // Load this with an image or create it + +void SDLApp::clean_up() { + if (renderer) { + SDL_DestroyRenderer(renderer); + } + if (window) { + SDL_DestroyWindow(window); + } + SDL_Quit(); +} |