Browse Source

Fixed TRLE colors and SDL heading

Thomas Buck 10 years ago
parent
commit
c790cae738
8 changed files with 36 additions and 55 deletions
  1. 3
    0
      ChangeLog.md
  2. 0
    4
      TODO.md
  3. 0
    1
      include/Font.h
  4. 14
    12
      src/Font.cpp
  5. 1
    10
      src/FontManager.cpp
  6. 0
    9
      src/FontSDL.cpp
  7. 14
    15
      src/FontTRLE.cpp
  8. 4
    4
      src/Menu.cpp

+ 3
- 0
ChangeLog.md View File

@@ -5,6 +5,9 @@
5 5
     [ 20140615 ]
6 6
     * Added FontManager, selecting Font library to use depending on
7 7
       the file extension of the font file specified in the config.
8
+    * Fixed menu heading not visible when using FontSDL
9
+    * Font::drawText now only implemented in Font
10
+    * TRLE Fonts can now be properly colored
8 11
 
9 12
     [ 20140614 ]
10 13
     * Implemented TRLE Font loader

+ 0
- 4
TODO.md View File

@@ -26,10 +26,6 @@ There are these DebugModel, DebugMap flags...?
26 26
 * Support SSE with other compilers than Clang (src/CMakeLists.txt)
27 27
 * Visual C++ compiler flags? (CMakeLists.txt)
28 28
 
29
-## Bugs
30
-
31
-* Menu Header “OpenRaider” not visible when using FontSDL?
32
-
33 29
 ## Future Features
34 30
 
35 31
 * Use only assets from old TR games, not even depending on a font file?

+ 0
- 1
include/Font.h View File

@@ -41,7 +41,6 @@ public:
41 41
 protected:
42 42
     bool mFontInit;
43 43
     char *mFontName;
44
-    FontString tempText;
45 44
 };
46 45
 
47 46
 Font &getFont();

+ 14
- 12
src/Font.cpp View File

@@ -12,9 +12,6 @@
12 12
 Font::~Font() {
13 13
     delete [] mFontName;
14 14
     mFontName = NULL;
15
-
16
-    delete [] tempText.text;
17
-    tempText.text = NULL;
18 15
 }
19 16
 
20 17
 void Font::setFont(const char *font) {
@@ -26,21 +23,26 @@ void Font::setFont(const char *font) {
26 23
 }
27 24
 
28 25
 void Font::drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...) {
26
+    FontString tempText;
29 27
     va_list args;
30 28
     va_start(args, s);
31
-    vsnprintf(tempText.text, 256, s, args);
32
-    tempText.text[255] = '\0';
33
-    va_end(args);
34 29
 
30
+    tempText.text = new char[256];
35 31
     tempText.scale = scale;
32
+    tempText.w = 0;
33
+    tempText.h = 0;
36 34
     tempText.x = x;
37 35
     tempText.y = y;
38
-    if (color) {
39
-        tempText.color[0] = color[0];
40
-        tempText.color[1] = color[1];
41
-        tempText.color[2] = color[2];
42
-        tempText.color[3] = color[3];
43
-    }
36
+    tempText.color[0] = color[0];
37
+    tempText.color[1] = color[1];
38
+    tempText.color[2] = color[2];
39
+    tempText.color[3] = color[3];
40
+
41
+    vsnprintf(tempText.text, 256, s, args);
42
+    tempText.text[255] = '\0';
44 43
     writeString(tempText);
44
+
45
+    delete [] tempText.text;
46
+    va_end(args);
45 47
 }
46 48
 

+ 1
- 10
src/FontManager.cpp View File

@@ -1,6 +1,6 @@
1 1
 /*!
2 2
  * \file src/FontManager.cpp
3
- * \brief SDL Font implementation
3
+ * \brief Font Manager
4 4
  *
5 5
  * \author xythobuz
6 6
  */
@@ -20,15 +20,6 @@ FontManager::FontManager() {
20 20
 #endif
21 21
 
22 22
     font = -1;
23
-
24
-    tempText.text = new char[256];
25
-    tempText.color[0] = 0xFF;
26
-    tempText.color[1] = 0xFF;
27
-    tempText.color[2] = 0xFF;
28
-    tempText.color[3] = 0xFF;
29
-    tempText.scale = 1.2f;
30
-    tempText.w = 0;
31
-    tempText.h = 0;
32 23
 }
