diff options
author | jaroWMR <jarorutjes07@gmail.com> | 2024-10-07 10:04:23 +0200 |
---|---|---|
committer | jaroWMR <jarorutjes07@gmail.com> | 2024-10-07 10:04:23 +0200 |
commit | 094ce1806156e191ffb554d4e88e636421cb0242 (patch) | |
tree | 675168131ac24bf29ffb161334be176e4d4022e0 /src/crepe/SDLApp.cpp | |
parent | bd24f87e18bef29679023ee9a60028f2afdbb470 (diff) |
particle direction is random
Diffstat (limited to 'src/crepe/SDLApp.cpp')
-rw-r--r-- | src/crepe/SDLApp.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/crepe/SDLApp.cpp b/src/crepe/SDLApp.cpp new file mode 100644 index 0000000..a5e3621 --- /dev/null +++ b/src/crepe/SDLApp.cpp @@ -0,0 +1,69 @@ +#include "SDLApp.hpp" +#include <iostream> + +SDLApp::SDLApp(int windowWidth, int windowHeight) + : windowWidth(windowWidth), windowHeight(windowHeight), window(nullptr), renderer(nullptr) {} + +SDLApp::~SDLApp() { + cleanUp(); +} + +bool SDLApp::initialize() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + std::cerr << "SDL Initialization Error: " << SDL_GetError() << std::endl; + return false; + } + + window = SDL_CreateWindow("Particle System", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + windowWidth, + windowHeight, + SDL_WINDOW_SHOWN); + if (!window) { + std::cerr << "Window Creation Error: " << SDL_GetError() << std::endl; + return false; + } + + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + std::cerr << "Renderer Creation Error: " << SDL_GetError() << std::endl; + return false; + } + + return true; +} + +void SDLApp::handleEvents(bool& running) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = false; + } + } +} + +void SDLApp::clearScreen() { + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); +} + +void SDLApp::presentScreen() { + SDL_RenderPresent(renderer); +} + +void SDLApp::drawSquare(int x, int y, int size) { + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_Rect rect = { x, y, size, size }; + SDL_RenderFillRect(renderer, &rect); +} + +void SDLApp::cleanUp() { + if (renderer) { + SDL_DestroyRenderer(renderer); + } + if (window) { + SDL_DestroyWindow(window); + } + SDL_Quit(); +} |