Преглед изворни кода

unsigned char instead of float for colors

Thomas Buck пре 10 година
родитељ
комит
436f04fd10
21 измењених фајлова са 94 додато и 100 уклоњено
  1. 3
    0
      ChangeLog.md
  2. 1
    0
      TODO.md
  3. 1
    0
      include/Camera.h
  4. 2
    2
      include/Font.h
  5. 1
    1
      include/RoomData.h
  6. 0
    2
      include/TextureManager.h
  7. 11
    11
      include/global.h
  8. 4
    4
      src/Console.cpp
  9. 1
    1
      src/Font.cpp
  10. 5
    5
      src/FontSDL.cpp
  11. 1
    1
      src/FontTRLE.cpp
  12. 6
    6
      src/Menu.cpp
  13. 2
    2
      src/OpenRaider.cpp
  14. 28
    11
      src/Render.cpp
  15. 2
    2
      src/Room.cpp
  16. 3
    3
      src/RoomData.cpp
  17. 2
    2
      src/Sprite.cpp
  18. 2
    2
      src/StaticMesh.cpp
  19. 19
    37
      src/TextureManager.cpp
  20. 0
    4
      src/utils/pcx.cpp
  21. 0
    4
      src/utils/png.cpp

+ 3
- 0
ChangeLog.md Прегледај датотеку

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20140623 ]
6
+    * Use unsigned char instead of float for colors
7
+
5
     [ 20140622 ]
8
     [ 20140622 ]
6
     * Wrote simple image reader/writer utilizing libpng
9
     * Wrote simple image reader/writer utilizing libpng
7
     * Created utils/pixels for pixel handling utilities
10
     * Created utils/pixels for pixel handling utilities

+ 1
- 0
TODO.md Прегледај датотеку

10
     * Rewrite Console and use operator << to write to the console?
10
     * Rewrite Console and use operator << to write to the console?
11
 * SDL_TTF 2.0.12+ [can do line breaks](http://stackoverflow.com/questions/17847818/how-to-do-line-breaks-and-line-wrapping-with-sdl-ttf/18418688#18418688), use it
11
 * SDL_TTF 2.0.12+ [can do line breaks](http://stackoverflow.com/questions/17847818/how-to-do-line-breaks-and-line-wrapping-with-sdl-ttf/18418688#18418688), use it
12
 * Mesh has 2 different approaches of storing the same data (eg. mColors and mColorArray), but half of ‘em isn’t implemented. Unify this, probably even combining Mesh and StaticMesh...
12
 * Mesh has 2 different approaches of storing the same data (eg. mColors and mColorArray), but half of ‘em isn’t implemented. Unify this, probably even combining Mesh and StaticMesh...
13
+* Don’t use float everywhere just because (eg. float colors)
13
 
14
 
14
 ## Changes
15
 ## Changes
15
 
16
 

+ 1
- 0
include/Camera.h Прегледај датотеку

5
  * \author Mongoose
5
  * \author Mongoose
6
  * \author xythobuz
6
  * \author xythobuz
7
  */
7
  */
8
+
8
 #ifndef _CAMERA_H_
9
 #ifndef _CAMERA_H_
9
 #define _CAMERA_H_
10
 #define _CAMERA_H_
10
 
11
 

+ 2
- 2
include/Font.h Прегледај датотеку

15
     int w;
15
     int w;
16
     int h;
16
     int h;
17
     float scale;
17
     float scale;
18
-    float color[4];
18
+    unsigned char color[4];
19
 } FontString;
19
 } FontString;
20
 
20
 
