소스 검색

LoaderTR2 tries to load object textures

Thomas Buck 9 년 전
부모
커밋
6aa059cc91
7개의 변경된 파일231개의 추가작업 그리고 37개의 파일을 삭제
  1. 3
    0
      ChangeLog.md
  2. 6
    1
      include/Render.h
  3. 30
    0
      include/TextureManager.h
  4. 31
    0
      src/Render.cpp
  5. 71
    5
      src/TextureManager.cpp
  6. 75
    13
      src/UI.cpp
  7. 15
    18
      src/loader/LoaderTR2.cpp

+ 3
- 0
ChangeLog.md 파일 보기

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141127 ]
6
+    * Started work on loading the object texture mapping, with debug UI
7
+
5 8
     [ 20141126 ]
6 9
     * Reduced code duplication for BinaryFile/BinaryMemory
7 10
     * LoaderTR2 tries to load an external SFX file

+ 6
- 1
include/Render.h 파일 보기

@@ -120,11 +120,16 @@ class Render {
120 120
             TextureManager::TextureStorage s = TextureManager::TextureStorage::GAME,
121 121
             float x = 0.0f, float y = 0.0f, float w = 256.0f, float h = 256.0f);
122 122
 
123
+    void debugDisplayTextile(int texture = -1,
124
+            float x = 0.0f, float y = 0.0f, float w = 64.0f, float h = 64.0f);
125
+
123 126
   private:
124 127
 
125 128
     void drawTexture(float x, float y, float w, float h,
126 129
             unsigned int texture, TextureManager::TextureStorage s);
127 130
 
131
+    void drawTextile(float x, float y, float w, float h, unsigned int textile);
132
+
128 133
     static void lightRoom(Room& room);
129 134
 
130 135
     void drawLoadScreen();
@@ -165,7 +170,7 @@ class Render {
165 170
     int mSkyMesh;                         //!< Skymesh model id
166 171
     bool mSkyMeshRotation;                //!< Should Skymesh be rotated?
167 172
 
168
-    int debugTexture;
173
+    int debugTexture, debugTextile;
169 174
     TextureManager::TextureStorage debugTextureStorage;
170 175
     float debugX, debugY, debugW, debugH;
171 176
 };

+ 30
- 0
include/TextureManager.h 파일 보기

@@ -9,12 +9,36 @@
9 9
 #ifndef _TEXTURE_MANAGER_H
10 10
 #define _TEXTURE_MANAGER_H
11 11
 
12
+#include <cstdint>
12 13
 #include <vector>
13 14
 
14 15
 // These are loaded into TextureStorage::SYSTEM by initialize()!
15 16
 #define TEXTURE_WHITE 0
16 17
 #define TEXTURE_SPLASH 1
17 18
 
19
+class TextureTileVertex {
20
+  public:
21
+    TextureTileVertex(uint8_t xc, uint8_t xp, uint8_t yc, uint8_t yp);
22
+
23
+    uint8_t xCoordinate, xPixel;
24
+    uint8_t yCoordinate, yPixel;
25
+};
26
+
27
+class TextureTile {
28
+  public:
29
+    TextureTile(uint16_t a, uint16_t t) : attribute(a), texture(t) { }
30
+    ~TextureTile();
31
+
32
+    void add(TextureTileVertex* t);
33
+
34
+    void displayRectangle(float x, float y, float w, float h, float z);
35
+
36
+  private:
37
+    uint16_t attribute;
38
+    uint16_t texture;
39
+    std::vector<TextureTileVertex*> vertices;
40
+};
41
+
18 42
 /*!
19 43
  * \brief Texture registry
20 44
  */
