Bläddra i källkod

Can show font bounding box

Thomas Buck 9 år sedan
förälder
incheckning
18b8317e42
7 ändrade filer med 65 tillägg och 6 borttagningar
  1. 3
    0
      ChangeLog.md
  2. 6
    0
      include/system/Font.h
  3. 2
    1
      include/system/Shader.h
  4. 2
    2
      src/Console.cpp
  5. 6
    0
      src/Render.cpp
  6. 41
    0
      src/system/Font.cpp
  7. 5
    3
      src/system/Shader.cpp

+ 3
- 0
ChangeLog.md Visa fil

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

+ 6
- 0
include/system/Font.h Visa fil

@@ -34,9 +34,15 @@ class Font {
34 34
     static void drawTextCentered(unsigned int x, unsigned int y, float scale,
35 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 40
   private:
41
+    static void drawFontBox(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
42
+
38 43
     static bool isInit;
39 44
     static std::string fontName;
45
+    static bool showFontBox;
40 46
 };
41 47
 
42 48
 #endif

+ 2
- 1
include/system/Shader.h Visa fil

@@ -57,7 +57,8 @@ class Shader {
57 57
     static void set2DState(bool on);
58 58
 
59 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 63
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
63 64
                        TextureStorage store = TextureStorage::GAME, Shader& shader = textureShader);

+ 2
- 2
src/Console.cpp Visa fil

@@ -79,7 +79,7 @@ void Console::display() {
79 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 83
         ImGui::Checkbox("Error##log", &visibleLogs[1]);
84 84
         ImGui::SameLine();
85 85
         ImGui::Checkbox("Warning##log", &visibleLogs[2]);
@@ -125,7 +125,7 @@ void Console::display() {
125 125
             }
126 126
 
127 127
             ImGui::PushStyleColor(ImGuiCol_Text, col);
128
-            ImGui::TextUnformatted(entry.text.c_str());
128
+            ImGui::TextWrapped("%s", entry.text.c_str());
129 129
             ImGui::PopStyleColor();
130 130
         }
131 131
         if (logToTTY || logToClipboard || logToFile) {

+ 6
- 0
src/Render.cpp Visa fil

@@ -14,6 +14,7 @@
14 14
 #include "Log.h"
15 15
 #include "StaticMesh.h"
16 16
 #include "World.h"
17
+#include "system/Font.h"
17 18
 #include "system/Shader.h"
18 19
 #include "system/Window.h"
19 20
 #include "Render.h"
@@ -213,6 +214,11 @@ void Render::displayUI() {
213 214
         if (ImGui::Checkbox("StaticMesh##bbox", &showBoundingBox2)) {
214 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 223
         ImGui::Separator();
218 224
         ImGui::Text("Renderable Objects:");

+ 41
- 0
src/system/Font.cpp Visa fil

@@ -5,16 +5,20 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include <vector>
9
+
8 10
 #include "global.h"
9 11
 #include "Log.h"
10 12
 #include "utils/strings.h"
11 13
 #include "system/FontImGui.h"
12 14
 #include "system/FontTRLE.h"
13 15
 #include "system/FontTTF.h"
16
+#include "system/Shader.h"
14 17
 #include "system/Font.h"
15 18
 
16 19
 bool Font::isInit = false;
17 20
 std::string Font::fontName;
21
+bool Font::showFontBox = false;
18 22
 
19 23
 void Font::shutdown() {
20 24
     FontTRLE::shutdown();
@@ -66,6 +70,12 @@ void Font::drawText(unsigned int x, unsigned int y, float scale,
66 70
     } else {
67 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 81
 void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
@@ -77,6 +87,14 @@ void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
77 87
     } else {
78 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 100
 void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
@@ -84,3 +102,26 @@ void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
84 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 Visa fil

@@ -235,9 +235,11 @@ void Shader::set2DState(bool on) {
235 235
 }
236 236
 
237 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 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 244
     shader.use();
243 245
     shader.loadUniform(0, Window::getSize());
@@ -247,7 +249,7 @@ void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
247 249
     uvs.bindBuffer(1, 2);
248 250
 
249 251
     set2DState(true);
250
-    glDrawArrays(GL_TRIANGLES, 0, vertices.getSize());
252
+    glDrawArrays(mode, 0, vertices.getSize());
251 253
     set2DState(false);
252 254
 
253 255
     vertices.unbind(0);

Laddar…
Avbryt
Spara