Przeglądaj źródła

Improved imgui integration. Colors still seem wrong!

Thomas Buck 9 lat temu
rodzic
commit
874288c38d
4 zmienionych plików z 32 dodań i 22 usunięć
  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 Wyświetl plik

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

+ 20
- 12
src/Debug.cpp Wyświetl plik

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

+ 7
- 7
src/Window.cpp Wyświetl plik

30
     //printf("GL Version : %s\n", glGetString(GL_VERSION));
30
     //printf("GL Version : %s\n", glGetString(GL_VERSION));
31
 
31
 
32
     // Testing for goodies
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
         //! \todo MultiTexture flag
35
         //! \todo MultiTexture flag
36
         //if (strstr(s, "GL_ARB_multitexture"))
36
         //if (strstr(s, "GL_ARB_multitexture"))
37
             //mFlags |= Render::fMultiTexture;
37
             //mFlags |= Render::fMultiTexture;
38
-    }
38
+    //}
39
 
39
 
40
     // Set up Z buffer
40
     // Set up Z buffer
41
     glEnable(GL_DEPTH_TEST);
41
     glEnable(GL_DEPTH_TEST);
84
 
84
 
85
     glDisable(GL_NORMALIZE);
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
     glPolygonMode(GL_FRONT, GL_FILL);
92
     glPolygonMode(GL_FRONT, GL_FILL);
93
 
93
 

+ 3
- 3
src/main.cpp Wyświetl plik

217
     // Get keyboard and mouse input
217
     // Get keyboard and mouse input
218
     getWindow().eventHandling();
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
     // Render everything
224
     // Render everything
225
     UI::passDisplay();
225
     UI::passDisplay();

Ładowanie…
Anuluj
Zapisz