@@ -59,6 +83,10 @@ class TextureManager {
59 83
 
60 84
     int loadImage(const char* filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
61 85
 
86
+    void addTile(TextureTile* t);
87
+    int numTiles();
88
+    TextureTile& getTile(int index);
89
+
62 90
   private:
63 91
     std::vector<unsigned int>& getIds(TextureStorage s);
64 92
 
@@ -68,6 +96,8 @@ class TextureManager {
68 96
 
69 97
     std::vector<unsigned int> mTextureIdsGame;
70 98
     std::vector<unsigned int> mTextureIdsSystem;
99
+
100
+    std::vector<TextureTile*> tiles;
71 101
 };
72 102
 
73 103
 TextureManager& getTextureManager();

+ 31
- 0
src/Render.cpp 파일 보기

@@ -30,6 +30,7 @@ Render::Render() {
30 30
     mFlags = (fRoomAlpha | fEntityModels | fRenderPonytail);
31 31
 
32 32
     debugTexture = -1;
33
+    debugTextile = -1;
33 34
     debugTextureStorage = TextureManager::TextureStorage::GAME;
34 35
     debugX = 0.0f;
35 36
     debugY = 0.0f;
@@ -337,6 +338,10 @@ void Render::display() {
337 338
             getWindow().glEnter2D();
338 339
             drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
339 340
             getWindow().glExit2D();
341
+        } else if (debugTextile >= 0) {
342
+            getWindow().glEnter2D();
343
+            drawTextile(debugX, debugY, debugW, debugH, debugTextile);
344
+            getWindow().glExit2D();
340 345
         }
341 346
     }
342 347
 
@@ -354,6 +359,8 @@ void Render::drawLoadScreen() {
354 359
 
355 360
     if (debugTexture >= 0)
356 361
         drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
362
+    else if (debugTextile >= 0)
363
+        drawTextile(debugX, debugY, debugW, debugH, debugTextile);
357 364
 
358 365
     getWindow().glExit2D();
359 366
 
@@ -486,6 +493,7 @@ void Render::debugDisplayTexture(int texture, TextureManager::TextureStorage s,
486 493
     debugY = y;
487 494
     debugW = w;
488 495
     debugH = h;
496
+    debugTextile = -1;
489 497
 }
490 498
 
491 499
 void Render::drawTexture(float x, float y, float w, float h,
@@ -514,3 +522,26 @@ void Render::drawTexture(float x, float y, float w, float h,
514 522
         glEnable(GL_LIGHTING);
515 523
 }
516 524
 
525
+void Render::debugDisplayTextile(int texture, float x, float y, float w, float h) {
526
+    debugTextile = texture;
527
+    debugX = x;
528
+    debugY = y;
529
+    debugW = w;
530
+    debugH = h;
531
+    debugTexture = -1;
532
+}
533
+
534
+void Render::drawTextile(float x, float y, float w, float h, unsigned int textile) {
535
+    float z = 0.0f;
536
+
537
+    glColor3ubv(WHITE);
538
+
539
+    if (mFlags & Render::fGL_Lights)
540
+        glDisable(GL_LIGHTING);
541
+
542
+    getTextureManager().getTile(textile).displayRectangle(x, y, w, h, z);
543
+
544
+    if (mFlags & Render::fGL_Lights)
545
+        glEnable(GL_LIGHTING);
546
+}
547
+

+ 71
- 5
src/TextureManager.cpp 파일 보기

@@ -24,13 +24,53 @@
24 24
 #include "utils/png.h"
25 25
 #endif
26 26
 
27
-std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
28
-    if (s == TextureStorage::GAME)
29
-        return mTextureIdsGame;
30
-    else
31
-        return mTextureIdsSystem;
27
+TextureTileVertex::TextureTileVertex(uint8_t xc, uint8_t xp, uint8_t yc, uint8_t yp)
28
+        : xCoordinate(xc), xPixel(xp), yCoordinate(yc), yPixel(yp) { }
29
+
30
+// ----------------------------------------------------------------------------
31
+
32
+TextureTile::~TextureTile() {
33
+    while (!vertices.empty()) {
34
+        delete vertices.at(vertices.size() - 1);
35
+        vertices.pop_back();
36
+    }
32 37
 }
33 38
 
39
+void TextureTile::add(TextureTileVertex* t) {
40
+    vertices.push_back(t);
41
+}
42
+
43
+void TextureTile::displayRectangle(float x, float y, float w, float h, float z) {
44
+    assert(vertices.size() == 4);
45
+
46
+    getTextureManager().bindTextureId(texture);
47
+    //glBegin(GL_TRIANGLE_STRIP);
48
+    glBegin(GL_QUADS);
49
+
50
+    for (int i = 0; i < 4; i++) {
51
+        glTexCoord2f(vertices.at(i)->xPixel / 256.0f,
52
+                vertices.at(i)->yPixel / 256.0f);
53
+
54
+        if (vertices.at(i)->xCoordinate == 255) {
55
+            if (vertices.at(i)->yCoordinate == 255) {
56
+                glVertex3f(x + w, y + h, z);
57
+            } else {
58
+                glVertex3f(x + w, y, z);
59
+            }
60
+        } else {
61
+            if (vertices.at(i)->yCoordinate == 255) {
62
+                glVertex3f(x, y + h, z);
63
+            } else {
64
+                glVertex3f(x, y, z);
65
+            }
66
+        }
67
+    }
68
+
69
+    glEnd();
70
+}
71
+
72
+// ----------------------------------------------------------------------------
73
+
34 74
 TextureManager::~TextureManager() {
35 75
     while (mTextureIdsSystem.size() > 0) {
36 76
         unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1);
@@ -43,6 +83,32 @@ TextureManager::~TextureManager() {
43 83
         glDeleteTextures(1, &id);
44 84
         mTextureIdsGame.pop_back();
45 85
     }
86
+
87
+    while (!tiles.empty()) {
88
+        delete tiles.at(tiles.size() - 1);
89
+        tiles.pop_back();
90
+    }
91
+}
92
+
93
+void TextureManager::addTile(TextureTile* t) {
94
+    tiles.push_back(t);
95
+}
96
+
97
+int TextureManager::numTiles() {
98
+    return tiles.size();
99
+}
100
+
101
+TextureTile& TextureManager::getTile(int index) {
102
+    assert(index >= 0);
103
+    assert(index < tiles.size());
104
+    return *tiles.at(index);
105
+}
106
+
107
+std::vector<unsigned int>& TextureManager::getIds(TextureStorage s) {
108
+    if (s == TextureStorage::GAME)
109
+        return mTextureIdsGame;
110
+    else
111
+        return mTextureIdsSystem;
46 112
 }
47 113
 
48 114
 int TextureManager::initialize() {

+ 75
- 13
src/UI.cpp 파일 보기

@@ -189,32 +189,51 @@ void UI::display() {
189 189
             ImGui::Text("Uptime: %lums", systemTimerGet());
190 190
         }
191 191
 
192
-        if (ImGui::CollapsingHeader("GL Textures")) {
192
+        static bool visibleTex = false;
193
+        static bool visibleTile = false;
194
+        if (ImGui::CollapsingHeader("Textures")) {
193 195
             static bool game = getGame().isLoaded();
194 196
             static int index = 0;
195
-            static bool visible = false;
196 197
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
197
-            ImGui::SliderInt("", &index, 0, getTextureManager().numTextures(
198
+            ImGui::SliderInt("##texslide", &index, 0, getTextureManager().numTextures(
198 199
                         game ? TextureManager::TextureStorage::GAME
199 200
                         : TextureManager::TextureStorage::SYSTEM) - 1);
200 201
             ImGui::PopItemWidth();
201 202
             ImGui::SameLine();
202
-            if (ImGui::Checkbox("Game", &game)) {
203
-                if (game && (getTextureManager().numTextures(
204
-                        game ? TextureManager::TextureStorage::GAME
205
-                        : TextureManager::TextureStorage::SYSTEM) <= 0))
206
-                    game = false;
203
+            if (ImGui::Button("+##texplus")) {
204
+                if (index < (getTextureManager().numTextures(
205
+                                game ? TextureManager::TextureStorage::GAME
206
+                                : TextureManager::TextureStorage::SYSTEM) - 1))
207
+                    index++;
208
+                else
209
+                    index = 0;
210
+            }
211
+            ImGui::SameLine();
212
+            if (ImGui::Button("-##texminus")) {
213
+                if (index > 0)
214
+                    index--;
215
+                else
216
+                    index = getTextureManager().numTextures(
217
+                                game ? TextureManager::TextureStorage::GAME
218
+                                : TextureManager::TextureStorage::SYSTEM) - 1;
219
+            }
220
+            ImGui::SameLine();
221
+            if ((getTextureManager().numTextures() > 0)) {
222
+                ImGui::Checkbox("Game##texgame", &game);
223
+            } else {
224
+                game = false;
207 225
             }
208 226
             ImGui::SameLine();
209
-            if (ImGui::Button("Show")) {
210
-                visible = true;
227
+            if (ImGui::Button("Show##texshow")) {
228
+                visibleTex = true;
229
+                visibleTile = false;
211 230
             }
212 231
             ImGui::SameLine();
213
-            if (ImGui::Button("Clear")) {
232
+            if (ImGui::Button("Clear##texclear")) {
214 233
                 getRender().debugDisplayTexture();
215
-                visible = false;
234
+                visibleTex = false;
216 235
             }
217
-            if (visible) {
236
+            if (visibleTex) {
218 237
                 getRender().debugDisplayTexture(index,
219 238
                         game ? TextureManager::TextureStorage::GAME
220 239
                         : TextureManager::TextureStorage::SYSTEM,
@@ -224,9 +243,52 @@ void UI::display() {
224 243
             }
225 244
         }
226 245
 
246
+        if (ImGui::CollapsingHeader("Textiles")) {
247
+            if (getTextureManager().numTiles() > 0) {
248
+                static int index = 0;
249
+                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
250
+                ImGui::SliderInt("##tileslide", &index, 0, getTextureManager().numTiles() - 1);
251
+                ImGui::PopItemWidth();
252
+                ImGui::SameLine();
253
+                if (ImGui::Button("+##tileplus")) {
254
+                    if (index < (getTextureManager().numTiles() - 1))
255
+                        index++;
256
+                    else
257
+                        index = 0;
258
+                }
259
+                ImGui::SameLine();
260
+                if (ImGui::Button("-##tileminus")) {
261
+                    if (index > 0)
262
+                        index--;
263
+                    else
264
+                        index = getTextureManager().numTiles() - 1;
265
+                }
266
+                ImGui::SameLine();
267
+                if (ImGui::Button("Show##tileshow")) {
268
+                    visibleTile = true;
269
+                    visibleTex = false;
270
+                }
271
+                ImGui::SameLine();
272
+                if (ImGui::Button("Clear##tileclear")) {
273
+                    getRender().debugDisplayTextile();
274
+                    visibleTile = false;
275
+                }
276
+                if (visibleTile) {
277
+                    getRender().debugDisplayTextile(index,
278
+                            ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
279
+                            ImGui::GetWindowPos().y,
280
+                            (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
281
+                }
282
+            } else {
283
+                ImGui::Text("Please load a level!");
284
+            }
285
+        }
286
+
287
+        /*
227 288
         if (ImGui::CollapsingHeader("UI Help")) {
228 289
             ImGui::ShowUserGuide();
229 290
         }
291
+        */
230 292
     }
231 293
     ImGui::End();
232 294
 

+ 15
- 18
src/loader/LoaderTR2.cpp 파일 보기

@@ -452,30 +452,27 @@ void LoaderTR2::loadTextures() {
452 452
         // Index into the textile list
453 453
         uint16_t tile = file.readU16();
454 454
 
455
+        TextureTile* t = new TextureTile(attribute, tile);
456
+
455 457
         // The four corner vertices of the texture
456 458
         // The Pixel values are the actual coordinates of the vertexs pixel
457 459
         // The Coordinate values depend on where the other vertices are in
458 460
         // the object texture. And if the object texture is used to specify
459 461
         // a triangle, then the fourth vertexs values will all be zero
460 462
         // Coordinate is 1 if Pixel is the low val, 255 if high val in object texture
461
-        uint8_t xCoordinate1 = file.readU8();
462
-        uint8_t xPixel1 = file.readU8();
463
-        uint8_t yCoordinate1 = file.readU8();
464
-        uint8_t yPixel1 = file.readU8();
465
-        uint8_t xCoordinate2 = file.readU8();
466
-        uint8_t xPixel2 = file.readU8();
467
-        uint8_t yCoordinate2 = file.readU8();
468
-        uint8_t yPixel2 = file.readU8();
469
-        uint8_t xCoordinate3 = file.readU8();
470
-        uint8_t xPixel3 = file.readU8();
471
-        uint8_t yCoordinate3 = file.readU8();
472
-        uint8_t yPixel3 = file.readU8();
473
-        uint8_t xCoordinate4 = file.readU8();
474
-        uint8_t xPixel4 = file.readU8();
475
-        uint8_t yCoordinate4 = file.readU8();
476
-        uint8_t yPixel4 = file.readU8();
477
-
478
-        // TODO store object textures somewhere
463
+        for (int i = 0; i < 4; i++) {
464
+            uint8_t xCoordinate = file.readU8();
465
+            uint8_t xPixel = file.readU8();
466
+            uint8_t yCoordinate = file.readU8();
467
+            uint8_t yPixel = file.readU8();
468
+
469
+            assert((xCoordinate != 1) || (xCoordinate != 255));
470
+            assert((yCoordinate != 1) || (yCoordinate != 255));
471
+
472
+            t->add(new TextureTileVertex(xCoordinate, xPixel, yCoordinate, yPixel));
473
+        }
474
+
475
+        getTextureManager().addTile(t);
479 476
     }
480 477
 }
481 478
 

Loading…
취소
저장