Pārlūkot izejas kodu

Can show font bounding box

Thomas Buck 9 gadus atpakaļ
vecāks
revīzija
18b8317e42

+ 3
- 0
ChangeLog.md Parādīt failu

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20140118 ]
6
+    * Added ability to visualize font _outline_
7
+
5
     [ 20140117 ]
8
     [ 20140117 ]
6
     * Updated imgui, fix for Logging to Clipboard included.
9
     * Updated imgui, fix for Logging to Clipboard included.
7
     * Sprites and SpriteSequences are now stored independently in World.
10
     * Sprites and SpriteSequences are now stored independently in World.

+ 6
- 0
include/system/Font.h Parādīt failu

34
     static void drawTextCentered(unsigned int x, unsigned int y, float scale,
34
     static void drawTextCentered(unsigned int x, unsigned int y, float scale,
35
                                  const unsigned char color[4], unsigned int width, std::string s);
35
                                  const unsigned char color[4], unsigned int width, std::string s);
36
 
36
 
37
+    static void setShowFontBox(bool s) { showFontBox = s; }
38
+    static bool getShowFontBox() { return showFontBox; }
39
+
37
   private:
40
   private:
41
+    static void drawFontBox(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
42
+
38
     static bool isInit;
43
     static bool isInit;
39
     static std::string fontName;
44
     static std::string fontName;
45
+    static bool showFontBox;
40
 };
46
 };
41
 
47
 
42
 #endif
48
 #endif

+ 2
- 1
include/system/Shader.h Parādīt failu

57
     static void set2DState(bool on);
57
     static void set2DState(bool on);
58
 
58
 
59
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
59
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
60
-                       TextureStorage store = TextureStorage::SYSTEM, Shader& shader = textShader);
60
+                       TextureStorage store = TextureStorage::SYSTEM, unsigned int mode = GL_TRIANGLES,
61
+                       Shader& shader = textShader);
61
 
62
 
62
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
63
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
63
                        TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);
64
                        TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);

+ 2
- 2
src/Console.cpp Parādīt failu

79
             scrollToBottom = true;
79
             scrollToBottom = true;
80
         }
80
         }
81
 
81
 
82
-        static bool visibleLogs[LOG_COUNT] = { true, true, true, true, false };
82
+        static bool visibleLogs[LOG_COUNT] = { true, true, true, true, true };
83
         ImGui::Checkbox("Error##log", &visibleLogs[1]);
83
         ImGui::Checkbox("Error##log", &visibleLogs[1]);
84
         ImGui::SameLine();
84
         ImGui::SameLine();
85
         ImGui::Checkbox("Warning##log", &visibleLogs[2]);
85
         ImGui::Checkbox("Warning##log", &visibleLogs[2]);
125
             }
125
             }
126
 
126
 
127
             ImGui::PushStyleColor(ImGuiCol_Text, col);
127
             ImGui::PushStyleColor(ImGuiCol_Text, col);
128
-            ImGui::TextUnformatted(entry.text.c_str());
128
+            ImGui::TextWrapped("%s", entry.text.c_str());
129
             ImGui::PopStyleColor();
129
             ImGui::PopStyleColor();
130
         }
130
         }
131
         if (logToTTY || logToClipboard || logToFile) {
131
         if (logToTTY || logToClipboard || logToFile) {

+ 6
- 0
src/Render.cpp Parādīt failu

14
 #include "Log.h"
14
 #include "Log.h"
15
 #include "StaticMesh.h"
15
 #include "StaticMesh.h"
16
 #include "World.h"
16
 #include "World.h"
17
+#include "system/Font.h"
17
 #include "system/Shader.h"
18
 #include "system/Shader.h"
18
 #include "system/Window.h"
19
 #include "system/Window.h"
19
 #include "Render.h"
20
 #include "Render.h"
213
         if (ImGui::Checkbox("StaticMesh##bbox", &showBoundingBox2)) {
214
         if (ImGui::Checkbox("StaticMesh##bbox", &showBoundingBox2)) {
214
             StaticMesh::setShowBoundingBox(showBoundingBox2);
215
             StaticMesh::setShowBoundingBox(showBoundingBox2);
215
         }
216
         }
217
+        ImGui::SameLine();
218
+        bool showFontBox = Font::getShowFontBox();
219
+        if (ImGui::Checkbox("Font##bbox", &showFontBox)) {
220
+            Font::setShowFontBox(showFontBox);
221
+        }
216
 
222
 
217
         ImGui::Separator();
223
         ImGui::Separator();
218
         ImGui::Text("Renderable Objects:");
224
         ImGui::Text("Renderable Objects:");

+ 41
- 0
src/system/Font.cpp Parādīt failu

5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
7
 
7
 
8
+#include <vector>
9
+
8
 #include "global.h"
10
 #include "global.h"
9
 #include "Log.h"
11
 #include "Log.h"
10
 #include "utils/strings.h"
12
 #include "utils/strings.h"
11
 #include "system/FontImGui.h"
13
 #include "system/FontImGui.h"
12
 #include "system/FontTRLE.h"
14
 #include "system/FontTRLE.h"
13
 #include "system/FontTTF.h"
15
 #include "system/FontTTF.h"
16
+#include "system/Shader.h"
14
 #include "system/Font.h"
17
 #include "system/Font.h"
15
 
18
 
16
 bool Font::isInit = false;
19
 bool Font::isInit = false;
17
 std::string Font::fontName;
20
 std::string Font::fontName;
21
+bool Font::showFontBox = false;
18
 
22
 
19
 void Font::shutdown() {
23
 void Font::shutdown() {
20
     FontTRLE::shutdown();
24
     FontTRLE::shutdown();
66
     } else {
70
     } else {
67
         FontImGui::drawText(x, y, scale, color, s);
71
         FontImGui::drawText(x, y, scale, color, s);
68
     }
72
     }
73
+
74
+    if (showFontBox) {
75
+        unsigned int w = widthText(scale, s);
76
+        unsigned int h = heightText(scale, w + 100, s); // Should always be one line
77
+        drawFontBox(x, y, w, h);
78
+    }
69
 }
79
 }
