aboutsummaryrefslogtreecommitdiff
path: root/src/libjin
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-05-19 00:09:44 +0800
committerchai <chaifix@163.com>2018-05-19 00:09:44 +0800
commitbda9d88e84a1dccd4df978205a6ba1f141178b0c (patch)
treeb1a9d20b21583e40e8d58a303deb56fd0644e189 /src/libjin
parentccd8422bbe59143a4c62c9ce96c785f3ac75ce89 (diff)
增加垂直同步
Diffstat (limited to 'src/libjin')
-rw-r--r--src/libjin/render/graphics.h1
-rw-r--r--src/libjin/render/window.cpp28
-rw-r--r--src/libjin/render/window.h11
3 files changed, 18 insertions, 22 deletions
diff --git a/src/libjin/render/graphics.h b/src/libjin/render/graphics.h
index 242b19d..a3125c5 100644
--- a/src/libjin/render/graphics.h
+++ b/src/libjin/render/graphics.h
@@ -34,4 +34,5 @@ namespace render
extern void polygon(RENDER_MODE mode, float* p, int count);
}
}
+
#endif
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
diff --git a/src/libjin/render/window.h b/src/libjin/render/window.h
index f29c82d..515ffff 100644
--- a/src/libjin/render/window.h
+++ b/src/libjin/render/window.h
@@ -20,21 +20,18 @@ namespace render
return (g_wnd ? g_wnd : (g_wnd = new Window()));
}
- inline int Window::getW()
+ inline int getW()
{
return w;
}
- inline int Window::getH()
+ inline int getH()
{
return h;
}
- inline void Window::swapBuffers()
- {
- if (wnd)
- SDL_GL_SwapWindow(wnd);
- }
+ inline void swapBuffers();
+
private:
Window();