21
 /*!
21
 /*!
35
 
35
 
36
     virtual void writeString(FontString &s) = 0;
36
     virtual void writeString(FontString &s) = 0;
37
 
37
 
38
-    virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
38
+    virtual void drawText(unsigned int x, unsigned int y, float scale, const unsigned char color[4], const char *s, ...)
39
         __attribute__((format(printf, 6, 0)));
39
         __attribute__((format(printf, 6, 0)));
40
 
40
 
41
 protected:
41
 protected:

+ 1
- 1
include/RoomData.h Прегледај датотеку

19
     BoundingBox();
19
     BoundingBox();
20
     void getBoundingBox(vec3_t box[2]);
20
     void getBoundingBox(vec3_t box[2]);
21
     void setBoundingBox(vec3_t min, vec3_t max);
21
     void setBoundingBox(vec3_t min, vec3_t max);
22
-    void display(bool points, const vec4_t c1, const vec4_t c2);
22
+    void display(bool points, const unsigned char c1[4], const unsigned char c2[4]);
23
     bool inBox(vec_t x, vec_t y, vec_t z);
23
     bool inBox(vec_t x, vec_t y, vec_t z);
24
     bool inBoxPlane(vec_t x, vec_t z);
24
     bool inBoxPlane(vec_t x, vec_t z);
25
 
25
 

+ 0
- 2
include/TextureManager.h Прегледај датотеку

152
     unsigned int mTextureCount; //!< Texture counter
152
     unsigned int mTextureCount; //!< Texture counter
153
     unsigned int mTextureLimit; //!< The texture limit
153
     unsigned int mTextureLimit; //!< The texture limit
154
     unsigned int mFlags;        //!< Class options
154
     unsigned int mFlags;        //!< Class options
155
-    int mTextureId;             //!< Currently bound texture id
156
-    int mTextureId2;            //!< Multitexture Texture Id
157
 };
155
 };
158
 
156
 
159
 #endif
157
 #endif

+ 11
- 11
include/global.h Прегледај датотеку

48
 #include <cassert>
48
 #include <cassert>
49
 #endif
49
 #endif
50
 
50
 
51
-// Colors used for Rendering
52
-const float BLACK[]       = {  0.0f,  0.0f,  0.0f, 1.0f };
53
-const float DIM_WHITE[]   = {  0.5f,  0.5f,  0.5f, 1.0f };
54
-const float WHITE[]       = {  1.0f,  1.0f,  1.0f, 1.0f };
55
-const float RED[]         = {  1.0f,  0.0f,  0.0f, 1.0f };
56
-const float GREEN[]       = {  0.0f,  1.0f,  0.0f, 1.0f };
57
-const float NEXT_PURPLE[] = {  0.3f,  0.3f,  0.5f, 1.0f };
58
-const float OR_BLUE[]     = {  0.5f,  0.7f,  1.0f, 1.0f };
59
-const float PINK[]        = {  1.0f,  0.0f,  1.0f, 1.0f };
60
-const float YELLOW[]      = {  1.0f,  1.0f,  0.0f, 1.0f };
61
-const float CYAN[]        = {  0.0f,  1.0f,  1.0f, 1.0f };
51
+// Colors used where ever needed
52
+const unsigned char BLACK[]  = {   0,   0,   0, 255 };
53
+const unsigned char GREY[]   = { 128, 128, 128, 255 };
54
+const unsigned char WHITE[]  = { 255, 255, 255, 255 };
55
+const unsigned char RED[]    = { 255,   0,   0, 255 };
56
+const unsigned char GREEN[]  = {   0, 255,   0, 255 };
57
+const unsigned char PURPLE[] = {  77,  77, 128, 255 };
58
+const unsigned char BLUE[]   = { 128, 179, 255, 255 };
59
+const unsigned char PINK[]   = { 255,   0, 255, 255 };
60
+const unsigned char YELLOW[] = { 255, 255,   0, 255 };
61
+const unsigned char CYAN[]   = {   0, 255, 255, 255 };
62
 
62
 
63
 // Actions that can be bound to a key and sent to the game engine
63
 // Actions that can be bound to a key and sent to the game engine
64
 typedef enum {
64
 typedef enum {

+ 4
- 4
src/Console.cpp Прегледај датотеку

101
             scrollIndicator = 100;
101
             scrollIndicator = 100;
102
         }
102
         }
103
 
103
 
104
-        getFont().drawText(10, 10, 0.70f, OR_BLUE,
104
+        getFont().drawText(10, 10, 0.70f, BLUE,
105
                 "%s uptime %lus scroll %d%%", VERSION, systemTimerGet() / 1000, scrollIndicator);
105
                 "%s uptime %lus scroll %d%%", VERSION, systemTimerGet() / 1000, scrollIndicator);
106
 
106
 
107
         // Draw output log
107
         // Draw output log
116
         }
116
         }
117
         for (int i = 0; i < end; i++) {
117
         for (int i = 0; i < end; i++) {
118
             getFont().drawText(10, ((i + drawOffset) * lineSteps) + firstLine,
118
             getFont().drawText(10, ((i + drawOffset) * lineSteps) + firstLine,
119
-                    0.75f, OR_BLUE, "%s", mHistory[i + historyOffset - mLineOffset]);
119
+                    0.75f, BLUE, "%s", mHistory[i + historyOffset - mLineOffset]);
120
         }
120
         }
121
 
121
 
122
         // Draw current input
122
         // Draw current input
123
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
123
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
124
-            getFont().drawText(10, inputLine, 0.75f, OR_BLUE, "> %s", mInputBuffer);
124
+            getFont().drawText(10, inputLine, 0.75f, BLUE, "> %s", mInputBuffer);
125
         } else {
125
         } else {
126
-            getFont().drawText(10, inputLine, 0.75f, OR_BLUE, ">");
126
+            getFont().drawText(10, inputLine, 0.75f, BLUE, ">");
127
         }
127
         }
128
 
128
 
129
         //! \todo display the current mPartialInput. The UTF-8 segfaults SDL-TTF, somehow?
129
         //! \todo display the current mPartialInput. The UTF-8 segfaults SDL-TTF, somehow?

+ 1
- 1
src/Font.cpp Прегледај датотеку

22
     mFontName = fullPath(font, 0);
22
     mFontName = fullPath(font, 0);
23
 }
23
 }
24
 
24
 
25
-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 unsigned char color[4], const char *s, ...) {
26
     FontString tempText;
26
     FontString tempText;
27
     va_list args;
27
     va_list args;
28
     va_start(args, s);
28
     va_start(args, s);

+ 5
- 5
src/FontSDL.cpp Прегледај датотеку

50
     assert(s.text != NULL);
50
     assert(s.text != NULL);
51
 
51
 
52
     SDL_Color color;
52
     SDL_Color color;
53
-    color.r = (unsigned char)(s.color[0] * 255.0f);
54
-    color.g = (unsigned char)(s.color[1] * 255.0f);
55
-    color.b = (unsigned char)(s.color[2] * 255.0f);
56
-    color.a = (unsigned char)(s.color[3] * 255.0f);
53
+    color.r = s.color[0];
54
+    color.g = s.color[1];
55
+    color.b = s.color[2];
56
+    color.a = s.color[3];
57
 
57
 
58
     SDL_Surface *surface = TTF_RenderUTF8_Blended(mFont, s.text, color);
58
     SDL_Surface *surface = TTF_RenderUTF8_Blended(mFont, s.text, color);
59
     if (surface == NULL) {
59
     if (surface == NULL) {
87
     GLuint xMax = xMin + s.w;
87
     GLuint xMax = xMin + s.w;
88
     GLuint yMax = yMin + s.h;
88
     GLuint yMax = yMin + s.h;
89
 
89
 
90
-    glColor4f(color.r / 256.0f, color.g / 256.0f, color.b / 256.0f, color.a / 256.0f);
90
+    glColor4ubv(s.color);
91
 
91
 
92
     glBegin(GL_QUADS);
92
     glBegin(GL_QUADS);
93
     glTexCoord2f(0.0f, 0.0f);
93
     glTexCoord2f(0.0f, 0.0f);

+ 1
- 1
src/FontTRLE.cpp Прегледај датотеку

123
 
123
 
124
     // draw
124
     // draw
125
     glBindTexture(GL_TEXTURE_2D, mFontTexture);
125
     glBindTexture(GL_TEXTURE_2D, mFontTexture);
126
-    glColor4f(s.color[0], s.color[1], s.color[2], s.color[3]);
126
+    glColor4f(s.color[0] * 256.0f, s.color[1] * 256.0f, s.color[2] * 256.0f, s.color[3] * 256.0f);
127
     glBegin(GL_QUADS);
127
     glBegin(GL_QUADS);
128
     glTexCoord2f(txMin, tyMin);
128
     glTexCoord2f(txMin, tyMin);
129
     glVertex2i(xMin, yMin);
129
     glVertex2i(xMin, yMin);

+ 6
- 6
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] = OR_BLUE[0];
34
-    mainText.color[1] = OR_BLUE[1];
35
-    mainText.color[2] = OR_BLUE[2];
36
-    mainText.color[3] = OR_BLUE[3];
33
+    mainText.color[0] = BLUE[0];
34
+    mainText.color[1] = BLUE[1];
35
+    mainText.color[2] = BLUE[2];
36
+    mainText.color[3] = 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;
194
         if ((i + min) == (int)mCursor)
194
         if ((i + min) == (int)mCursor)
195
             getFont().drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
195
             getFont().drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
196
         else
196
         else
197
-            getFont().drawText(25, 100 + (25 * i), 0.75f, OR_BLUE, "%s", map);
197
+            getFont().drawText(25, 100 + (25 * i), 0.75f, BLUE, "%s", map);
198
     }
198
     }
199
 }
199
 }
200
 
200
 
212
         getFont().writeString(mainText);
212
         getFont().writeString(mainText);
213
 
213
 
214
         if (!mMapListFilled) {
214
         if (!mMapListFilled) {
215
-            getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
215
+            getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, BLUE, "Generating map list...");
216
         } else {
216
         } else {
217
             if (mMapList.size() == 0) {
217
             if (mMapList.size() == 0) {
218
                 getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, RED, "No maps found! See README.md");
218
                 getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, RED, "No maps found! See README.md");

+ 2
- 2
src/OpenRaider.cpp Прегледај датотеку

120
 
120
 
121
     // Draw FPS counter
121
     // Draw FPS counter
122
     if (mFPS)
122
     if (mFPS)
123
-        getFont().drawText(10, getWindow().getHeight() - 20, 0.5f, OR_BLUE, "%dFPS", fps);
123
+        getFont().drawText(10, getWindow().getHeight() - 20, 0.5f, BLUE, "%dFPS", fps);
124
 
124
 
125
 #ifdef DEBUG
125
 #ifdef DEBUG
126
     // Draw debug infos
126
     // Draw debug infos
127
     if (getGame().isLoaded() && (!getMenu().isVisible())) {
127
     if (getGame().isLoaded() && (!getMenu().isVisible())) {
128
         for (int i = 0; i < 3; i++) {
128
         for (int i = 0; i < 3; i++) {
129
-            getFont().drawText(10, getWindow().getHeight() - ((4 - i) * 20), 0.5f, OR_BLUE, "%.2f (%.2f)",
129
+            getFont().drawText(10, getWindow().getHeight() - ((4 - i) * 20), 0.5f, BLUE, "%.2f (%.2f)",
130
                 getGame().getLara().getPos(i) / 256.0f, getGame().getLara().getAngle(i));
130
                 getGame().getLara().getPos(i) / 256.0f, getGame().getLara().getAngle(i));
131
         }
131
         }
132
     }
132
     }

+ 28
- 11
src/Render.cpp Прегледај датотеку

81
         unsigned int width, unsigned int height,
81
         unsigned int width, unsigned int height,
82
         unsigned int id)
82
         unsigned int id)
83
 {
83
 {
84
-    glColor3fv(WHITE);
84
+    glColor3ubv(WHITE);
85
     mTexture.loadBufferSlot(image, width, height, TextureManager::RGBA, 32, id);
85
     mTexture.loadBufferSlot(image, width, height, TextureManager::RGBA, 32, id);
86
 }
86
 }
87
 
87
 
169
 {
169
 {
170
     if (on)
170
     if (on)
171
     {
171
     {
172
+        float color[4];
173
+        color[0] = WHITE[0] * 256.0f;
174
+        color[1] = WHITE[1] * 256.0f;
175
+        color[2] = WHITE[2] * 256.0f;
176
+        color[3] = WHITE[3] * 256.0f;
177
+
172
         glEnable(GL_LIGHTING);
178
         glEnable(GL_LIGHTING);
173
         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
179
         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
174
-        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, WHITE);
175
-        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, WHITE);
176
-        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, DIM_WHITE);
180
+        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
181
+        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
182
+
183
+        color[0] = GREY[0] * 256.0f;
184
+        color[1] = GREY[1] * 256.0f;
185
+        color[2] = GREY[2] * 256.0f;
186
+        color[3] = GREY[3] * 256.0f;
187
+        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color);
177
     }
188
     }
178
     else
189
     else
179
     {
190
     {
249
         glFogf(GL_FOG_DENSITY, 0.00008f);
260
         glFogf(GL_FOG_DENSITY, 0.00008f);
250
         glFogf(GL_FOG_START, 30000.0f);
261
         glFogf(GL_FOG_START, 30000.0f);
251
         glFogf(GL_FOG_END, 50000.0f);
262
         glFogf(GL_FOG_END, 50000.0f);
252
-        glFogfv(GL_FOG_COLOR, BLACK);
263
+
264
+        float color[4];
265
+        color[0] = BLACK[0] * 256.0f;
266
+        color[1] = BLACK[1] * 256.0f;
267
+        color[2] = BLACK[2] * 256.0f;
268
+        color[3] = BLACK[3] * 256.0f;
269
+        glFogfv(GL_FOG_COLOR, color);
253
     }
270
     }
254
 
271
 
255
     if (flags & Render::fGL_Lights)
272
     if (flags & Render::fGL_Lights)
275
             break;
292
             break;
276
         case Render::modeSolid:
293
         case Render::modeSolid:
277
         case Render::modeWireframe:
294
         case Render::modeWireframe:
278
-            glClearColor(NEXT_PURPLE[0], NEXT_PURPLE[1],
279
-                    NEXT_PURPLE[2], NEXT_PURPLE[3]);
295
+            glClearColor(PURPLE[0] * 256.0f, PURPLE[1] * 256.0f,
296
+                    PURPLE[2] * 256.0f, PURPLE[3] * 256.0f);
280
             glDisable(GL_TEXTURE_2D);
297
             glDisable(GL_TEXTURE_2D);
281
             break;
298
             break;
282
         default:
299
         default:
412
     updateViewVolume();
429
     updateViewVolume();
413
 
430
 
414
     // Render world
431
     // Render world
415
-    glColor3fv(DIM_WHITE); // was WHITE
432
+    glColor3ubv(GREY); // was WHITE
416
     drawSkyMesh(96.0);
433
     drawSkyMesh(96.0);
417
 
434
 
418
     // Figure out how much of the map to render
435
     // Figure out how much of the map to render
507
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
524
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
508
     glLoadIdentity();
525
     glLoadIdentity();
509
 
526
 
510
-    glColor3fv(WHITE);
527
+    glColor3ubv(WHITE);
511
 
528
 
512
     if (mFlags & Render::fGL_Lights)
529
     if (mFlags & Render::fGL_Lights)
513
         glDisable(GL_LIGHTING);
530
         glDisable(GL_LIGHTING);
691
     if (mMode == Render::modeWireframe)
708
     if (mMode == Render::modeWireframe)
692
     {
709
     {
693
         glPointSize(5.0);
710
         glPointSize(5.0);
694
-        glColor3fv(PINK);
711
+        glColor3ubv(PINK);
695
         glBegin(GL_POINTS);
712
         glBegin(GL_POINTS);
696
         glVertex3f(x, y, z);
713
         glVertex3f(x, y, z);
697
         glEnd();
714
         glEnd();
707
     if (mMode == Render::modeWireframe)
724
     if (mMode == Render::modeWireframe)
708
     {
725
     {
709
         glPointSize(5.0);
726
         glPointSize(5.0);
710
-        glColor3fv(PINK);
727
+        glColor3ubv(PINK);
711
         glBegin(GL_POINTS);
728
         glBegin(GL_POINTS);
712
         glVertex3f(x, y, z);
729
         glVertex3f(x, y, z);
713
         glEnd();
730
         glEnd();

+ 2
- 2
src/Room.cpp Прегледај датотеку

461
 
461
 
462
     if ((!alpha) && getRender().getMode() == Render::modeWireframe) {
462
     if ((!alpha) && getRender().getMode() == Render::modeWireframe) {
463
         glLineWidth(2.0);
463
         glLineWidth(2.0);
464
-        glColor3fv(RED);
464
+        glColor3ubv(RED);
465
 
465
 
466
         for (unsigned int i = 0; i < sizePortals(); i++) {
466
         for (unsigned int i = 0; i < sizePortals(); i++) {
467
             Portal &portal = getPortal(i);
467
             Portal &portal = getPortal(i);
486
     glTranslated(pos[0], pos[1], pos[2]);
486
     glTranslated(pos[0], pos[1], pos[2]);
487
 
487
 
488
     // Reset since GL_MODULATE used, reset to WHITE
488
     // Reset since GL_MODULATE used, reset to WHITE
489
-    glColor3fv(WHITE);
489
+    glColor3ubv(WHITE);
490
 
490
 
491
     switch (getRender().getMode())
491
     switch (getRender().getMode())
492
     {
492
     {

+ 3
- 3
src/RoomData.cpp Прегледај датотеку

43
             && (z > a[2]) && (z < b[2]));
43
             && (z > a[2]) && (z < b[2]));
44
 }
44
 }
45
 
45
 
46
-void BoundingBox::display(bool points, const vec4_t c1, const vec4_t c2) {
46
+void BoundingBox::display(bool points, const unsigned char c1[4], const unsigned char c2[4]) {
47
     // Bind before entering now
47
     // Bind before entering now
48
     //glBindTexture(GL_TEXTURE_2D, 1);
48
     //glBindTexture(GL_TEXTURE_2D, 1);
49
     glPointSize(4.0);
49
     glPointSize(4.0);
50
     //glLineWidth(1.25);
50
     //glLineWidth(1.25);
51
 
51
 
52
     //! \fixme Need to make custom color key for this
52
     //! \fixme Need to make custom color key for this
53
-    glColor3fv(c1);
53
+    glColor3ubv(c1);
54
 
54
 
55
     glBegin(GL_POINTS);
55
     glBegin(GL_POINTS);
56
     glVertex3f(b[0], b[1], b[2]);
56
     glVertex3f(b[0], b[1], b[2]);
68
 
68
 
69
     glEnd();
69
     glEnd();
70
 
70
 
71
-    glColor3fv(c2);
71
+    glColor3ubv(c2);
72
 
72
 
73
     glBegin(GL_LINES);
73
     glBegin(GL_LINES);
74
     // max, top quad
74
     // max, top quad

+ 2
- 2
src/Sprite.cpp Прегледај датотеку

129
             glEnd();
129
             glEnd();
130
             break;
130
             break;
131
         case Render::modeWireframe:
131
         case Render::modeWireframe:
132
-            glColor3fv(CYAN);
132
+            glColor3ubv(CYAN);
133
             glBegin(GL_LINE_LOOP);
133
             glBegin(GL_LINE_LOOP);
134
             glVertex3fv(vertex[0]);
134
             glVertex3fv(vertex[0]);
135
             glVertex3fv(vertex[1]);
135
             glVertex3fv(vertex[1]);
136
             glVertex3fv(vertex[2]);
136
             glVertex3fv(vertex[2]);
137
             glVertex3fv(vertex[3]);
137
             glVertex3fv(vertex[3]);
138
             glEnd();
138
             glEnd();
139
-            glColor3fv(WHITE);
139
+            glColor3ubv(WHITE);
140
             break;
140
             break;
141
         default:
141
         default:
142
             glBindTexture(GL_TEXTURE_2D, texture+1);
142
             glBindTexture(GL_TEXTURE_2D, texture+1);

+ 2
- 2
src/StaticMesh.cpp Прегледај датотеку

247
         //   return;
247
         //   return;
248
 
248
 
249
         //! \fixme 'AMBIENT' -- Mongoose 2002.01.08
249
         //! \fixme 'AMBIENT' -- Mongoose 2002.01.08
250
-        glColor3fv(WHITE);
250
+        glColor3ubv(WHITE);
251
 
251
 
252
         if (getRender().getMode() == Render::modeWireframe)
252
         if (getRender().getMode() == Render::modeWireframe)
253
-            glColor3fv(WHITE);
253
+            glColor3ubv(WHITE);
254
 
254
 
255
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
255
         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
256
         glBindTexture(GL_TEXTURE_2D, 1);  // White texture for colors
256
         glBindTexture(GL_TEXTURE_2D, 1);  // White texture for colors

+ 19
- 37
src/TextureManager.cpp Прегледај датотеку

21
 TextureManager::TextureManager() {
21
 TextureManager::TextureManager() {
22
     mTextureIds = NULL;
22
     mTextureIds = NULL;
23
     mFlags = 0;
23
     mFlags = 0;
24
-    mTextureId = -1;
25
-    mTextureId2 = -1;
26
     mTextureCount = 0;
24
     mTextureCount = 0;
27
     mTextureLimit = 0;
25
     mTextureLimit = 0;
28
 }
26
 }
33
 
31
 
34
 unsigned char *TextureManager::generateColorTexture(unsigned char rgba[4],
32
 unsigned char *TextureManager::generateColorTexture(unsigned char rgba[4],
35
         unsigned int width, unsigned int height) {
33
         unsigned int width, unsigned int height) {
36
-    unsigned char *image;
37
-    unsigned int i, size;
38
-
39
     assert(rgba != NULL);
34
     assert(rgba != NULL);
40
     assert(width > 0);
35
     assert(width > 0);
41
     assert(height > 0);
36
     assert(height > 0);
42
 
37
 
43
-    image = new unsigned char[height*width*4];
38
+    unsigned char *image = new unsigned char[height * width * 4];
44
 
39
 
45
-    for (i = 0, size = width*height; i < size; ++i) {
46
-        /* RBGA */
47
-        image[i*4]   = rgba[0];
48
-        image[i*4+1] = rgba[1];
49
-        image[i*4+2] = rgba[2];
50
-        image[i*4+3] = rgba[3];
40
+    for (unsigned int i = 0; i < (width * height); i++) {
41
+        image[i * 4] = rgba[0];
42
+        image[(i * 4) + 1] = rgba[1];
43
+        image[(i * 4) + 2] = rgba[2];
44
+        image[(i * 4) + 3] = rgba[3];
51
     }