33 24
 
34 25
 FontManager::~FontManager() {

+ 0
- 9
src/FontSDL.cpp View File

@@ -13,15 +13,6 @@ FontSDL::FontSDL() {
13 13
     mFontInit = false;
14 14
     mFontName = NULL;
15 15
     mFontTexture = 0;
16
-
17
-    tempText.text = new char[256];
18
-    tempText.color[0] = 0xFF;
19
-    tempText.color[1] = 0xFF;
20
-    tempText.color[2] = 0xFF;
21
-    tempText.color[3] = 0xFF;
22
-    tempText.scale = 1.2f;
23
-    tempText.w = 0;
24
-    tempText.h = 0;
25 16
 }
26 17
 
27 18
 FontSDL::~FontSDL() {

+ 14
- 15
src/FontTRLE.cpp View File

@@ -16,15 +16,6 @@ FontTRLE::FontTRLE() {
16 16
     mFontInit = false;
17 17
     mFontName = NULL;
18 18
     mFontTexture = 0;
19
-
20
-    tempText.text = new char[256];
21
-    tempText.color[0] = 0xFF;
22
-    tempText.color[1] = 0xFF;
23
-    tempText.color[2] = 0xFF;
24
-    tempText.color[3] = 0xFF;
25
-    tempText.scale = 1.2f;
26
-    tempText.w = 0;
27
-    tempText.h = 0;
28 19
 }
29 20
 
30 21
 FontTRLE::~FontTRLE() {
@@ -46,6 +37,14 @@ int FontTRLE::initialize() {
46 37
         return -1;
47 38
     }
48 39
 
40
+    // Fix coloring
41
+    for (unsigned int i = 0; i < (256 * 256 * 4); i += 4) {
42
+        float y = (0.2126f * pixels[i + 2]);
43
+        y += (0.7152f * pixels[i + 1]);
44
+        y += (0.0722f * pixels[i]);
45
+        pixels[i] = pixels[i + 1] = pixels[i + 2] = (unsigned char)y;
46
+    }
47
+
49 48
     // ...into GL texture
50 49
     glGenTextures(1, &mFontTexture);
51 50
     glBindTexture(GL_TEXTURE_2D, mFontTexture);
@@ -142,6 +141,7 @@ void FontTRLE::writeString(FontString &s) {
142 141
     assert(s.text != NULL);
143 142
 
144 143
     unsigned int x = s.x;
144
+    unsigned int y = 0;
145 145
 
146 146
     for (unsigned int i = 0; s.text[i] != '\0'; i++) {
147 147
         // index into offset table
@@ -155,13 +155,12 @@ void FontTRLE::writeString(FontString &s) {
155 155
 
156 156
         writeChar((unsigned int)index, x, s);
157 157
         x += (int)((vec_t)(offsets[index][2] + 1) * s.scale * SCALING); // width
158
+
159
+        if (y < (unsigned int)(((vec_t)offsets[index][3]) * s.scale * SCALING))
160
+            y = (unsigned int)(((vec_t)offsets[index][3]) * s.scale * SCALING);
158 161
     }
159 162
 
160
-    // TODO scaling?!
161
-    s.w = x;
162
-/*
163
-    s.w = (int)((float)surface->w * s.scale * SCALING);
164
-    s.h = (int)((float)surface->h * s.scale * SCALING);
165
-*/
163
+    s.w = x - s.x;
164
+    s.h = y;
166 165
 }
167 166
 

+ 4
- 4
src/Menu.cpp View File

@@ -30,10 +30,10 @@ Menu::Menu() {
30 30
     mMin = 0;
31 31
 
32 32
     mainText.text = bufferString(VERSION);
33
-    mainText.color[0] = 0xFF;
34
-    mainText.color[1] = 0xFF;
35
-    mainText.color[2] = 0xFF;
36
-    mainText.color[3] = 0xFF;
33
+    mainText.color[0] = OR_BLUE[0];
34
+    mainText.color[1] = OR_BLUE[1];
35
+    mainText.color[2] = OR_BLUE[2];
36
+    mainText.color[3] = OR_BLUE[3];
37 37
     mainText.scale = 1.2f;
38 38
     mainText.y = 10;
39 39
     mainText.w = 0;

Loading…
Cancel
Save