diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-18 18:18:15 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-18 18:18:15 +0100 |
| commit | b228349c5d3e93e8e58e96efeb332fdb58093f0f (patch) | |
| tree | c6c85e7feaf668c15b4f9a685c6955f7095135f6 /src | |
| download | 2048-b228349c5d3e93e8e58e96efeb332fdb58093f0f.tar.gz 2048-b228349c5d3e93e8e58e96efeb332fdb58093f0f.tar.bz2 2048-b228349c5d3e93e8e58e96efeb332fdb58093f0f.zip | |
Initial commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/graphics.cpp | 50 | ||||
| -rw-r--r-- | src/main.cpp | 17 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp new file mode 100644 index 0000000..589a1a8 --- /dev/null +++ b/src/graphics.cpp @@ -0,0 +1,50 @@ +#include "graphics.hpp" + +Graphics::Graphics(std::string t, int w, int h) +{ + running = true; + title = t; + width = w; + height = h; + + if (SDL_Init(SDL_INIT_VIDEO) < 0) + return; + if ((window = SDL_CreateWindow(title.c_str(), 0, 0, width, height, 0)) == NULL) + return; + if ((renderer = SDL_CreateRenderer(window, -1, 0)) == NULL) + return; +} + +Graphics::~Graphics() +{ + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); +} + +void Graphics::update() +{ + SDL_RenderClear(renderer); + handleEvent(); + SDL_RenderPresent(renderer); +} + +bool Graphics::isRunning() +{ + return running; +} + +void Graphics::handleEvent() +{ + SDL_Event e; + + while (SDL_PollEvent(&e)) + { + switch (e.type) + { + case SDL_QUIT: + running = false; + } + } + +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..c4ef817 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,17 @@ +#include <iostream> +#include <SDL2/SDL.h> +#include "graphics.hpp" + +#define WINDOW_TITLE "2048" +#define WINDOW_WIDTH 640 +#define WINDOW_HEIGHT 480 + +int main() +{ + Graphics g = Graphics(WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT); + + while (g.isRunning()) + g.update(); + + return 0; +} |