45
     }
52
 
46
 
53
     return image;
47
     return image;
55
 
49
 
56
 int TextureManager::loadColorTexture(unsigned char rgba[4],
50
 int TextureManager::loadColorTexture(unsigned char rgba[4],
57
         unsigned int width, unsigned int height) {
51
         unsigned int width, unsigned int height) {
58
-    unsigned char *image;
59
-    int id;
60
-
61
     assert(rgba != NULL);
52
     assert(rgba != NULL);
62
     assert(width > 0);
53
     assert(width > 0);
63
     assert(height > 0);
54
     assert(height > 0);
64
 
55
 
65
-    image = generateColorTexture(rgba, width, height);
66
-    id = loadBuffer(image, width, height, RGBA, 32);
56
+    unsigned char *image = generateColorTexture(rgba, width, height);
57
+    int id = loadBuffer(image, width, height, RGBA, 32);
67
     delete [] image;
58
     delete [] image;
68
 
59
 
69
     return id;
60
     return id;
89
 }
80
 }
90
 
81
 
91
 void TextureManager::disableMultiTexture() {
82
 void TextureManager::disableMultiTexture() {
92
-    mFlags ^= fUseMultiTexture;
93
-    mTextureId = -1;
94
-    mTextureId2 = -1;
83
+    mFlags &= ~fUseMultiTexture;
95
 
84
 
96
     glDisable(GL_TEXTURE_2D);
85
     glDisable(GL_TEXTURE_2D);
97
     glActiveTextureARB(GL_TEXTURE0_ARB);
86
     glActiveTextureARB(GL_TEXTURE0_ARB);
106
 }
95
 }
