Переглянути джерело

Fixed TRLE colors and SDL heading

Thomas Buck 10 роки тому
джерело
коміт
c790cae738
8 змінених файлів з 36 додано та 55 видалено
  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 Переглянути файл

5
     [ 20140615 ]
5
     [ 20140615 ]
6
     * Added FontManager, selecting Font library to use depending on
6
     * Added FontManager, selecting Font library to use depending on
7
       the file extension of the font file specified in the config.
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
     [ 20140614 ]
12
     [ 20140614 ]
10
     * Implemented TRLE Font loader
13
     * Implemented TRLE Font loader

+ 0
- 4
TODO.md Переглянути файл

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

+ 0
- 1
include/Font.h Переглянути файл

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

+ 14
- 12
src/Font.cpp Переглянути файл

12
 Font::~Font() {
12
 Font::~Font() {
13
     delete [] mFontName;
13
     delete [] mFontName;
14
     mFontName = NULL;
14
     mFontName = NULL;
15
-
16
-    delete [] tempText.text;
17
-    tempText.text = NULL;
18
 }
15
 }
19
 
16
 
20
 void Font::setFont(const char *font) {
17
 void Font::setFont(const char *font) {
26
 }
23
 }
27
 
24
 
28
 void Font::drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...) {
25
 void Font::drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...) {
26
+    FontString tempText;
29
     va_list args;
27
     va_list args;
30
     va_start(args, s);
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
     tempText.scale = scale;
31
     tempText.scale = scale;
32
+    tempText.w = 0;
33
+    tempText.h = 0;
36
     tempText.x = x;
34
     tempText.x = x;
37
     tempText.y = y;
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
     writeString(tempText);
43
     writeString(tempText);
44
+
45
+    delete [] tempText.text;
46
+    va_end(args);
45
 }
47
 }
46
 
48
 

+ 1
- 10
src/FontManager.cpp Переглянути файл

1
 /*!
1
 /*!
2
  * \file src/FontManager.cpp
2
  * \file src/FontManager.cpp
3
- * \brief SDL Font implementation
3
+ * \brief Font Manager
4
  *
4
  *
5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
20
 #endif
20
 #endif
21
 
21
 
22
     font = -1;
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
 FontManager::~FontManager() {
25
 FontManager::~FontManager() {

+ 0
- 9
src/FontSDL.cpp Переглянути файл

13
     mFontInit = false;
13
     mFontInit = false;
14
     mFontName = NULL;
14
     mFontName = NULL;
15
     mFontTexture = 0;
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
 FontSDL::~FontSDL() {
18
 FontSDL::~FontSDL() {

+ 14
- 15
src/FontTRLE.cpp Переглянути файл

16
     mFontInit = false;
16
     mFontInit = false;
17
     mFontName = NULL;
17
     mFontName = NULL;
18
     mFontTexture = 0;
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
 FontTRLE::~FontTRLE() {
21
 FontTRLE::~FontTRLE() {
46
         return -1;
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
     // ...into GL texture
48
     // ...into GL texture
50
     glGenTextures(1, &mFontTexture);
49
     glGenTextures(1, &mFontTexture);
51
     glBindTexture(GL_TEXTURE_2D, mFontTexture);
50
     glBindTexture(GL_TEXTURE_2D, mFontTexture);
142
     assert(s.text != NULL);
141
     assert(s.text != NULL);
143
 
142
 
144
     unsigned int x = s.x;
143
     unsigned int x = s.x;
144
+    unsigned int y = 0;
145
 
145
 
146
     for (unsigned int i = 0; s.text[i] != '\0'; i++) {
146
     for (unsigned int i = 0; s.text[i] != '\0'; i++) {
147
         // index into offset table
147
         // index into offset table
155
 
155
 
156
         writeChar((unsigned int)index, x, s);
156
         writeChar((unsigned int)index, x, s);
157
         x += (int)((vec_t)(offsets[index][2] + 1) * s.scale * SCALING); // width
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 Переглянути файл

30
     mMin = 0;
30
     mMin = 0;
31
 
31
 
32
     mainText.text = bufferString(VERSION);
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
     mainText.scale = 1.2f;
37
     mainText.scale = 1.2f;
38
     mainText.y = 10;
38
     mainText.y = 10;
39
     mainText.w = 0;
39
     mainText.w = 0;

Завантаження…
Відмінити
Зберегти