Repository navigation
Expand file tree
/
Copy pathGraphics.cpp
More file actions
63 lines (53 loc) · 1.51 KB
/
Copy pathGraphics.cpp
File metadata and controls
63 lines (53 loc) · 1.51 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// filepath: c:\PROJECTS\sdl3_ls_engine\Graphics.cpp
#include "Graphics.h"
#include <SDL3/SDL.h>
#include <stdexcept>
Graphics::Graphics(unsigned int width, unsigned int height, const std::string& title)
: width(width), height(height), window(nullptr), renderer(nullptr)
{
// Create the window
if (!SDL_CreateWindowAndRenderer(title.c_str(), width, height, SDL_WINDOW_RESIZABLE, &window, &renderer)) {
SDL_Log("Couldn't create window and renderer: %s", SDL_GetError());
throw std::runtime_error(SDL_GetError());
}
const SDL_Rect textarea = {0, 0, 800, 600};
SDL_SetTextInputArea(window, &textarea, 0);
SDL_StartTextInput(window);
}
Graphics::~Graphics()
{
if (renderer) {
SDL_DestroyRenderer(renderer);
renderer = nullptr;
}
if (window) {
SDL_DestroyWindow(window);
window = nullptr;
}
// Quit SDL subsystems initialized by this object
SDL_Quit();
}
void Graphics::Render(const std::vector<std::shared_ptr<IDrawable>> drawables)
{
if (!renderer) return;
// Clear to black and present (simple stub)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
Draw(drawables);
SDL_RenderPresent(renderer);
}
SDL_Renderer* Graphics::GetRenderer()
{
return renderer;
}
SDL_Window* Graphics::GetWindow()
{
return window;
}
void Graphics::Draw(const std::vector<std::shared_ptr<IDrawable>> drawables)
{
for(const auto& drawable : drawables)
{
drawable->Draw(renderer);
}
}