소스 검색

Using float for font colors. Better controller mapping.

Thomas Buck 9 년 전
부모
커밋
f7cbc216ce

+ 3
- 0
ChangeLog.md 파일 보기

@@ -5,6 +5,9 @@
5 5
     [ 20140306 ]
6 6
     * Fixed LoaderTR1, can now also open the Unfinished Business levels
7 7
     * Walk key can now be used to increase free-camera movement speed
8
+    * Removed color definitions in global.h
9
+    * Font interface now using glm::vec4 float colors
10
+    * Hard-coded controller mapping now supports all available ActionEvents
8 11
 
9 12
     [ 20140305 ]
10 13
     * SoundAL now has more useful error message output.

+ 3
- 0
include/Menu.h 파일 보기

@@ -30,6 +30,9 @@ class Menu {
30 30
 
31 31
     void setVisible(bool v) { visible = v; }
32 32
 
33
+    static const glm::vec4 textColor;
34
+    static const glm::vec4 selectedColor;
35
+
33 36
   protected:
34 37
 
35 38
     virtual void showDialog(std::string msg, std::string btn1, std::string btn2,

+ 2
- 12
include/global.h 파일 보기

@@ -11,18 +11,6 @@
11 11
 
12 12
 void renderFrame();
13 13
 
14
-// Colors used where ever needed
15
-const unsigned char BLACK[]  = {   0,   0,   0, 255 };
16
-const unsigned char GREY[]   = { 128, 128, 128, 255 };
17
-const unsigned char WHITE[]  = { 255, 255, 255, 255 };
18
-const unsigned char RED[]    = { 255,   0,   0, 255 };
19
-const unsigned char GREEN[]  = {   0, 255,   0, 255 };
20
-const unsigned char PURPLE[] = {  77,  77, 128, 255 };
21
-const unsigned char BLUE[]   = { 128, 179, 255, 255 };
22
-const unsigned char PINK[]   = { 255,   0, 255, 255 };
23
-const unsigned char YELLOW[] = { 255, 255,   0, 255 };
24
-const unsigned char CYAN[]   = {   0, 255, 255, 255 };
25
-
26 14
 // Actions that can be bound to a key and sent to the game engine
27 15
 typedef enum {
28 16
     menuAction = 0,
@@ -64,6 +52,8 @@ typedef enum {
64 52
     pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
65 53
     rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
66 54
     semicolonKey, slashKey, spaceKey, tabKey,
55
+
56
+    // Mouse
67 57
     leftmouseKey, middlemouseKey, rightmouseKey,
68 58
     fourthmouseKey, fifthmouseKey,
69 59
 

+ 3
- 3
include/system/Font.h 파일 보기

@@ -26,13 +26,13 @@ class Font {
26 26
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
27 27
 
28 28
     static void drawText(unsigned int x, unsigned int y, float scale,
29
-                         const unsigned char color[4], std::string s);
29
+                         glm::vec4 color, std::string s);
30 30
 
31 31
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
32
-                                const unsigned char color[4], unsigned int maxWidth, std::string s);
32
+                                glm::vec4 color, unsigned int maxWidth, std::string s);
33 33
 
34 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
+                                 glm::vec4 color, unsigned int width, std::string s);
36 36
 
37 37
     static void setShowFontBox(bool s) { showFontBox = s; }
38 38
     static bool getShowFontBox() { return showFontBox; }

+ 2
- 2
include/system/FontImGui.h 파일 보기

@@ -20,10 +20,10 @@ class FontImGui {
20 20
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
21 21
 
22 22
     static void drawText(unsigned int x, unsigned int y, float scale,
23
-                         const unsigned char color[4], std::string s);
23
+                         glm::vec4 color, std::string s);
24 24
 
25 25
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
26
-                                const unsigned char color[4], unsigned int maxWidth, std::string s);
26
+                                glm::vec4 color, unsigned int maxWidth, std::string s);
27 27
 };
