Sfoglia il codice sorgente

Using only colors that were defined for renderer

Thomas Buck 10 anni fa
parent
commit
4d98afd2aa
7 ha cambiato i file con 69 aggiunte e 78 eliminazioni
  1. 1
    1
      include/Window.h
  2. 1
    1
      include/WindowSDL.h
  3. 12
    1
      include/global.h
  4. 5
    5
      src/Console.cpp
  5. 8
    13
      src/Menu.cpp
  6. 37
    52
      src/Render.cpp
  7. 5
    5
      src/WindowSDL.cpp

+ 1
- 1
include/Window.h Vedi File

@@ -55,7 +55,7 @@ public:
55 55
 
56 56
     virtual void writeString(WindowString *s) = 0;
57 57
 
58
-    virtual void drawText(unsigned int x, unsigned int y, float scale, unsigned char *color, const char *s, ...)
58
+    virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
59 59
         __attribute__((format(printf, 6, 0))) = 0;
60 60
 
61 61
     unsigned int mWidth;

+ 1
- 1
include/WindowSDL.h Vedi File

@@ -61,7 +61,7 @@ public:
61 61
 
62 62
     virtual void writeString(WindowString *s);
63 63
 
64
-    virtual void drawText(unsigned int x, unsigned int y, float scale, unsigned char *color, const char *s, ...)
64
+    virtual void drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...)
65 65
         __attribute__((format(printf, 6, 0)));
66 66
 
67 67
 private:

+ 12
- 1
include/global.h Vedi File

@@ -7,6 +7,17 @@
7 7
 #ifndef _GLOBAL_H_
8 8
 #define _GLOBAL_H_
9 9
 
