-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
48 lines (37 loc) · 1.49 KB
/
window.cpp
File metadata and controls
48 lines (37 loc) · 1.49 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
#include "window.hpp"
#include <SDL2/SDL.h>
#include <SDL2pp/Renderer.hh>
#include <SDL2pp/SDL.hh>
#include <SDL2pp/Texture.hh>
#include <SDL2pp/Window.hh>
Window::Window(int width, int height) : width_(width), height_(height)
{
sdl_ = std::make_unique<SDL2pp::SDL>(SDL_INIT_VIDEO);
window_ = std::make_unique<SDL2pp::Window>("L-systems",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height,
0); // flags
renderer_ = std::make_unique<SDL2pp::Renderer>(*window_,
-1, // first renderer to support requested flags
SDL_RENDERER_ACCELERATED);
texture_ = std::make_unique<SDL2pp::Texture>(*renderer_,
SDL_PIXELFORMAT_RGBA32,
SDL_TEXTUREACCESS_TARGET,
width_, height_);
SDL2pp::Color background { 30, 30, 40};
// Clear black texture
renderer_->SetTarget(*texture_);
renderer_->SetDrawColor(background);
renderer_->Clear();
// Clear black screen
renderer_->SetTarget();
renderer_->SetDrawColor(background);
renderer_->Clear();
renderer_->Present();
}
void Window::upate() const
{
renderer_->SetTarget();
renderer_->Copy(*texture_);
renderer_->Present();
}