aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/je_window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/je_window.cpp')
-rw-r--r--src/libjin/graphics/je_window.cpp154
1 files changed, 77 insertions, 77 deletions
diff --git a/src/libjin/graphics/je_window.cpp b/src/libjin/graphics/je_window.cpp
index 6572304..3260e14 100644
--- a/src/libjin/graphics/je_window.cpp
+++ b/src/libjin/graphics/je_window.cpp
@@ -17,57 +17,57 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
-
- bool Window::startSystem(const SettingBase* s)
- {
- jin_log_info("Initialize window system.");
-
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
- return false;
-
- const Setting* setting = (Setting*)s;
- mSize.w = setting->width;
+ namespace Graphics
+ {
+
+ bool Window::startSystem(const SettingBase* s)
+ {
+ jin_log_info("Initialize window system.");
+
+ if (SDL_Init(SDL_INIT_VIDEO) < 0)
+ return false;
+
+ const Setting* setting = (Setting*)s;
+ mSize.w = setting->width;
mSize.h = setting->height;
- mFps = setting->fps;
- bool vsync = setting->vsync;
- const char* title = setting->title;
+ mFps = setting->fps;
+ bool vsync = setting->vsync;
+ const char* title = setting->title;
const char* icon = setting->icon;
- if (mWnd)
- {
- SDL_DestroyWindow(mWnd);
- SDL_FlushEvent(SDL_WINDOWEVENT);
- }
-
- SDL_GLContext ctx = NULL;
-
- if (ctx)
- {
- SDL_GL_DeleteContext(ctx);
- }
-
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ if (mWnd)
+ {
+ SDL_DestroyWindow(mWnd);
+ SDL_FlushEvent(SDL_WINDOWEVENT);
+ }
+
+ SDL_GLContext ctx = NULL;
+
+ if (ctx)
+ {
+ SDL_GL_DeleteContext(ctx);
+ }
+
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
- int wx = SDL_WINDOWPOS_UNDEFINED,
- wy = SDL_WINDOWPOS_UNDEFINED;
+ int wx = SDL_WINDOWPOS_UNDEFINED,
+ wy = SDL_WINDOWPOS_UNDEFINED;
- int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
- if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
- if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
+ int flag = SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL;
+ if (setting->fullscreen) flag |= SDL_WINDOW_FULLSCREEN;
+ if (setting->resizable) flag |= SDL_WINDOW_RESIZABLE;
mWnd = SDL_CreateWindow(title, wx, wy, mSize.w, mSize.h, flag);
- if (mWnd == NULL)
- return false;
+ if (mWnd == NULL)
+ return false;
// Set window icon.
try
@@ -82,49 +82,49 @@ namespace JinEngine
SDL_FreeSurface(surface);
} catch (...) {}
- ctx = SDL_GL_CreateContext(mWnd);
- if (ctx == NULL)
- return false;
- SDL_GL_SetSwapInterval(vsync ? 1 : 0);
- SDL_GL_MakeCurrent(mWnd, ctx);
- // Default configuration.
- gl.setClearColor(0, 0, 0, 0xff);
+ ctx = SDL_GL_CreateContext(mWnd);
+ if (ctx == NULL)
+ return false;
+ SDL_GL_SetSwapInterval(vsync ? 1 : 0);
+ SDL_GL_MakeCurrent(mWnd, ctx);
+ // Default configuration.
+ gl.setClearColor(0, 0, 0, 0xff);
glClear(GL_COLOR_BUFFER_BIT);
gl.setColor(0xff, 0xff, 0xff, 0xff);
- gl.enable(GL_BLEND);
- gl.enable(GL_TEXTURE_2D);
+ gl.enable(GL_BLEND);
+ gl.enable(GL_TEXTURE_2D);
// Default blend function.
gl.setBlendMode(OpenGL::BlendMode::ALPHA);
- // Bind to default canvas.
+ // Bind to default canvas.
gl.unbindCanvas();
gl.unuseShader();
- return true;
- }
+ return true;
+ }
- void Window::quitSystem()
- {
+ void Window::quitSystem()
+ {
jin_log_info("Quit window system.");
- // disable opengl
- gl.disable(GL_BLEND);
- gl.disable(GL_TEXTURE_2D);
- // close window
- SDL_DestroyWindow(mWnd);
- SDL_Quit();
- }
-
- void Window::swapBuffers()
- {
- if (mWnd)
- SDL_GL_SwapWindow(mWnd);
- }
-
- void Window::setTitle(const char* title)
- {
- SDL_SetWindowTitle(mWnd, title);
- };
-
- } // namespace Graphics
+ // disable opengl
+ gl.disable(GL_BLEND);
+ gl.disable(GL_TEXTURE_2D);
+ // close window
+ SDL_DestroyWindow(mWnd);
+ SDL_Quit();
+ }
+
+ void Window::swapBuffers()
+ {
+ if (mWnd)
+ SDL_GL_SwapWindow(mWnd);
+ }
+
+ void Window::setTitle(const char* title)
+ {
+ SDL_SetWindowTitle(mWnd, title);
+ };
+
+ } // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics) \ No newline at end of file