10
+const float BLACK[]       = {  0.0f,  0.0f,  0.0f, 1.0f };
11
+const float DIM_WHITE[]   = {  0.5f,  0.5f,  0.5f, 1.0f };
12
+const float WHITE[]       = {  1.0f,  1.0f,  1.0f, 1.0f };
13
+const float RED[]         = {  1.0f,  0.0f,  0.0f, 1.0f };
14
+const float GREEN[]       = {  0.0f,  1.0f,  0.0f, 1.0f };
15
+const float NEXT_PURPLE[] = {  0.3f,  0.3f,  0.5f, 1.0f };
16
+const float OR_BLUE[]     = {  0.5f,  0.7f,  1.0f, 1.0f };
17
+const float PINK[]        = {  1.0f,  0.0f,  1.0f, 1.0f };
18
+const float YELLOW[]      = {  1.0f,  1.0f,  0.0f, 1.0f };
19
+const float CYAN[]        = {  0.0f,  1.0f,  1.0f, 1.0f };
20
+
10 21
 typedef enum {
11 22
     menuAction = 0,
12 23
     consoleAction, // menu and console should always be the first two items
@@ -61,7 +72,7 @@ typedef struct {
61 72
     int w;
62 73
     int h;
63 74
     float scale;
64
-    unsigned char color[4];
75
+    float color[4];
65 76
 } WindowString;
66 77
 
67 78
 #endif

+ 5
- 5
src/Console.cpp Vedi File

@@ -14,6 +14,7 @@
14 14
 #endif
15 15
 
16 16
 #include "config.h"
17
+#include "global.h"
17 18
 #include "Console.h"
18 19
 #include "main.h"
19 20
 #include "utils/strings.h"
@@ -90,7 +91,6 @@ void Console::print(const char *s, ...) {
90 91
 
91 92
 void Console::display() {
92 93
     Window *window = gOpenRaider->mWindow;
93
-    unsigned char color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
94 94
 
95 95
     if (mVisible) {
96 96
         // Calculate line drawing geometry
@@ -110,7 +110,7 @@ void Console::display() {
110 110
             scrollIndicator = 100;
111 111
         }
112 112
 
113
-        gOpenRaider->mWindow->drawText(10, 10, 0.70f, color,
113
+        gOpenRaider->mWindow->drawText(10, 10, 0.70f, OR_BLUE,
114 114
                 "%s uptime %lus scroll %d%%", VERSION, systemTimerGet() / 1000, scrollIndicator);
115 115
 
116 116
         // Draw output log
@@ -125,14 +125,14 @@ void Console::display() {
125 125
         }
126 126
         for (int i = 0; i < end; i++) {
127 127
             gOpenRaider->mWindow->drawText(10, ((i + drawOffset) * lineSteps) + firstLine,
128
-                    0.75f, color, "%s", mHistory[i + historyOffset - mLineOffset]);
128
+                    0.75f, OR_BLUE, "%s", mHistory[i + historyOffset - mLineOffset]);
129 129
         }
130 130
 
131 131
         // Draw current input
132 132
         if ((mInputBufferPointer > 0) && (mInputBuffer[0] != '\0')) {
133
-            gOpenRaider->mWindow->drawText(10, inputLine, 0.75f, color, "> %s", mInputBuffer);
133
+            gOpenRaider->mWindow->drawText(10, inputLine, 0.75f, OR_BLUE, "> %s", mInputBuffer);
134 134
         } else {
135
-            gOpenRaider->mWindow->drawText(10, inputLine, 0.75f, color, ">");
135
+            gOpenRaider->mWindow->drawText(10, inputLine, 0.75f, OR_BLUE, ">");
136 136
         }
137 137
 
138 138
         //! \todo display the current mPartialInput. The UTF-8 segfaults SDL-TTF, somehow?

+ 8
- 13
src/Menu.cpp Vedi File

@@ -14,6 +14,7 @@
14 14
 #endif
15 15
 
16 16
 #include "config.h"
17
+#include "global.h"
17 18
 #include "main.h"
18 19
 #include "Menu.h"
19 20
 #include "utils/strings.h"
@@ -75,19 +76,15 @@ void Menu::displayMapList() {
75 76
 
76 77
     for (int i = 0; i < (max - min); i++) {
77 78
         char *map = gOpenRaider->mMapList[i + min];
78
-        unsigned char color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
79
-        if ((i + min) == (int)mCursor) {
80
-            // Less greem & red --> highlight in red
81
-            color[1] = 0x42;
82
-            color[2] = 0x42;
83
-        }
84
-        gOpenRaider->mWindow->drawText(25, 100 + (25 * i), 0.75f, color, "%s", map);
79
+        if ((i + min) == (int)mCursor)
80
+            gOpenRaider->mWindow->drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
81
+        else
82
+            gOpenRaider->mWindow->drawText(25, 100 + (25 * i), 0.75f, OR_BLUE, "%s", map);
85 83
     }
86 84
 }
87 85
 
88 86
 void Menu::display() {
89 87
     Window *window = gOpenRaider->mWindow;
90
-    unsigned char color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
91 88
 
92 89
     if (mVisible) {
93 90
         // Draw half-transparent *overlay*
@@ -101,19 +98,17 @@ void Menu::display() {
101 98
         window->writeString(&mainText);
102 99
 
103 100
         if (!gOpenRaider->mMapListFilled) {
104
-            gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, color, "Generating map list...");
101
+            gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, OR_BLUE, "Generating map list...");
105 102
         } else {
106 103
             if (gOpenRaider->mMapList.size() == 0) {
107
-                gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, color, "No maps found! See README.md");
104
+                gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, RED, "No maps found! See README.md");
108 105
             } else {
109 106
                 // draw *play button* above list
110 107
                 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
111 108
                 glDisable(GL_TEXTURE_2D);
112 109
                 glRecti(25, 25, 100, 75);
113 110
                 glEnable(GL_TEXTURE_2D);
114
-                color[0] = color[1] = color[2] = 0x00;
115
-                gOpenRaider->mWindow->drawText(40, 35, 0.75f, color, "Play");
116
-                color[0] = color[1] = color[2] = 0xFF;
111
+                gOpenRaider->mWindow->drawText(40, 35, 0.75f, BLACK, "Play");
117 112
 
118 113
                 displayMapList();
119 114
             }

+ 37
- 52
src/Render.cpp Vedi File

@@ -24,27 +24,12 @@
24 24
 #include "Emitter.h"
25 25
 #endif
26 26
 
27
+#include "global.h"
27 28
 #include "main.h"
28 29
 #include "Game.h"
29 30
 #include "OpenRaider.h"
30 31
 #include "Render.h"
31 32
 
32
-//! \fixme Should be changed
33
-#define LARA gOpenRaider->mGame->mLara
34
-#define gWorld gOpenRaider->mGame->mWorld
35
-
36
-// Colors
37
-const float BLACK[]       = {  0.0f,  0.0f,  0.0f, 1.0f };
38
-const float DIM_WHITE[]   = {  0.5f,  0.5f,  0.5f, 1.0f };
39
-const float WHITE[]       = {  1.0f,  1.0f,  1.0f, 1.0f };
40
-const float RED[]         = {  1.0f,  0.0f,  0.0f, 1.0f };
41
-const float GREEN[]       = {  0.0f,  1.0f,  0.0f, 1.0f };
42
-const float NEXT_PURPLE[] = {  0.3f,  0.3f,  0.5f, 1.0f };
43
-//const float OR_BLUE[]     = {  0.5f,  0.7f,  1.0f, 1.0f };
44
-const float PINK[]        = {  1.0f,  0.0f,  1.0f, 1.0f };
45
-const float YELLOW[]      = {  1.0f,  1.0f,  0.0f, 1.0f };
46
-const float CYAN[]        = {  0.0f,  1.0f,  1.0f, 1.0f };
47
-
48 33
 ViewVolume gViewVolume; /* View volume for frustum culling */
49 34
 
50 35
 void Render::drawLoadScreen()
@@ -325,7 +310,7 @@ void Render::initEmitter(const char *name, unsigned int size,
325 310
 
326 311
 void Render::ClearWorld()
327 312
 {
328
-    LARA = NULL;
313
+    gOpenRaider->mGame->mLara = NULL;
329 314
 
330 315
     mRoomRenderList.clear();
331 316
 
@@ -599,14 +584,14 @@ void Render::Display()
599 584
 
600 585
     index = -1;
601 586
 
602
-    if (LARA)
587
+    if (gOpenRaider->mGame->mLara)
603 588
     {
604 589
         float yaw;
605 590
         int sector;
606 591
         float camOffsetH = 0.0f;
607 592
 
608 593
 
609
-        switch (LARA->moveType)
594
+        switch (gOpenRaider->mGame->mLara->moveType)
610 595
         {
611 596
             case worldMoveType_fly:
612 597
             case worldMoveType_noClipping:
@@ -619,12 +604,12 @@ void Render::Display()
619 604
                 break;
620 605
         }
621 606
 
622
-        curPos[0] = LARA->pos[0];
623
-        curPos[1] = LARA->pos[1];
624
-        curPos[2] = LARA->pos[2];
625
-        yaw = LARA->angles[1];
607
+        curPos[0] = gOpenRaider->mGame->mLara->pos[0];
608
+        curPos[1] = gOpenRaider->mGame->mLara->pos[1];
609
+        curPos[2] = gOpenRaider->mGame->mLara->pos[2];
610
+        yaw = gOpenRaider->mGame->mLara->angles[1];
626 611
 
627
-        index = LARA->room;
612
+        index = gOpenRaider->mGame->mLara->room;
628 613
 
629 614
         // Mongoose 2002.08.24, New 3rd person camera hack
630 615
         camPos[0] = curPos[0];
@@ -634,10 +619,10 @@ void Render::Display()
634 619
         camPos[0] -= (1024.0f * sinf(yaw));
635 620
         camPos[2] -= (1024.0f * cosf(yaw));
636 621
 
637
-        sector = gWorld.getSector(index, camPos[0], camPos[2]);
622
+        sector = gOpenRaider->mGame->mWorld.getSector(index, camPos[0], camPos[2]);
638 623
 
639 624
         // Handle camera out of world
640
-        if (sector < 0 || gWorld.isWall(index, sector))
625
+        if (sector < 0 || gOpenRaider->mGame->mWorld.isWall(index, sector))
641 626
         {
642 627
             camPos[0] = curPos[0] + (64.0f * sinf(yaw));
643 628
             camPos[1] -= 64.0f;
@@ -663,33 +648,33 @@ void Render::Display()
663 648
     updateViewVolume();
664 649
 
665 650
     // Let's see the LoS -- should be event controled
666
-    if (LARA)
651
+    if (gOpenRaider->mGame->mLara)
667 652
     {
668
-        //      SkeletalModel *mdl = (SkeletalModel *)LARA->tmpHook;
653
+        //      SkeletalModel *mdl = (SkeletalModel *)gOpenRaider->mGame->mLara->tmpHook;
669 654
 
670 655
         // Draw in solid colors
671 656
         glDisable(GL_TEXTURE_2D);
672 657
         glDisable(GL_CULL_FACE);
673 658
 
674
-        if (LARA->state == 64) // eWeaponFire
659
+        if (gOpenRaider->mGame->mLara->state == 64) // eWeaponFire
675 660
         {
676 661
             vec3_t u, v; //, s, t;
677 662
 
678
-            // Center of LARA
663
+            // Center of gOpenRaider->mGame->mLara
679 664
             u[0] = curPos[0];
680 665
             u[1] = curPos[1] - 512.0f;
681 666
             u[2] = curPos[2];
682 667
 
683
-            // Location LARA is aiming at?  ( Not finished yet )
684
-            v[0] = u[0] + (9000.0f * sinf(LARA->angles[1]));
685
-            v[1] = u[1] + (9000.0f * sinf(LARA->angles[2]));
686
-            v[2] = u[2] + (9000.0f * cosf(LARA->angles[1]));
668
+            // Location gOpenRaider->mGame->mLara is aiming at?  ( Not finished yet )
669
+            v[0] = u[0] + (9000.0f * sinf(gOpenRaider->mGame->mLara->angles[1]));
670
+            v[1] = u[1] + (9000.0f * sinf(gOpenRaider->mGame->mLara->angles[2]));
671
+            v[2] = u[2] + (9000.0f * cosf(gOpenRaider->mGame->mLara->angles[1]));
687 672
 
688 673
             // Test tracing of aim
689 674
             renderTrace(0, u, v); // v = target
690 675
         }
691 676
 
692
-        entity_t *route = LARA->master;
677
+        entity_t *route = gOpenRaider->mGame->mLara->master;
693 678
 
694 679
         while (route)
695 680
         {
@@ -733,14 +718,14 @@ void Render::Display()
733 718
     {
734 719
         entity_t *e;
735 720
         std::vector<entity_t *> entityRenderList;
736
-        std::vector<entity_t *> *entities = gWorld.getEntities();
721
+        std::vector<entity_t *> *entities = gOpenRaider->mGame->mWorld.getEntities();
737 722
 
738 723
         for (unsigned int i = 0; i < entities->size(); i++)
739 724
         {
740 725
             e = entities->at(i);
741 726
 
742 727
             // Mongoose 2002.03.26, Don't show lara to it's own player
743
-            if (!e || e == LARA)
728
+            if (!e || e == gOpenRaider->mGame->mLara)
744 729
             {
745 730
                 continue;
746 731
             }
@@ -979,7 +964,7 @@ void Render::buildRoomRenderList(RenderRoom *rRoom)
979 964
 
980 965
 void Render::drawSkyMesh(float scale)
981 966
 {
982
-    skeletal_model_t *model = gWorld.getModel(mSkyMesh);
967
+    skeletal_model_t *model = gOpenRaider->mGame->mWorld.getModel(mSkyMesh);
983 968
 
984 969
 
985 970
     if (!model)
@@ -996,7 +981,7 @@ void Render::drawSkyMesh(float scale)
996 981
     glTranslated(0.0, 1000.0, 0.0);
997 982
     glScaled(scale, scale, scale);
998 983
     //drawModel(model);
999
-    //drawModelMesh(gWorld.getMesh(mSkyMesh), );
984
+    //drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mSkyMesh), );
1000 985
     glPopMatrix();
1001 986
     glEnable(GL_DEPTH_TEST);
1002 987
 }
@@ -1012,15 +997,15 @@ void Render::drawObjects()
1012 997
 
1013 998
 
1014 999
     // Draw lara or other player model ( move to entity rendering method )
1015
-    if (mFlags & Render::fViewModel && LARA && LARA->tmpHook)
1000
+    if (mFlags & Render::fViewModel && gOpenRaider->mGame->mLara && gOpenRaider->mGame->mLara->tmpHook)
1016 1001
     {
1017
-        SkeletalModel *mdl = static_cast<SkeletalModel *>(LARA->tmpHook);
1002
+        SkeletalModel *mdl = static_cast<SkeletalModel *>(gOpenRaider->mGame->mLara->tmpHook);
1018 1003
 
1019 1004
         if (mdl)
1020 1005
         {
1021 1006
 
1022 1007
             // Mongoose 2002.03.22, Test 'idle' aniamtions
1023
-            if (!LARA->moving)
1008
+            if (!gOpenRaider->mGame->mLara->moving)
1024 1009
             {
1025 1010
                 frame = mdl->getIdleAnimation();
1026 1011
 
@@ -1051,11 +1036,11 @@ void Render::drawObjects()
1051 1036
         glRotated(gOpenRaider->mGame->mCamera->getYaw(), 0, 1, 0);
1052 1037
         glTranslated(0, 500, 1200);
1053 1038
 #else
1054
-        glTranslated(LARA->pos[0], LARA->pos[1], LARA->pos[2]);
1039
+        glTranslated(gOpenRaider->mGame->mLara->pos[0], gOpenRaider->mGame->mLara->pos[1], gOpenRaider->mGame->mLara->pos[2]);
1055 1040
         glRotated(gOpenRaider->mGame->mCamera->getYaw(), 0, 1, 0);
1056 1041
 #endif
1057 1042
 
1058
-        drawModel(static_cast<SkeletalModel *>(LARA->tmpHook));
1043
+        drawModel(static_cast<SkeletalModel *>(gOpenRaider->mGame->mLara->tmpHook));
1059 1044
         glPopMatrix();
1060 1045
     }
1061 1046
 
@@ -1064,7 +1049,7 @@ void Render::drawObjects()
1064 1049
     {
1065 1050
         std::vector<sprite_seq_t *> *sprites;
1066 1051
 
1067
-        sprites = gWorld.getSprites();
1052
+        sprites = gOpenRaider->mGame->mWorld.getSprites();
1068 1053
 
1069 1054
         for (unsigned int i = 0; i < sprites->size(); i++)
1070 1055
         {
@@ -1184,7 +1169,7 @@ void Render::drawModel(SkeletalModel *model)
1184 1169
 
1185 1170
                 if (tag2)
1186 1171
                 {
1187
-                    drawModelMesh(gWorld.getMesh(tag2->mesh), Render::skeletalMesh);
1172
+                    drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(tag2->mesh), Render::skeletalMesh);
1188 1173
                 }
1189 1174
             }
1190 1175
         }
@@ -1227,19 +1212,19 @@ void Render::drawModel(SkeletalModel *model)
1227 1212
                     {
1228 1213
                         glPushMatrix();
1229 1214
                         glTranslatef(mdl->ponyOff2, 0.0, 0.0);
1230
-                        drawModelMesh(gWorld.getMesh(mdl->ponytailMeshId + i),
1215
+                        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mdl->ponytailMeshId + i),
1231 1216
                                 Render::skeletalMesh);
1232 1217
                         glPopMatrix();
1233 1218
 
1234 1219
                         glPushMatrix();
1235 1220
                         glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
1236
-                        drawModelMesh(gWorld.getMesh(mdl->ponytailMeshId + i),
1221
+                        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mdl->ponytailMeshId + i),
1237 1222
                                 Render::skeletalMesh);
1238 1223
                         glPopMatrix();
1239 1224
                     }
1240 1225
                     else
1241 1226
                     {
1242
-                        drawModelMesh(gWorld.getMesh(mdl->ponytailMeshId + i),
1227
+                        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(mdl->ponytailMeshId + i),
1243 1228
                                 Render::skeletalMesh);
1244 1229
                     }
1245 1230
                 }
@@ -1253,7 +1238,7 @@ void Render::drawModel(SkeletalModel *model)
1253 1238
             }
1254 1239
         }
1255 1240
 
1256
-        drawModelMesh(gWorld.getMesh(tag->mesh), Render::skeletalMesh);
1241
+        drawModelMesh(gOpenRaider->mGame->mWorld.getMesh(tag->mesh), Render::skeletalMesh);
1257 1242
     }
1258 1243
 
1259 1244
     // Cycle frames ( cheap hack from old ent state based system )
@@ -1635,7 +1620,7 @@ void Render::drawRoomModel(static_model_t *mesh)
1635 1620
     if (!mesh)
1636 1621
         return;
1637 1622
 
1638
-    r_mesh = gWorld.getMesh(mesh->index);
1623
+    r_mesh = gOpenRaider->mGame->mWorld.getMesh(mesh->index);
1639 1624
 
1640 1625
     if (!r_mesh)
1641 1626
         return;
@@ -1885,7 +1870,7 @@ void Render::ViewModel(entity_t *ent, int index)
1885 1870
         return;
1886 1871
     }
1887 1872
 
1888
-    model = gWorld.getModel(index);
1873
+    model = gOpenRaider->mGame->mWorld.getModel(index);
1889 1874
 
1890 1875
     if (model)
1891 1876
     {

+ 5
- 5
src/WindowSDL.cpp Vedi File

@@ -546,10 +546,10 @@ void WindowSDL::writeString(WindowString *s) {
546 546
     assert(mInit == true);
547 547
 
548 548
     SDL_Color color;
549
-    color.r = s->color[0];
550
-    color.g = s->color[1];
551
-    color.b = s->color[2];
552
-    color.a = s->color[3];
549
+    color.r = (unsigned char)(s->color[0] * 255.0f);
550
+    color.g = (unsigned char)(s->color[1] * 255.0f);
551
+    color.b = (unsigned char)(s->color[2] * 255.0f);
552
+    color.a = (unsigned char)(s->color[3] * 255.0f);
553 553
 
554 554
     SDL_Surface *surface = TTF_RenderUTF8_Blended(mFont, s->text, color);
555 555
     if (surface == NULL) {
@@ -599,7 +599,7 @@ void WindowSDL::writeString(WindowString *s) {
599 599
     SDL_FreeSurface(surface);
600 600
 }
601 601
 
602
-void WindowSDL::drawText(unsigned int x, unsigned int y, float scale, unsigned char *color, const char *s, ...) {
602
+void WindowSDL::drawText(unsigned int x, unsigned int y, float scale, const float color[4], const char *s, ...) {
603 603
     va_list args;
604 604
     va_start(args, s);
605 605
     vsnprintf(tempText.text, 256, s, args);

Loading…
Annulla
Salva