blob: 589a1a82ed97d1c245f0f1b5a357442b43ae9339 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
}
}
}
|