-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameDani.cpp2
76 lines (68 loc) · 1.63 KB
/
GameDani.cpp2
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Game.h"
#include <SDL.h>
#include <iostream>
namespace dani
{
Game::Game()
{
m_bRunning = true;
}
Game::~Game()
{
}
void Game::render()
{
// set to black
SDL_SetRenderDrawColor(m_pRenderer, 0, 0, 0, 255);
// clear the window to black
SDL_RenderClear(m_pRenderer);
// show the window
SDL_RenderPresent(m_pRenderer);
}
void Game::clean()
{
std::cout << "cleaning game\n";
SDL_DestroyWindow(m_pWindow);
SDL_DestroyRenderer(m_pRenderer);
SDL_Quit();
}
void Game::handleEvents()
{
SDL_Event event;
if(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
m_bRunning = false;
break;
default:
break; }
}
}
void Game::update()
{
}
bool Game::init(const char* title, int xpos, int ypos, int width,
int height, int flags)
{
//see at http://wiki.libsdl.org/MigrationGuide#Overview_of_new_features how to upgrade to SDL2 textures to use GPU better
// initialize SDL
if(SDL_Init(SDL_INIT_EVERYTHING) >= 0)
{
// if succeeded create our window
m_pWindow = SDL_CreateWindow("Chapter 1: Setting up SDL",
xpos, SDL_WINDOWPOS_CENTERED,
height, width,
flags);
// if the window creation succeeded create our renderer
if(m_pWindow != 0)
{
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
}
} else {
return false; // sdl could not initialize
}
return true;
}
}