.. _program_listing_file_gui_Demeter_Renderer_SDL2.hpp: Program Listing for File SDL2.hpp ================================= |exhale_lsh| :ref:`Return to documentation for file ` (``gui/Demeter/Renderer/SDL2.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include #include #include #include #include "SDL_timer.h" struct SDL2 { private: bool _isSDLInit = false; bool _isIMGInit = false; SDL_Window *_window; SDL_GLContext _context = nullptr; SDL_Event _event; size_t _width; size_t _height; void SetAttribute(SDL_GLattr attr, int value) const // NOLINT { SDL_GL_SetAttribute(attr, value); } public: SDL2() = default; ~SDL2(); bool Init(size_t width = 800, size_t height = 600); void SetWindowSize(size_t width, size_t height) { _width = width; _height = height; glViewport(0, 0, (GLsizei)_width, (GLsizei)_height); } [[nodiscard]] size_t GetWidth() const { return _width; } [[nodiscard]] size_t GetHeight() const { return _height; } std::string GetError() const // NOLINT { return SDL_GetError(); } std::string GetIMGError() const // NOLINT { return IMG_GetError(); } void SwapWindow() const { SDL_GL_SwapWindow(_window); } void Clear(GLclampf r, GLclampf g, GLclampf b, GLclampf a) const // NOLINT { glClearColor(r, g, b, a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } [[nodiscard]] Uint64 GetTicks64() const // NOLINT { return SDL_GetTicks64(); } [[nodiscard]] bool PollEvent() { return SDL_PollEvent(&_event); } [[nodiscard]] const SDL_Event &GetEvent() const { return _event; } [[nodiscard]] std::unique_ptr IMGLoad(const std::string &s) const // NOLINT { return std::unique_ptr(IMG_Load(s.c_str())); } };