70
 
80
 
71
 void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
81
 void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
77
     } else {
87
     } else {
78
         FontImGui::drawTextWrapped(x, y, scale, color, maxWidth, s);
88
         FontImGui::drawTextWrapped(x, y, scale, color, maxWidth, s);
79
     }
89
     }
90
+
91
+    if (showFontBox) {
92
+        unsigned int w = widthText(scale, s);
93
+        if (w > maxWidth)
94
+            w = maxWidth;
95
+        unsigned int h = heightText(scale, w, s); // Should always be one line
96
+        drawFontBox(x, y, w, h);
97
+    }
80
 }
98
 }
81
 
99
 
82
 void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
100
 void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
84
     drawText(x + ((width / 2) - (widthText(scale, s) / 2)), y, scale, color, s);
102
     drawText(x + ((width / 2) - (widthText(scale, s) / 2)), y, scale, color, s);
85
 }
103
 }
86
 
104
 
105
+void Font::drawFontBox(unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
106
+    static ShaderBuffer vert, uv;
107
+    std::vector<glm::vec2> vertices, uvs;
108
+
109
+    vertices.emplace_back(x, y);
110
+    vertices.emplace_back(x + w, y);
111
+    vertices.emplace_back(x + w, y + h);
112
+    vertices.emplace_back(x, y + h);
113
+    vertices.emplace_back(x, y);
114
+
115
+    uvs.emplace_back(0.0f, 0.0f);
116
+    uvs.emplace_back(1.0f, 0.0f);
117
+    uvs.emplace_back(1.0f, 1.0f);
118
+    uvs.emplace_back(0.0f, 1.0f);
119
+    uvs.emplace_back(0.0f, 0.0f);
120
+
121
+    vert.bufferData(vertices);
122
+    uv.bufferData(uvs);
123
+
124
+    Shader::drawGL(vert, uv, glm::vec4(1.0f, 1.0f, 0.0f, 1.0f), TEXTURE_WHITE,
125
+                   TextureStorage::SYSTEM, GL_LINE_STRIP);
126
+}
127
+

+ 5
- 3
src/system/Shader.cpp Parādīt failu

235
 }
235
 }
236
 
236
 
237
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
237
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
238
-                    unsigned int texture, TextureStorage store, Shader& shader) {
238
+                    unsigned int texture, TextureStorage store, unsigned int mode,
239
+                    Shader& shader) {
239
     assert(vertices.getSize() == uvs.getSize());
240
     assert(vertices.getSize() == uvs.getSize());
240
-    assert((vertices.getSize() % 3) == 0);
241
+    if (mode == GL_TRIANGLES)
242
+        assert((vertices.getSize() % 3) == 0)
241
 
243
 
242
     shader.use();
244
     shader.use();
243
     shader.loadUniform(0, Window::getSize());
245
     shader.loadUniform(0, Window::getSize());
247
     uvs.bindBuffer(1, 2);
249
     uvs.bindBuffer(1, 2);
248
 
250
 
249
     set2DState(true);
251
     set2DState(true);
250
-    glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
252
+    glDrawArrays(mode, 0, vertices.getSize());
251
     set2DState(false);
253
     set2DState(false);
252
 
254
 
253
     vertices.unbind(0);
255
     vertices.unbind(0);

Notiek ielāde…
Atcelt
Saglabāt