-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cc
More file actions
49 lines (35 loc) · 1.2 KB
/
window.cc
File metadata and controls
49 lines (35 loc) · 1.2 KB
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
#include "window.h"
Window::Window(const int width, const int height, const std::string& title)
: width(width), height(height), title(title) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "Could not initiate video. \n";
std::exit(-1);
}
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height,
SDL_WINDOW_SHOWN);
if (window == nullptr) {
std::cerr << "Could not create a window. \n";
std::exit(-1);
}
//Get window surface
this->screen = SDL_GetWindowSurface(window);
//Fill the surface white
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0x00, 0xCC, 0xFF));
//Update the surface
SDL_UpdateWindowSurface(window);
}
Window::~Window() {
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();
}
void Window::drawRectToScreen(Rect r, Color c) {
SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, c.red, c.green, c.blue));
}
void Window::updateWindow() {
SDL_UpdateWindowSurface(window);
}
void Window::saveToFile(const std::string& file) {
SDL_SaveBMP(screen, file.c_str());
}