diff options
author | chai <chaifix@163.com> | 2021-10-30 22:59:42 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-30 22:59:42 +0800 |
commit | 26f05c6e3dcac9995345fb5a2b031be7e3ea79e9 (patch) | |
tree | fc32c3e9d235817df0be331a6100b7f8263facab /Editor | |
parent | c3e259f4d29e9bdcb73617ad8e4d71f117b4d289 (diff) |
*TextGenerator
Diffstat (limited to 'Editor')
-rw-r--r-- | Editor/EditorMain.cpp | 28 | ||||
-rw-r--r-- | Editor/GUI/ContainerWindow.cpp | 19 | ||||
-rw-r--r-- | Editor/GUI/EditorWindows.h | 4 | ||||
-rw-r--r-- | Editor/GUI/GUIWindow.cpp | 18 | ||||
-rw-r--r-- | Editor/Graphics/Graphics.cpp | 2 | ||||
-rw-r--r-- | Editor/Graphics/Graphics.h | 2 |
6 files changed, 41 insertions, 32 deletions
diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index 69c1c1a..e31da28 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -9,6 +9,8 @@ #include "Editor/Win/Win.h"
#include "Runtime/Threading/Thread.h"
+#include "Runtime/GUI/TextGenerator.h"
+
using namespace LuaBind;
void ErrorHandle(cc8* msg)
@@ -16,6 +18,27 @@ void ErrorHandle(cc8* msg) log_error(std::string("[Lua] ") + msg);
}
+void TestFont()
+{
+ TextGeneratingSettings setting;
+ setting.margin = 5;
+ setting.padding = 3;
+ setting.atlasSize = Internal::Vector2(256, 256);
+ TextGenerator::Instance()->Setup(setting);
+ TextGenerator::Instance()->RenderCharacter(L'好', 14);
+ TextGenerator::Instance()->RenderCharacter(L'大', 14);
+ TextGenerator::Instance()->RenderCharacter(L'家', 14);
+ TextGenerator::Instance()->RenderCharacter(L'晚', 14);
+ TextGenerator::Instance()->RenderCharacter(L'上', 14);
+ TextGenerator::Instance()->RenderCharacter(L'快', 14);
+}
+
+int BeforeMainLoop(lua_State* L)
+{
+ TestFont();
+ return 0;
+}
+
void InitLuaState(LuaBind::VM& vm)
{
vm.Setup();
@@ -35,6 +58,9 @@ void InitLuaState(LuaBind::VM& vm) Win::SetDllSearchDirectory(workingDir);
LuaBind::State state = vm.GetMainState();
+ state.PushGlobalNamespace();
+ state.RegisterMethod("BeforeMainLoop", BeforeMainLoop);
+
state.DoFile("./boot.lua");
}
@@ -50,4 +76,4 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) InitLuaState(vm);
return 0;
-}
\ No newline at end of file +}
diff --git a/Editor/GUI/ContainerWindow.cpp b/Editor/GUI/ContainerWindow.cpp index 62c6cb7..01bb1e9 100644 --- a/Editor/GUI/ContainerWindow.cpp +++ b/Editor/GUI/ContainerWindow.cpp @@ -196,8 +196,8 @@ void ContainerWindow::DoPaint() void ContainerWindow::SetAsRenderContext() { Assert(m_DC != NULL); - Assert(m_RC != NULL); - Assert(wglMakeCurrent(m_DC, m_RC)); + Assert(g_GLRC != NULL); + Assert(wglMakeCurrent(m_DC, g_GLRC)); RECT rect; GetWindowRect(m_Window, &rect); glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top); @@ -256,16 +256,15 @@ bool ContainerWindow::SetRenderContext() int pf = 0; DescribePixelFormat(m_DC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - if (!(m_RC = wglCreateContext(m_DC))) // Are We Able To Get A Rendering Context? - { - MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); - return FALSE; // Return FALSE - } - - if (m_RC && !g_IsGLInitialized) + if (g_GLRC == NULL || !g_IsGLInitialized) { + if (!(g_GLRC = wglCreateContext(m_DC))) // Are We Able To Get A Rendering Context? + { + MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return FALSE; // Return FALSE + } log_info("Initialize OpenGL"); - wglMakeCurrent(m_DC, m_RC); + wglMakeCurrent(m_DC, g_GLRC); if (!gladLoadGL()) { log_error("初始化GL错误"); } diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h index 79e047c..e1ad89a 100644 --- a/Editor/GUI/EditorWindows.h +++ b/Editor/GUI/EditorWindows.h @@ -67,7 +67,6 @@ public: GET(HWND, WindowHandle, m_Window); GET(HDC, DC, m_DC); - GET(HGLRC, RC, m_RC); void OnRectChanged(); void OnActivateApplication(bool active); @@ -79,7 +78,6 @@ private: HWND m_Window; HDC m_DC; - HGLRC m_RC; POINT m_Size; ShowMode m_ShowMode; // 窗口类型 bool m_IsClosing; @@ -149,7 +147,6 @@ public: GET_SET(std::string, Name, m_Name); GET(HDC, DC, m_DC); - GET(HGLRC, RC, m_RC); private: void ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam); @@ -160,7 +157,6 @@ private: ContainerWindow* m_ContainerWindow; HWND m_Handle; HDC m_DC; - HGLRC m_RC; std::vector<LuaBind::MemberRef> m_EditorWindows; diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp index fddc68d..eb44647 100644 --- a/Editor/GUI/GUIWindow.cpp +++ b/Editor/GUI/GUIWindow.cpp @@ -293,21 +293,6 @@ bool GUIWindow::SetRenderContext() int pf = 0; DescribePixelFormat(m_DC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - if (!(m_RC = wglCreateContext(m_DC))) // Are We Able To Get A Rendering Context? - { - MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); - return FALSE; // Return FALSE - } - - if (m_RC && !g_IsGLInitialized) - { - log_info("Initialize OpenGL"); - wglMakeCurrent(m_DC, m_RC); - if (!gladLoadGL()) { - log_error("初始化GL错误"); - } - g_IsGLInitialized = true; - } return true; } @@ -345,8 +330,7 @@ void GUIWindow::SetPosition(Internal::Rect position) void GUIWindow::SetAsRenderContext() { Assert(m_DC != NULL); - Assert(m_RC != NULL); - Assert(wglMakeCurrent(m_DC, m_RC)); + Assert(wglMakeCurrent(m_DC, g_GLRC)); RECT rect; GetWindowRect(m_Handle, &rect); glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top); diff --git a/Editor/Graphics/Graphics.cpp b/Editor/Graphics/Graphics.cpp index af48d75..4c9465f 100644 --- a/Editor/Graphics/Graphics.cpp +++ b/Editor/Graphics/Graphics.cpp @@ -1,3 +1,5 @@ #include "Graphics.h"
bool g_IsGLInitialized = false;
+
+HGLRC g_GLRC = NULL;
\ No newline at end of file diff --git a/Editor/Graphics/Graphics.h b/Editor/Graphics/Graphics.h index ad27ede..f32246a 100644 --- a/Editor/Graphics/Graphics.h +++ b/Editor/Graphics/Graphics.h @@ -1,3 +1,5 @@ #pragma once
+#include <windows.h>
extern bool g_IsGLInitialized;
+extern HGLRC g_GLRC;
\ No newline at end of file |