28 28
 
29 29
 #endif

+ 2
- 2
include/system/FontTRLE.h 파일 보기

@@ -26,10 +26,10 @@ class FontTRLE {
26 26
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
27 27
 
28 28
     static void drawText(unsigned int x, unsigned int y, float scale,
29
-                         const unsigned char color[4], std::string s);
29
+                         glm::vec4 color, std::string s);
30 30
 
31 31
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
32
-                                const unsigned char color[4], unsigned int maxWidth, std::string s);
32
+                                glm::vec4 color, unsigned int maxWidth, std::string s);
33 33
 
34 34
   private:
35 35
     static void setDefaultOffsets();

+ 3
- 3
include/system/FontTTF.h 파일 보기

@@ -40,15 +40,15 @@ class FontTTF {
40 40
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
41 41
 
42 42
     static void drawText(unsigned int x, unsigned int y, float scale,
43
-                         const unsigned char color[4], std::string s);
43
+                         glm::vec4 color, std::string s);
44 44
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
45
-                                const unsigned char color[4], unsigned int maxWidth, std::string s);
45
+                                glm::vec4 color, unsigned int maxWidth, std::string s);
46 46
 
47 47
   private:
48 48
     static int charIsMapped(int c);
49 49
     static int getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad);
50 50
     static void drawTextInternal(unsigned int x, unsigned int y, float scale,
51
-                                 const unsigned char color[4], unsigned int maxWidth, std::string s,
51
+                                 glm::vec4 color, unsigned int maxWidth, std::string s,
52 52
                                  bool drawWrapped);
53 53
 
54 54
     static unsigned char* fontData;

+ 1
- 1
include/utils/pixel.h 파일 보기

@@ -8,7 +8,7 @@
8 8
 #ifndef _UTILS_PIXEL_H_
9 9
 #define _UTILS_PIXEL_H_
10 10
 
11
-unsigned char* generateColorTexture(const unsigned char* rgba, unsigned int width,
11
+unsigned char* generateColorTexture(glm::vec4 rgba, unsigned int width,
12 12
                                     unsigned int height, unsigned int bpp);
13 13
 
14 14
 void argb2rgba32(unsigned char* image, unsigned int w, unsigned int h);

+ 9
- 6
src/Menu.cpp 파일 보기

@@ -11,6 +11,9 @@
11 11
 #include "system/Font.h"
12 12
 #include "system/Window.h"
13 13
 
14
+const glm::vec4 Menu::textColor(0.5f, 0.7f, 1.0f, 1.0f);
15
+const glm::vec4 Menu::selectedColor(1.0f, 0.0f, 0.0f, 1.0f);
16
+
14 17
 void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
15 18
                       std::function<int (bool state)> callback) {
16 19
     // Only show one dialog at a time
@@ -148,22 +151,22 @@ void Menu::displayDialog() {
148 151
         glEnable(GL_TEXTURE_2D);
149 152
         */
150 153
 
151
-        Font::drawTextWrapped(xOverlay + 10, yOverlay + 5, 1.0f, BLUE, w0, dialogText);
154
+        Font::drawTextWrapped(xOverlay + 10, yOverlay + 5, 1.0f, textColor, w0, dialogText);
152 155
         if (dialogButton2.length() > 0) {
153 156
             if ((w1 + w2) <= wMax) {
154 157
                 Font::drawTextWrapped(xOverlay + 10, yOverlay + 10 + h0, 1.0f,
155
-                                      dialogState ? BLUE : RED, w1, dialogButton1);
158
+                                      dialogState ? textColor : selectedColor, w1, dialogButton1);
156 159
                 Font::drawTextWrapped(xOverlay + 10 + w1, yOverlay + 10 + h0,
157
-                                      1.0f, dialogState ? RED : BLUE, w2, dialogButton2);
160
+                                      1.0f, dialogState ? selectedColor : textColor, w2, dialogButton2);
158 161
             } else {
159 162
                 Font::drawTextWrapped((Window::getSize().x - w1) / 2,
160
-                                      yOverlay + 10 + h0, 1.0f, dialogState ? BLUE : RED, w1, dialogButton1);
163
+                                      yOverlay + 10 + h0, 1.0f, dialogState ? textColor : selectedColor, w1, dialogButton1);
161 164
                 Font::drawTextWrapped((Window::getSize().x - w2) / 2,
162
-                                      yOverlay + 10 + h0 + h1, 1.0f, dialogState ? RED : BLUE, w2, dialogButton2);
165
+                                      yOverlay + 10 + h0 + h1, 1.0f, dialogState ? selectedColor : textColor, w2, dialogButton2);
163 166
             }
