aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Graphics')
-rw-r--r--src/libjin/Graphics/Canvas.cpp2
-rw-r--r--src/libjin/Graphics/Texture.cpp4
-rw-r--r--src/libjin/Graphics/Window.cpp16
-rw-r--r--src/libjin/Graphics/Window.h27
4 files changed, 27 insertions, 22 deletions
diff --git a/src/libjin/Graphics/Canvas.cpp b/src/libjin/Graphics/Canvas.cpp
index dddc889..f5bd09f 100644
--- a/src/libjin/Graphics/Canvas.cpp
+++ b/src/libjin/Graphics/Canvas.cpp
@@ -109,7 +109,7 @@ namespace graphics
cur = 0;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
- WindowSystem* wnd = WindowSystem::get();
+ Window* wnd = Window::get();
int ww = wnd->getW(),
wh = wnd->getH();
diff --git a/src/libjin/Graphics/Texture.cpp b/src/libjin/Graphics/Texture.cpp
index 7349c36..4c6707d 100644
--- a/src/libjin/Graphics/Texture.cpp
+++ b/src/libjin/Graphics/Texture.cpp
@@ -5,13 +5,15 @@
#include "texture.h"
#include "../3rdparty/stb/stb_image.h"
#include "../utils/utils.h"
-#include "../math/math.h"
+#include "../Math/Math.h"
namespace jin
{
namespace graphics
{
+ using namespace jin::math;
+
Texture* Texture::createTexture(const char* file)
{
std::ifstream fs;
diff --git a/src/libjin/Graphics/Window.cpp b/src/libjin/Graphics/Window.cpp
index 28e5b84..708a30f 100644
--- a/src/libjin/Graphics/Window.cpp
+++ b/src/libjin/Graphics/Window.cpp
@@ -14,17 +14,19 @@ namespace jin
namespace graphics
{
- bool WindowSystem::initSystem(const SettingBase* s)
+ bool Window::initSystem(const SettingBase* s)
{
+#if JIN_DEBUG
Loghelper::log(Loglevel::LV_INFO, "Init window system");
+#endif // JIN_DEBUG
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return false;
const Setting* setting = (Setting*)s;
-
width = setting->width;
height = setting->height;
+ fps = setting->fps;
bool vsync = setting->vsync;
const char* title = setting->title;
@@ -52,8 +54,12 @@ namespace graphics
int wx = SDL_WINDOWPOS_UNDEFINED,
wy = SDL_WINDOWPOS_UNDEFINED;
+
+ int flag = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
+ if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
+ if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
- wnd = SDL_CreateWindow(title, wx, wy, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
+ wnd = SDL_CreateWindow(title, wx, wy, width, height, flag);
if (wnd == NULL)
return false;
ctx = SDL_GL_CreateContext(wnd);
@@ -73,13 +79,13 @@ namespace graphics
return true;
}
- void WindowSystem::quitSystem()
+ void Window::quitSystem()
{
SDL_DestroyWindow(wnd);
SDL_Quit();
}
- inline void WindowSystem::swapBuffers()
+ inline void Window::swapBuffers()
{
if (wnd)
SDL_GL_SwapWindow(wnd);
diff --git a/src/libjin/Graphics/Window.h b/src/libjin/Graphics/Window.h
index 6213cee..e09e9f9 100644
--- a/src/libjin/Graphics/Window.h
+++ b/src/libjin/Graphics/Window.h
@@ -12,40 +12,37 @@ namespace jin
namespace graphics
{
- class WindowSystem : public Subsystem<WindowSystem>
+ class Window : public Subsystem<Window>
{
public:
struct Setting : SettingBase
{
public:
+ const char* title; //
+ bool fullscreen; // ȫ
int width, height; // ڴС
bool vsync; // ֱͬ
- const char* title; //
+ int fps; // FPS
+ bool resizable; // resize
};
- inline int getW()
- {
- return width;
- }
-
- inline int getH()
- {
- return height;
- }
-
+ inline int getW(){ return width; }
+ inline int getH(){ return height; }
+ inline int getFPS(){ return fps; }
inline void swapBuffers();
private:
- WindowSystem() {};
- virtual ~WindowSystem() {};
+ Window() {};
+ virtual ~Window() {};
- SINGLETON(WindowSystem);
+ SINGLETON(Window);
SDL_Window* wnd;
int width, height;
+ int fps;
onlyonce bool initSystem(const SettingBase* setting) override;
onlyonce void quitSystem() override;