aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/render/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/render/window.cpp')
-rw-r--r--src/libjin/render/window.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/libjin/render/window.cpp b/src/libjin/render/window.cpp
index 0d53654..0179877 100644
--- a/src/libjin/render/window.cpp
+++ b/src/libjin/render/window.cpp
@@ -32,40 +32,32 @@ namespace render
{
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);
- Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL ;
-
- int wx = SDL_WINDOWPOS_UNDEFINED,
- wy = SDL_WINDOWPOS_UNDEFINED;
+ int wx = SDL_WINDOWPOS_UNDEFINED,
+ wy = SDL_WINDOWPOS_UNDEFINED;
- /* Create window */
- wnd = SDL_CreateWindow(t, wx, wy, w, h, flags);
-
- // Create an opengl context
+ wnd = SDL_CreateWindow(t, wx, wy, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
ctx = SDL_GL_CreateContext(wnd);
+ // ֱͬ󽵵GPUռ8%->4%
+ SDL_GL_SetSwapInterval(1);
SDL_GL_MakeCurrent(wnd, ctx);
-
- // Default clear color
glClearColor(0.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-
- // Default render color
glColor4f(1, 1, 1, 1);
-
/**
* Set the viewport to top-left corner.
* Bind to the default render buffer.
*/
Canvas::unbind();
-
// Swap window buffer
swapBuffers();
}
@@ -80,5 +72,11 @@ namespace render
return ctx;
}
+ inline void Window::swapBuffers()
+ {
+ if (wnd)
+ SDL_GL_SwapWindow(wnd);
+ }
+
}
} \ No newline at end of file