소스 검색

Improved imgui integration. Colors still seem wrong!

Thomas Buck 9 년 전
부모
커밋
874288c38d
4개의 변경된 파일32개의 추가작업 그리고 22개의 파일을 삭제
  1. 2
    0
      include/Debug.h
  2. 20
    12
      src/Debug.cpp
  3. 7
    7
      src/Window.cpp
  4. 3
    3
      src/main.cpp

+ 2
- 0
include/Debug.h 파일 보기

@@ -29,6 +29,8 @@ private:
29 29
     static void renderImGui(ImDrawList** const draw_lists, int count);
30 30
 
31 31
     static unsigned int fontTex;
32
+    std::string iniFilename;
33
+    std::string logFilename;
32 34
 };
33 35
 
34 36
 Debug &getDebug();

+ 20
- 12
src/Debug.cpp 파일 보기

@@ -5,10 +5,9 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
-#include <algorithm>
9
-
10 8
 #include "global.h"
11 9
 #include "Debug.h"
10
+#include "RunTime.h"
12 11
 #include "TextureManager.h"
13 12
 #include "Window.h"
14 13
 
@@ -24,14 +23,22 @@ Debug::Debug() {
24 23
 }
25 24
 
26 25
 Debug::~Debug() {
26
+    // TODO Segfaults...?
27
+    //ImGui::Shutdown();
28
+
27 29
     UI::removeWindow(this);
28 30
 }
29 31
 
30 32
 int Debug::initialize() {
33
+    iniFilename = getRunTime().getBaseDir() + "/imgui.ini";
34
+    logFilename = getRunTime().getBaseDir() + "/imgui_log.txt";
35
+
31 36
     ImGuiIO& io = ImGui::GetIO();
32 37
     io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
33 38
     io.DeltaTime = 1.0f/60.0f;
34
-    io.PixelCenterOffset = 0.0f;
39
+
40
+    io.IniFilename = iniFilename.c_str();
41
+    io.LogFilename = logFilename.c_str();
35 42
 
36 43
     io.KeyMap[ImGuiKey_Tab] = tabKey;
37 44
     io.KeyMap[ImGuiKey_LeftArrow] = leftKey;
@@ -75,6 +82,10 @@ void Debug::display() {
75 82
 }
76 83
 
77 84
 void Debug::eventsFinished() {
85
+    ImGuiIO& io = ImGui::GetIO();
86
+    io.DisplaySize = ImVec2((float)getWindow().getWidth(), (float)getWindow().getHeight());
87
+    io.DeltaTime = 1.0f / 60.0f; // TODO proper timing
88
+
78 89
     ImGui::NewFrame();
79 90
 }
80 91
 
@@ -125,19 +136,16 @@ void Debug::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
125 136
 
126 137
     getWindow().glEnter2D();
127 138
 
128
-    glDisable(GL_CULL_FACE);
129 139
     glDisable(GL_DEPTH_TEST);
130 140
     glEnable(GL_SCISSOR_TEST);
131
-    //glEnableClientState(GL_VERTEX_ARRAY);
141
+
142
+    glEnableClientState(GL_VERTEX_ARRAY);
132 143
     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
133 144
     glEnableClientState(GL_COLOR_ARRAY);
134 145
 
135 146
     // Setup texture
136 147
     getTextureManager().bindTextureId(fontTex);
137 148
 
138
-    const float width = ImGui::GetIO().DisplaySize.x;
139
-    const float height = ImGui::GetIO().DisplaySize.y;
140
-
141 149
     // Render command lists
142 150
     for (int n = 0; n < cmd_lists_count; n++) {
143 151
         const ImDrawList* cmd_list = cmd_lists[n];
@@ -149,7 +157,7 @@ void Debug::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
149 157
         int vtx_offset = 0;
150 158
         const ImDrawCmd* pcmd_end = cmd_list->commands.end();
151 159
         for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) {
152
-            glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w),
160
+            glScissor((int)pcmd->clip_rect.x, (int)(ImGui::GetIO().DisplaySize.y - pcmd->clip_rect.w),
153 161
                     (int)(pcmd->clip_rect.z - pcmd->clip_rect.x),
154 162
                     (int)(pcmd->clip_rect.w - pcmd->clip_rect.y));
155 163
             glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count);
@@ -157,12 +165,12 @@ void Debug::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
157 165
         }
158 166
     }
159 167
 
160
-    glEnable(GL_CULL_FACE);
161 168
     glEnable(GL_DEPTH_TEST);
162 169
     glDisable(GL_SCISSOR_TEST);
163
-    glDisableClientState(GL_COLOR_ARRAY);
170
+
171
+    glDisableClientState(GL_VERTEX_ARRAY);
164 172
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
165
-    //glDisableClientState(GL_VERTEX_ARRAY);
173
+    glDisableClientState(GL_COLOR_ARRAY);
166 174
 
167 175
     getWindow().glExit2D();
168 176
 }

+ 7
- 7
src/Window.cpp 파일 보기

@@ -30,12 +30,12 @@ int Window::initializeGL() {
30 30
     //printf("GL Version : %s\n", glGetString(GL_VERSION));
31 31
 
32 32
     // Testing for goodies
33
-    const char *s = (const char *)glGetString(GL_EXTENSIONS);
34
-    if ((s != NULL) && (s[0] != '\0')) {
33
+    //const char *s = (const char *)glGetString(GL_EXTENSIONS);
34
+    //if ((s != NULL) && (s[0] != '\0')) {
35 35
         //! \todo MultiTexture flag
36 36
         //if (strstr(s, "GL_ARB_multitexture"))
37 37
             //mFlags |= Render::fMultiTexture;
38
-    }
38
+    //}
39 39
 
40 40
     // Set up Z buffer
41 41
     glEnable(GL_DEPTH_TEST);
@@ -84,10 +84,10 @@ int Window::initializeGL() {
84 84
 
85 85
     glDisable(GL_NORMALIZE);
86 86
 
87
-    glEnableClientState(GL_VERTEX_ARRAY);
88
-    glDisableClientState(GL_EDGE_FLAG_ARRAY);
89
-    glDisableClientState(GL_COLOR_ARRAY);
90
-    glDisableClientState(GL_NORMAL_ARRAY);
87
+    //glEnableClientState(GL_VERTEX_ARRAY);
88
+    //glDisableClientState(GL_EDGE_FLAG_ARRAY);
89
+    //glDisableClientState(GL_COLOR_ARRAY);
90
+    //glDisableClientState(GL_NORMAL_ARRAY);
91 91
 
92 92
     glPolygonMode(GL_FRONT, GL_FILL);
93 93
 

+ 3
- 3
src/main.cpp 파일 보기

@@ -217,9 +217,9 @@ void renderFrame() {
217 217
     // Get keyboard and mouse input
218 218
     getWindow().eventHandling();
219 219
 
220
-    ImGui::SetNewWindowDefaultPos(ImVec2(50, 50));
221
-    bool show_test_window = false;
222
-    ImGui::ShowTestWindow(&show_test_window);
220
+    ImGui::ShowTestWindow();
221
+    ImGui::ShowStyleEditor();
222
+    //ImGui::ShowUserGuide();
223 223
 
224 224
     // Render everything
225 225
     UI::passDisplay();

Loading…
취소
저장