107
 
96
 
108
 void TextureManager::useMultiTexture(float u, float v) {
97
 void TextureManager::useMultiTexture(float u, float v) {
109
-    if (!(mFlags & fUseMultiTexture))
110
-        return;
111
-
112
-    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u, v);
113
-    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, u, v);
98
+    useMultiTexture(u, v, u, v);
114
 }
99
 }
115
 
100
 
116
 void TextureManager::bindMultiTexture(int texture0, int texture1) {
101
 void TextureManager::bindMultiTexture(int texture0, int texture1) {
117
     assert(mTextureIds != NULL);
102
     assert(mTextureIds != NULL);
118
     assert(texture0 >= 0);
103
     assert(texture0 >= 0);
119
-    assert((unsigned int)texture0 <= mTextureCount);
120
     assert(texture1 >= 0);
104
     assert(texture1 >= 0);
105
+    assert((unsigned int)texture0 <= mTextureCount);
121
     assert((unsigned int)texture1 <= mTextureCount);
106
     assert((unsigned int)texture1 <= mTextureCount);
122
 
107
 
123
     mFlags |= fUseMultiTexture;
108
     mFlags |= fUseMultiTexture;
124
-    mTextureId  = texture0;
125
-    mTextureId2 = texture1;
126
 
109
 
127
     glActiveTextureARB(GL_TEXTURE0_ARB);
110
     glActiveTextureARB(GL_TEXTURE0_ARB);
128
     glEnable(GL_TEXTURE_2D);
111
     glEnable(GL_TEXTURE_2D);
134
 }
117
 }
