summaryrefslogtreecommitdiffstats
path: root/video.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--video.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/video.cpp b/video.cpp
index d6ae6cb..f58b171 100644
--- a/video.cpp
+++ b/video.cpp
@@ -10,6 +10,8 @@ extern "C" {
using namespace wrapsdl2;
+/* class window */
+
window::window(const std::string& title, std::size_t width, std::size_t height) {
// create (hidden) window
m_window = SDL_CreateWindow(
@@ -25,26 +27,49 @@ window::window(const std::string& title, std::size_t width, std::size_t height)
throw std::runtime_error("failed to create SDL window");
}
- // create surface
- m_surface = SDL_GetWindowSurface(m_window);
+ // create a rendering contest
+ m_renderer = SDL_CreateRenderer(
+ m_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC
+ );
+
+ // other attributes
+ m_open = false;
}
window::~window() {
- SDL_FreeSurface(m_surface);
- SDL_DestroyWindow(m_window);
+ if (m_renderer != NULL)
+ SDL_DestroyRenderer(m_renderer);
+
+ if (m_window != NULL)
+ SDL_DestroyWindow(m_window);
+}
+
+
+void window::open() {
+ show();
+ m_open = true;
}
+void window::close() {
+ hide();
+ m_open = false;
+}
void window::show() { SDL_ShowWindow(m_window); }
void window::hide() { SDL_HideWindow(m_window); }
void window::raise() { SDL_RaiseWindow(m_window); }
-bool window::visible() {
+bool window::is_open() {
+ return m_open;
+}
+
+bool window::is_visible() {
std::uint32_t flags = SDL_GetWindowFlags(m_window);
return flags & SDL_WINDOW_SHOWN;
}
void window::update() {
- SDL_UpdateWindowSurface(m_window);
+ SDL_RenderClear(m_renderer);
+ SDL_RenderPresent(m_renderer);
} \ No newline at end of file