-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphicsSystem.cpp
More file actions
39 lines (30 loc) · 977 Bytes
/
GraphicsSystem.cpp
File metadata and controls
39 lines (30 loc) · 977 Bytes
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
#include "GraphicsSystem.h"
#include "SDL.h"
#include "Error.h"
GraphicsSystem &GraphicsSystem::GetInstance()
{
static GraphicsSystem instance;
return instance;
}
GraphicsSystem::~GraphicsSystem()
{
// free resources
SDL_DestroyRenderer(mRenderer);
SDL_DestroyWindow(mWindow);
}
void GraphicsSystem::Initialize(int windowWidth, int windowHeight)
{
// init video (and event) subsystems
if (SDL_Init(SDL_INIT_VIDEO) != 0)
Error("can't initialize video", SDL_GetError());
// create window
mWindow = SDL_CreateWindow("NES Emulator", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0);
if (!mWindow)
Error("can't create window", SDL_GetError());
mWindowWidth = windowWidth;
mWindowHeight = windowHeight;
// create renderer (default render target is the window from which it is created)
mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);
if (!mRenderer)
Error("can't create renderer", SDL_GetError());
}