164 167
         } else {
165 168
             Font::drawTextWrapped((Window::getSize().x - w1) / 2,
166
-                                  yOverlay + 10 + h0, 1.0f, RED, w1, dialogButton1);
169
+                                  yOverlay + 10 + h0, 1.0f, selectedColor, w1, dialogButton1);
167 170
         }
168 171
     }
169 172
 }

+ 4
- 4
src/MenuFolder.cpp 파일 보기

@@ -79,7 +79,7 @@ void MenuFolder::display() {
79 79
     if (!visible)
80 80
         return;
81 81
 
82
-    Font::drawTextCentered(0, 10, 1.2f, BLUE, Window::getSize().x, VERSION);
82
+    Font::drawTextCentered(0, 10, 1.2f, textColor, Window::getSize().x, VERSION);
83 83
 
84 84
     // Draw half-transparent overlay
85 85
     glm::vec4 color(0.0f, 0.0f, 0.0f, 0.75f);
@@ -87,7 +87,7 @@ void MenuFolder::display() {
87 87
                         color, TEXTURE_WHITE, TextureStorage::SYSTEM);
88 88
 
89 89
     // Draw heading
90
-    Font::drawTextCentered(0, 10, 1.2f, BLUE, Window::getSize().x, VERSION);
90
+    Font::drawTextCentered(0, 10, 1.2f, textColor, Window::getSize().x, VERSION);
91 91
 
92 92
     // Estimate displayable number of items
93 93
     int items = (Window::getSize().y - 60) / 25;
@@ -96,10 +96,10 @@ void MenuFolder::display() {
96 96
     for (long i = mMin; (i < (mMin + items))
97 97
          && (i < (mapFolder->folderCount() + mapFolder->fileCount() + 1)); i++) {
98 98
         if (i == 0) {
99
-            Font::drawText(25, 50, 0.75f, (mCursor == i) ? RED : BLUE, "..");
99
+            Font::drawText(25, 50, 0.75f, (mCursor == i) ? selectedColor : textColor, "..");
100 100
         } else {
101 101
             Font::drawText(25, (unsigned int)(50 + (25 * (i - mMin))), 0.75f,
102
-                           (mCursor == i) ? RED : BLUE,
102
+                           (mCursor == i) ? selectedColor : textColor,
103 103
                            ((i - 1) < mapFolder->folderCount()) ?
104 104
                            (mapFolder->getFolder(i - 1).getName() + "/")
105 105
                            : mapFolder->getFile(i - 1 - mapFolder->folderCount()).getName());

+ 1
- 1
src/TextureManager.cpp 파일 보기

@@ -69,7 +69,7 @@ int TextureManager::initialize() {
69 69
         mTextureIdsSystem.push_back(id);
70 70
     }
71 71
 
72
-    unsigned char* image = generateColorTexture(WHITE, 32, 32, 32);
72
+    unsigned char* image = generateColorTexture(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), 32, 32, 32);
73 73
     int res = loadBufferSlot(image, 32, 32, ColorMode::RGBA, 32, TextureStorage::SYSTEM, TEXTURE_WHITE,
74 74
                              false);
75 75
     delete [] image;

+ 6
- 0
src/UI.cpp 파일 보기

@@ -461,6 +461,10 @@ void UI::handleControllerButton(KeyboardButton button, bool released) {
461 461
             Game::handleAction(jumpAction, released);
462 462
         } else if (button == bButton) {
463 463
             Game::handleAction(crouchAction, released);
464
+        } else if (button == xButton) {
465
+            Game::handleAction(useAction, released);
466
+        } else if (button == yButton) {
467
+            Game::handleAction(holsterAction, released);
464 468
         } else if (button == padUp) {
465 469
             Game::handleAction(forwardAction, released);
466 470
         } else if (button == padDown) {
@@ -469,6 +473,8 @@ void UI::handleControllerButton(KeyboardButton button, bool released) {
469 473
             Game::handleAction(leftAction, released);
470 474
         } else if (button == padRight) {
471 475
             Game::handleAction(rightAction, released);
476
+        } else if (button == leftShoulder) {
477
+            Game::handleAction(walkAction, released);
472 478
         } else if (button == startButton) {
473 479
             if (!released)
474 480
                 getMenu().setVisible(true);

+ 3
- 3
src/system/Font.cpp 파일 보기

@@ -62,7 +62,7 @@ unsigned int Font::heightText(float scale, unsigned int maxWidth, std::string s)
62 62
 }
63 63
 
64 64
 void Font::drawText(unsigned int x, unsigned int y, float scale,
65
-                    const unsigned char color[4], std::string s) {
65
+                    glm::vec4 color, std::string s) {
66 66
     if (stringEndsWith(fontName, ".pc")) {
67 67
         FontTRLE::drawText(x, y, scale, color, s);
68 68
     } else if (stringEndsWith(fontName, ".ttf")) {
@@ -79,7 +79,7 @@ void Font::drawText(unsigned int x, unsigned int y, float scale,
79 79
 }
80 80
 
81 81
 void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
82
-                           const unsigned char color[4], unsigned int maxWidth, std::string s) {
82
+                           glm::vec4 color, unsigned int maxWidth, std::string s) {
83 83
     if (stringEndsWith(fontName, ".pc")) {
84 84
         FontTRLE::drawTextWrapped(x, y, scale, color, maxWidth, s);
85 85
     } else if (stringEndsWith(fontName, ".ttf")) {
@@ -98,7 +98,7 @@ void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
98 98
 }
99 99
 
100 100
 void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
101
-                            const unsigned char color[4], unsigned int width, std::string s) {
101
+                            glm::vec4 color, unsigned int width, std::string s) {
102 102
     drawText(x + ((width / 2) - (widthText(scale, s) / 2)), y, scale, color, s);
103 103
 }
104 104
 

+ 6
- 4
src/system/FontImGui.cpp 파일 보기

@@ -23,11 +23,12 @@ unsigned int FontImGui::widthText(float scale, std::string s) {
23 23
 }
24 24
 
25 25
 void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
26
-                         const unsigned char color[4], std::string s) {
26
+                         glm::vec4 color, std::string s) {
27 27
     ImGuiIO& io = ImGui::GetIO();
28 28
     ImFont* font = io.Fonts->Fonts.at(0);
29 29
     ImVec2 pos = ImVec2(x, y);
30
-    ImU32 col = color[0] | (color[1] << 8) | (color[2] << 16) | (color[3] << 24);
30
+    ImU32 col = (ImU32(color.r * 255)) | (ImU32(color.g * 255) << 8) | (ImU32(color.b * 255) << 16) |
31
+                (ImU32(color.a * 255) << 24);
31 32
 
32 33
     ImDrawList dl;
33 34
     dl.PushTextureID(font->ContainerAtlas->TexID);
@@ -47,11 +48,12 @@ unsigned int FontImGui::heightText(float scale, unsigned int maxWidth, std::stri
47 48
 }
48 49
 
49 50
 void FontImGui::drawTextWrapped(unsigned int x, unsigned int y, float scale,
50
-                                const unsigned char color[4], unsigned int maxWidth, std::string s) {
51
+                                glm::vec4 color, unsigned int maxWidth, std::string s) {
51 52
     ImGuiIO& io = ImGui::GetIO();
52 53
     ImFont* font = io.Fonts->Fonts.at(0);
53 54
     ImVec2 pos = ImVec2(x, y);
54
-    ImU32 col = color[0] | (color[1] << 8) | (color[2] << 16) | (color[3] << 24);
55
+    ImU32 col = (ImU32(color.r * 255)) | (ImU32(color.g * 255) << 8) | (ImU32(color.b * 255) << 16) |
56
+                (ImU32(color.a * 255) << 24);
55 57
 
56 58
     ImDrawList dl;
57 59
     dl.PushTextureID(font->ContainerAtlas->TexID);

+ 4
- 6
src/system/FontTRLE.cpp 파일 보기

@@ -147,7 +147,7 @@ unsigned int FontTRLE::widthText(float scale, std::string s) {
147 147
 }
148 148
 
149 149
 void FontTRLE::drawText(unsigned int x, unsigned int y, float scale,
150
-                        const unsigned char color[4], std::string s) {
150
+                        glm::vec4 color, std::string s) {
151 151
     assert(mFontInit == true);
152 152
     assert(s.length() > 0);
153 153
 
@@ -169,8 +169,7 @@ void FontTRLE::drawText(unsigned int x, unsigned int y, float scale,
169 169
 
170 170
     vertexBuffer.bufferData(vertices);
171 171
     uvBuffer.bufferData(uvs);
172
-    glm::vec4 col(color[0] / 256.0f, color[1] / 256.0f, color[2] / 256.0f, color[3] / 256.0f);
173
-    Shader::drawGL(vertexBuffer, uvBuffer, col, mFontTexture);
172
+    Shader::drawGL(vertexBuffer, uvBuffer, color, mFontTexture);
174 173
 }
175 174
 
176 175
 unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::string s) {
@@ -207,7 +206,7 @@ unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::strin
207 206
 }
208 207
 
209 208
 void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
210
-                               const unsigned char color[4], unsigned int maxWidth, std::string s) {
209
+                               glm::vec4 color, unsigned int maxWidth, std::string s) {
211 210
     assert(mFontInit == true);
212 211
     assert(s.length() > 0);
213 212
 
@@ -245,8 +244,7 @@ void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
245 244
 
246 245
     vertexBuffer.bufferData(vertices);
247 246
     uvBuffer.bufferData(uvs);
248
-    glm::vec4 col(color[0] / 256.0f, color[1] / 256.0f, color[2] / 256.0f, color[3] / 256.0f);
249
-    Shader::drawGL(vertexBuffer, uvBuffer, col, mFontTexture);
247
+    Shader::drawGL(vertexBuffer, uvBuffer, color, mFontTexture);
250 248
 }
251 249
 
252 250
 int FontTRLE::defaultOffsets[106][5] = {

+ 5
- 6
src/system/FontTTF.cpp 파일 보기

@@ -158,7 +158,7 @@ unsigned int FontTTF::widthText(float scale, std::string s) {
158 158
 }
159 159
 
160 160
 void FontTTF::drawText(unsigned int x, unsigned int y, float scale,
161
-                       const unsigned char color[4], std::string s) {
161
+                       glm::vec4 color, std::string s) {
162 162
     drawTextInternal(x, y, scale, color, 0, s, false);
163 163
 }
164 164
 
@@ -180,14 +180,13 @@ unsigned int FontTTF::heightText(float scale, unsigned int maxWidth, std::string
180 180
 }
181 181
 
182 182
 void FontTTF::drawTextWrapped(unsigned int x, unsigned int y, float scale,
183
-                              const unsigned char color[4], unsigned int maxWidth, std::string s) {
183
+                              glm::vec4 color, unsigned int maxWidth, std::string s) {
184 184
     drawTextInternal(x, y, scale, color, maxWidth, s, true);
185 185
 }
186 186
 
187 187
 void FontTTF::drawTextInternal(unsigned int x, unsigned int y, float scale,
188
-                               const unsigned char color[4], unsigned int maxWidth, std::string s,
188
+                               glm::vec4 color, unsigned int maxWidth, std::string s,
189 189
                                bool drawWrapped) {
190
-    glm::vec4 col(color[0] / 256.0f, color[1] / 256.0f, color[2] / 256.0f, color[3] / 256.0f);
191 190
     std::vector<glm::vec2> vertices;
192 191
     std::vector<glm::vec2> uvs;
193 192
     int texture = -1;
@@ -211,7 +210,7 @@ void FontTTF::drawTextInternal(unsigned int x, unsigned int y, float scale,
211 210
         if ((texture != tex) && (texture != -1)) {
212 211
             vertexBuffer.bufferData(vertices);
213 212
             uvBuffer.bufferData(uvs);
214
-            Shader::drawGL(vertexBuffer, uvBuffer, col, texture);
213
+            Shader::drawGL(vertexBuffer, uvBuffer, color, texture);
215 214
             vertices.clear();
216 215
             uvs.clear();
217 216
         }
@@ -240,7 +239,7 @@ void FontTTF::drawTextInternal(unsigned int x, unsigned int y, float scale,
240 239
 
241 240
     vertexBuffer.bufferData(vertices);
242 241
     uvBuffer.bufferData(uvs);
243
-    Shader::drawGL(vertexBuffer, uvBuffer, col, texture);
242
+    Shader::drawGL(vertexBuffer, uvBuffer, color, texture);
244 243
 }
245 244
 
246 245
 int FontTTF::charIsMapped(int c) {

+ 1
- 2
src/system/Shader.cpp 파일 보기

@@ -224,8 +224,7 @@ int Shader::initialize() {
224 224
     glGenVertexArrays(1, &vertexArrayID);
225 225
     glBindVertexArray(vertexArrayID);
226 226
 
227
-    // Set background to black
228
-    //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
227
+    // Set background color
229 228
     glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
230 229
 
231 230
     set2DState(false);

+ 7
- 5
src/utils/pixel.cpp 파일 보기

@@ -8,17 +8,19 @@
8 8
 #include "global.h"
9 9
 #include "utils/pixel.h"
10 10
 
11
-unsigned char* generateColorTexture(const unsigned char* rgba, unsigned int width,
11
+unsigned char* generateColorTexture(glm::vec4 rgba, unsigned int width,
12 12
                                     unsigned int height, unsigned int bpp) {
13
-    assert(rgba != nullptr);
14 13
     assert(width > 0);
15 14
     assert(height > 0);
16
-    assert((bpp % 8) == 0);
15
+    assert((bpp == 24) || (bpp == 32));
17 16
 
18 17
     unsigned char* image = new unsigned char[height * width * (bpp / 8)];
19 18
     for (unsigned int i = 0; i < (width * height); i++) {
20
-        for (unsigned int a = 0; a < (bpp / 8); a++) {
21
-            image[(i * (bpp / 8)) + a] = rgba[a];
19
+        image[i * (bpp / 8)] = (unsigned char)(rgba.r * 255);
20
+        image[(i * (bpp / 8)) + 1] = (unsigned char)(rgba.g * 255);
21
+        image[(i * (bpp / 8)) + 2] = (unsigned char)(rgba.b * 255);
22
+        if (bpp == 32) {
23
+            image[(i * (bpp / 8)) + 3] = (unsigned char)(rgba.a * 255);
22 24
         }
23 25
     }
24 26
     return image;

Loading…
취소
저장