135
 
118
 
136
 void TextureManager::setMaxTextureCount(unsigned int n) {
119
 void TextureManager::setMaxTextureCount(unsigned int n) {
137
-    assert(n > 0);
138
-
139
     mTextureLimit = n;
120
     mTextureLimit = n;
140
-
141
     mTextureIds = new unsigned int[n];
121
     mTextureIds = new unsigned int[n];
142
-
143
     glGenTextures(n, mTextureIds);
122
     glGenTextures(n, mTextureIds);
144
 }
123
 }
145
 
124
 
274
     assert(mTextureIds != NULL);
253
     assert(mTextureIds != NULL);
275
     assert(n <= mTextureCount);
254
     assert(n <= mTextureCount);
276
 
255
 
277
-    mTextureId = n;
278
-
279
     glEnable(GL_TEXTURE_2D);
256
     glEnable(GL_TEXTURE_2D);
280
     //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
257
     //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
281
 
258
 
283
 }
260
 }
284
 
261
 
285
 int TextureManager::loadPCX(const char *filename) {
262
 int TextureManager::loadPCX(const char *filename) {
263
+    assert(filename != NULL);
264
+    assert(filename[0] != '\0');
265
+
286
     unsigned char *image;
266
     unsigned char *image;
287
     unsigned int w, h, bpp;
267
     unsigned int w, h, bpp;
288
     ColorMode c;
268
     ColorMode c;
289
     int id = -1;
269
     int id = -1;
290
     int error = pcxLoad(filename, &image, &w, &h, &c, &bpp);
270
     int error = pcxLoad(filename, &image, &w, &h, &c, &bpp);
271
+
291
     if (error == 0) {
272
     if (error == 0) {
292
         unsigned char *image2 = scaleBuffer(image, &w, &h, bpp);
273
         unsigned char *image2 = scaleBuffer(image, &w, &h, bpp);
293
         if (image2) {
274
         if (image2) {
297
         id = loadBuffer(image, w, h, c, bpp);
278
         id = loadBuffer(image, w, h, c, bpp);
298
         delete [] image;
279
         delete [] image;
299
     }
280
     }
281
+
300
     return id;
282
     return id;
301
 }
283
 }
302
 
284
 
303
 int TextureManager::loadTGA(const char *filename) {
285
 int TextureManager::loadTGA(const char *filename) {
286
+    assert(filename != NULL);
287
+    assert(filename[0] != '\0');
288
+
304
     unsigned char *image = NULL;
289
     unsigned char *image = NULL;
305
     unsigned char *image2 = NULL;
290
     unsigned char *image2 = NULL;
306
     unsigned int w, h;
291
     unsigned int w, h;
307
     char type;
292
     char type;
308
     int id = -1;
293
     int id = -1;
309
 
294
 
310
-    assert(filename != NULL);
311
-    assert(filename[0] != '\0');
312
-
313
     if (!tgaCheck(filename)) {
295
     if (!tgaCheck(filename)) {
314
         tgaLoad(filename, &image, &w, &h, &type);
296
         tgaLoad(filename, &image, &w, &h, &type);
315
 
297
 

+ 0
- 4
src/utils/pcx.cpp Прегледај датотеку

13
 #include "global.h"
13
 #include "global.h"
14
 #include "utils/pcx.h"
14
 #include "utils/pcx.h"
15
 
15
 
16
-#ifdef DEBUG
17
 #include "Console.h"
16
 #include "Console.h"
18
 #define pcxPrint getConsole().print
17
 #define pcxPrint getConsole().print
19
-#else
20
-void pcxPrint(...) { }
21
-#endif
22
 
18
 
23
 int pcxCheck(const char *filename) {
19
 int pcxCheck(const char *filename) {
24
     assert(filename != NULL);
20
     assert(filename != NULL);

+ 0
- 4
src/utils/png.cpp Прегледај датотеку

15
 #include "utils/pixel.h"
15
 #include "utils/pixel.h"
16
 #include "utils/png.h"
16
 #include "utils/png.h"
17
 
17
 
18
-#ifdef DEBUG
19
 #include "Console.h"
18
 #include "Console.h"
20
 #define pngPrint getConsole().print
19
 #define pngPrint getConsole().print
21
-#else
22
-void pngPrint(...) { }
23
-#endif
24
 
20
 
25
 int pngCheck(const char *filename) {
21
 int pngCheck(const char *filename) {
26
     png_byte header[8];
22
     png_byte header[8];

Loading…
Откажи
Сачувај