Browse Source

Using float for font colors. Better controller mapping.

Thomas Buck 9 years ago
parent
commit
f7cbc216ce

+ 3
- 0
ChangeLog.md View File

5
     [ 20140306 ]
5
     [ 20140306 ]
6
     * Fixed LoaderTR1, can now also open the Unfinished Business levels
6
     * Fixed LoaderTR1, can now also open the Unfinished Business levels
7
     * Walk key can now be used to increase free-camera movement speed
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
     [ 20140305 ]
12
     [ 20140305 ]
10
     * SoundAL now has more useful error message output.
13
     * SoundAL now has more useful error message output.

+ 3
- 0
include/Menu.h View File

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

+ 2
- 12
include/global.h View File

11
 
11
 
12
 void renderFrame();
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
 // Actions that can be bound to a key and sent to the game engine
14
 // Actions that can be bound to a key and sent to the game engine
27
 typedef enum {
15
 typedef enum {
28
     menuAction = 0,
16
     menuAction = 0,
64
     pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
52
     pageupKey, pauseKey, dotKey, rightaltKey, rightctrlKey, enterKey,
65
     rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
53
     rightguiKey, rightbracketKey, rightshiftKey, scrolllockKey,
66
     semicolonKey, slashKey, spaceKey, tabKey,
54
     semicolonKey, slashKey, spaceKey, tabKey,
55
+
56
+    // Mouse
67
     leftmouseKey, middlemouseKey, rightmouseKey,
57
     leftmouseKey, middlemouseKey, rightmouseKey,
68
     fourthmouseKey, fifthmouseKey,
58
     fourthmouseKey, fifthmouseKey,
69
 
59
 

+ 3
- 3
include/system/Font.h View File

26
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
26
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
27
 
27
 
28
     static void drawText(unsigned int x, unsigned int y, float scale,
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
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
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
     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
+                                 glm::vec4 color, unsigned int width, std::string s);
36
 
36
 
37
     static void setShowFontBox(bool s) { showFontBox = s; }
37
     static void setShowFontBox(bool s) { showFontBox = s; }
38
     static bool getShowFontBox() { return showFontBox; }
38
     static bool getShowFontBox() { return showFontBox; }

+ 2
- 2
include/system/FontImGui.h View File

20
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
20
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
21
 
21
 
22
     static void drawText(unsigned int x, unsigned int y, float scale,
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
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
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
 #endif
29
 #endif

+ 2
- 2
include/system/FontTRLE.h View File

26
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
26
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
27
 
27
 
28
     static void drawText(unsigned int x, unsigned int y, float scale,
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
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
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
   private:
34
   private:
35
     static void setDefaultOffsets();
35
     static void setDefaultOffsets();

+ 3
- 3
include/system/FontTTF.h View File

40
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
40
     static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
41
 
41
 
42
     static void drawText(unsigned int x, unsigned int y, float scale,
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
     static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
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
   private:
47
   private:
48
     static int charIsMapped(int c);
48
     static int charIsMapped(int c);
49
     static int getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad);
49
     static int getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad);
50
     static void drawTextInternal(unsigned int x, unsigned int y, float scale,
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
                                  bool drawWrapped);
52
                                  bool drawWrapped);
53
 
53
 
54
     static unsigned char* fontData;
54
     static unsigned char* fontData;

+ 1
- 1
include/utils/pixel.h View File

8
 #ifndef _UTILS_PIXEL_H_
8
 #ifndef _UTILS_PIXEL_H_
9
 #define _UTILS_PIXEL_H_
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
                                     unsigned int height, unsigned int bpp);
12
                                     unsigned int height, unsigned int bpp);
13
 
13
 
14
 void argb2rgba32(unsigned char* image, unsigned int w, unsigned int h);
14
 void argb2rgba32(unsigned char* image, unsigned int w, unsigned int h);

+ 9
- 6
src/Menu.cpp View File

11
 #include "system/Font.h"
11
 #include "system/Font.h"
12
 #include "system/Window.h"
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
 void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
17
 void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
15
                       std::function<int (bool state)> callback) {
18
                       std::function<int (bool state)> callback) {
16
     // Only show one dialog at a time
19
     // Only show one dialog at a time
148
         glEnable(GL_TEXTURE_2D);
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
         if (dialogButton2.length() > 0) {
155
         if (dialogButton2.length() > 0) {
153
             if ((w1 + w2) <= wMax) {
156
             if ((w1 + w2) <= wMax) {
154
                 Font::drawTextWrapped(xOverlay + 10, yOverlay + 10 + h0, 1.0f,
157
                 Font::drawTextWrapped(xOverlay + 10, yOverlay + 10 + h0, 1.0f,
155
-                                      dialogState ? BLUE : RED, w1, dialogButton1);
158
+                                      dialogState ? textColor : selectedColor, w1, dialogButton1);
156
                 Font::drawTextWrapped(xOverlay + 10 + w1, yOverlay + 10 + h0,
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
             } else {
161
             } else {
159
                 Font::drawTextWrapped((Window::getSize().x - w1) / 2,
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
                 Font::drawTextWrapped((Window::getSize().x - w2) / 2,
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
         } else {
167
         } else {
165
             Font::drawTextWrapped((Window::getSize().x - w1) / 2,
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 View File

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

+ 1
- 1
src/TextureManager.cpp View File

69
         mTextureIdsSystem.push_back(id);
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
     int res = loadBufferSlot(image, 32, 32, ColorMode::RGBA, 32, TextureStorage::SYSTEM, TEXTURE_WHITE,
73
     int res = loadBufferSlot(image, 32, 32, ColorMode::RGBA, 32, TextureStorage::SYSTEM, TEXTURE_WHITE,
74
                              false);
74
                              false);
75
     delete [] image;
75
     delete [] image;

+ 6
- 0
src/UI.cpp View File

461
             Game::handleAction(jumpAction, released);
461
             Game::handleAction(jumpAction, released);
462
         } else if (button == bButton) {
462
         } else if (button == bButton) {
463
             Game::handleAction(crouchAction, released);
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
         } else if (button == padUp) {
468
         } else if (button == padUp) {
465
             Game::handleAction(forwardAction, released);
469
             Game::handleAction(forwardAction, released);
466
         } else if (button == padDown) {
470
         } else if (button == padDown) {
469
             Game::handleAction(leftAction, released);
473
             Game::handleAction(leftAction, released);
470
         } else if (button == padRight) {
474
         } else if (button == padRight) {
471
             Game::handleAction(rightAction, released);
475
             Game::handleAction(rightAction, released);
476
+        } else if (button == leftShoulder) {
477
+            Game::handleAction(walkAction, released);
472
         } else if (button == startButton) {
478
         } else if (button == startButton) {
473
             if (!released)
479
             if (!released)
474
                 getMenu().setVisible(true);
480
                 getMenu().setVisible(true);

+ 3
- 3
src/system/Font.cpp View File

62
 }
62
 }
63
 
63
 
64
 void Font::drawText(unsigned int x, unsigned int y, float scale,
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
     if (stringEndsWith(fontName, ".pc")) {
66
     if (stringEndsWith(fontName, ".pc")) {
67
         FontTRLE::drawText(x, y, scale, color, s);
67
         FontTRLE::drawText(x, y, scale, color, s);
68
     } else if (stringEndsWith(fontName, ".ttf")) {
68
     } else if (stringEndsWith(fontName, ".ttf")) {
79
 }
79
 }
80
 
80
 
81
 void Font::drawTextWrapped(unsigned int x, unsigned int y, float scale,
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
     if (stringEndsWith(fontName, ".pc")) {
83
     if (stringEndsWith(fontName, ".pc")) {
84
         FontTRLE::drawTextWrapped(x, y, scale, color, maxWidth, s);
84
         FontTRLE::drawTextWrapped(x, y, scale, color, maxWidth, s);
85
     } else if (stringEndsWith(fontName, ".ttf")) {
85
     } else if (stringEndsWith(fontName, ".ttf")) {
98
 }
98
 }
99
 
99
 
100
 void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
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
     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);
103
 }
103
 }
104
 
104
 

+ 6
- 4
src/system/FontImGui.cpp View File

23
 }
23
 }
24
 
24
 
25
 void FontImGui::drawText(unsigned int x, unsigned int y, float scale,
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
     ImGuiIO& io = ImGui::GetIO();
27
     ImGuiIO& io = ImGui::GetIO();
28
     ImFont* font = io.Fonts->Fonts.at(0);
28
     ImFont* font = io.Fonts->Fonts.at(0);
29
     ImVec2 pos = ImVec2(x, y);
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
     ImDrawList dl;
33
     ImDrawList dl;
33
     dl.PushTextureID(font->ContainerAtlas->TexID);
34
     dl.PushTextureID(font->ContainerAtlas->TexID);
47
 }
48
 }
48
 
49
 
49
 void FontImGui::drawTextWrapped(unsigned int x, unsigned int y, float scale,
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
     ImGuiIO& io = ImGui::GetIO();
52
     ImGuiIO& io = ImGui::GetIO();
52
     ImFont* font = io.Fonts->Fonts.at(0);
53
     ImFont* font = io.Fonts->Fonts.at(0);
53
     ImVec2 pos = ImVec2(x, y);
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
     ImDrawList dl;
58
     ImDrawList dl;
57
     dl.PushTextureID(font->ContainerAtlas->TexID);
59
     dl.PushTextureID(font->ContainerAtlas->TexID);

+ 4
- 6
src/system/FontTRLE.cpp View File

147
 }
147
 }
148
 
148
 
149
 void FontTRLE::drawText(unsigned int x, unsigned int y, float scale,
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
     assert(mFontInit == true);
151
     assert(mFontInit == true);
152
     assert(s.length() > 0);
152
     assert(s.length() > 0);
153
 
153
 
169
 
169
 
170
     vertexBuffer.bufferData(vertices);
170
     vertexBuffer.bufferData(vertices);
171
     uvBuffer.bufferData(uvs);
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
 unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::string s) {
175
 unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::string s) {
207
 }
206
 }
208
 
207
 
209
 void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
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
     assert(mFontInit == true);
210
     assert(mFontInit == true);
212
     assert(s.length() > 0);
211
     assert(s.length() > 0);
213
 
212
 
245
 
244
 
246
     vertexBuffer.bufferData(vertices);
245
     vertexBuffer.bufferData(vertices);
247
     uvBuffer.bufferData(uvs);
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
 int FontTRLE::defaultOffsets[106][5] = {
250
 int FontTRLE::defaultOffsets[106][5] = {

+ 5
- 6
src/system/FontTTF.cpp View File

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

+ 1
- 2
src/system/Shader.cpp View File

224
     glGenVertexArrays(1, &vertexArrayID);
224
     glGenVertexArrays(1, &vertexArrayID);
225
     glBindVertexArray(vertexArrayID);
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
     glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
228
     glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
230
 
229
 
231
     set2DState(false);
230
     set2DState(false);

+ 7
- 5
src/utils/pixel.cpp View File

8
 #include "global.h"
8
 #include "global.h"
9
 #include "utils/pixel.h"
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
                                     unsigned int height, unsigned int bpp) {
12
                                     unsigned int height, unsigned int bpp) {
13
-    assert(rgba != nullptr);
14
     assert(width > 0);
13
     assert(width > 0);
15
     assert(height > 0);
14
     assert(height > 0);
16
-    assert((bpp % 8) == 0);
15
+    assert((bpp == 24) || (bpp == 32));
17
 
16
 
18
     unsigned char* image = new unsigned char[height * width * (bpp / 8)];
17
     unsigned char* image = new unsigned char[height * width * (bpp / 8)];
19
     for (unsigned int i = 0; i < (width * height); i++) {
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
     return image;
26
     return image;

Loading…
Cancel
Save