Преглед на файлове

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
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
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
     [ 20141126 ]
8
     [ 20141126 ]
6
     * Reduced code duplication for BinaryFile/BinaryMemory
9
     * Reduced code duplication for BinaryFile/BinaryMemory
7
     * LoaderTR2 tries to load an external SFX file
10
     * LoaderTR2 tries to load an external SFX file

+ 6
- 1
include/Render.h Целия файл

120
             TextureManager::TextureStorage s = TextureManager::TextureStorage::GAME,
120
             TextureManager::TextureStorage s = TextureManager::TextureStorage::GAME,
121
             float x = 0.0f, float y = 0.0f, float w = 256.0f, float h = 256.0f);
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
   private:
126
   private:
124
 
127
 
125
     void drawTexture(float x, float y, float w, float h,
128
     void drawTexture(float x, float y, float w, float h,
126
             unsigned int texture, TextureManager::TextureStorage s);
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
     static void lightRoom(Room& room);
133
     static void lightRoom(Room& room);
129
 
134
 
130
     void drawLoadScreen();
135
     void drawLoadScreen();
165
     int mSkyMesh;                         //!< Skymesh model id
170
     int mSkyMesh;                         //!< Skymesh model id
166
     bool mSkyMeshRotation;                //!< Should Skymesh be rotated?
171
     bool mSkyMeshRotation;                //!< Should Skymesh be rotated?
167
 
172
 
168
-    int debugTexture;
173
+    int debugTexture, debugTextile;
169
     TextureManager::TextureStorage debugTextureStorage;
174
     TextureManager::TextureStorage debugTextureStorage;
170
     float debugX, debugY, debugW, debugH;
175
     float debugX, debugY, debugW, debugH;
171
 };
176
 };

+ 30
- 0
include/TextureManager.h Целия файл

9
 #ifndef _TEXTURE_MANAGER_H
9
 #ifndef _TEXTURE_MANAGER_H
10
 #define _TEXTURE_MANAGER_H
10
 #define _TEXTURE_MANAGER_H
11
 
11
 
12
+#include <cstdint>
12
 #include <vector>
13
 #include <vector>
13
 
14
 
14
 // These are loaded into TextureStorage::SYSTEM by initialize()!
15
 // These are loaded into TextureStorage::SYSTEM by initialize()!
15
 #define TEXTURE_WHITE 0
16
 #define TEXTURE_WHITE 0
16
 #define TEXTURE_SPLASH 1
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
  * \brief Texture registry
43
  * \brief Texture registry
20
  */
44
  */
59
 
83
 
60
     int loadImage(const char* filename, TextureStorage s = TextureStorage::GAME, int slot = -1);
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
   private:
90
   private:
63
     std::vector<unsigned int>& getIds(TextureStorage s);
91
     std::vector<unsigned int>& getIds(TextureStorage s);
64
 
92
 
68
 
96
 
69
     std::vector<unsigned int> mTextureIdsGame;
97
     std::vector<unsigned int> mTextureIdsGame;
70
     std::vector<unsigned int> mTextureIdsSystem;
98
     std::vector<unsigned int> mTextureIdsSystem;
99
+
100
+    std::vector<TextureTile*> tiles;
71
 };
101
 };
72
 
102
 
73
 TextureManager& getTextureManager();
103
 TextureManager& getTextureManager();

+ 31
- 0
src/Render.cpp Целия файл

30
     mFlags = (fRoomAlpha | fEntityModels | fRenderPonytail);
30
     mFlags = (fRoomAlpha | fEntityModels | fRenderPonytail);
31
 
31
 
32
     debugTexture = -1;
32
     debugTexture = -1;
33
+    debugTextile = -1;
33
     debugTextureStorage = TextureManager::TextureStorage::GAME;
34
     debugTextureStorage = TextureManager::TextureStorage::GAME;
34
     debugX = 0.0f;
35
     debugX = 0.0f;
35
     debugY = 0.0f;
36
     debugY = 0.0f;
337
             getWindow().glEnter2D();
338
             getWindow().glEnter2D();
338
             drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
339
             drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
339
             getWindow().glExit2D();
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
 
359
 
355
     if (debugTexture >= 0)
360
     if (debugTexture >= 0)
356
         drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
361
         drawTexture(debugX, debugY, debugW, debugH, debugTexture, debugTextureStorage);
362
+    else if (debugTextile >= 0)
363
+        drawTextile(debugX, debugY, debugW, debugH, debugTextile);
357
 
364
 
358
     getWindow().glExit2D();
365
     getWindow().glExit2D();
359
 
366
 
486
     debugY = y;
493
     debugY = y;
487
     debugW = w;
494
     debugW = w;
488
     debugH = h;
495
     debugH = h;
496
+    debugTextile = -1;
489
 }
497
 }
490
 
498
 
491
 void Render::drawTexture(float x, float y, float w, float h,
499
 void Render::drawTexture(float x, float y, float w, float h,
514
         glEnable(GL_LIGHTING);
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
 #include "utils/png.h"
24
 #include "utils/png.h"
25
 #endif
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
 TextureManager::~TextureManager() {
74
 TextureManager::~TextureManager() {
35
     while (mTextureIdsSystem.size() > 0) {
75
     while (mTextureIdsSystem.size() > 0) {
36
         unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1);
76
         unsigned int id = mTextureIdsSystem.at(mTextureIdsSystem.size() - 1);
43
         glDeleteTextures(1, &id);
83
         glDeleteTextures(1, &id);
44
         mTextureIdsGame.pop_back();
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
 int TextureManager::initialize() {
114
 int TextureManager::initialize() {

+ 75
- 13
src/UI.cpp Целия файл

189
             ImGui::Text("Uptime: %lums", systemTimerGet());
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
             static bool game = getGame().isLoaded();
195
             static bool game = getGame().isLoaded();
194
             static int index = 0;
196
             static int index = 0;
195
-            static bool visible = false;
196
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
197
             ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
197
-            ImGui::SliderInt("", &index, 0, getTextureManager().numTextures(
198
+            ImGui::SliderInt("##texslide", &index, 0, getTextureManager().numTextures(
198
                         game ? TextureManager::TextureStorage::GAME
199
                         game ? TextureManager::TextureStorage::GAME
199
                         : TextureManager::TextureStorage::SYSTEM) - 1);
200
                         : TextureManager::TextureStorage::SYSTEM) - 1);
200
             ImGui::PopItemWidth();
201
             ImGui::PopItemWidth();
201
             ImGui::SameLine();
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
             ImGui::SameLine();
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
             ImGui::SameLine();
231
             ImGui::SameLine();
213
-            if (ImGui::Button("Clear")) {
232
+            if (ImGui::Button("Clear##texclear")) {
214
                 getRender().debugDisplayTexture();
233
                 getRender().debugDisplayTexture();
215
-                visible = false;
234
+                visibleTex = false;
216
             }
235
             }
217
-            if (visible) {
236
+            if (visibleTex) {
218
                 getRender().debugDisplayTexture(index,
237
                 getRender().debugDisplayTexture(index,
219
                         game ? TextureManager::TextureStorage::GAME
238
                         game ? TextureManager::TextureStorage::GAME
220
                         : TextureManager::TextureStorage::SYSTEM,
239
                         : TextureManager::TextureStorage::SYSTEM,
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
         if (ImGui::CollapsingHeader("UI Help")) {
288
         if (ImGui::CollapsingHeader("UI Help")) {
228
             ImGui::ShowUserGuide();
289
             ImGui::ShowUserGuide();
229
         }
290
         }
291
+        */
230
     }
292
     }
231
     ImGui::End();
293
     ImGui::End();
232
 
294
 

+ 15
- 18
src/loader/LoaderTR2.cpp Целия файл

452
         // Index into the textile list
452
         // Index into the textile list
453
         uint16_t tile = file.readU16();
453
         uint16_t tile = file.readU16();
454
 
454
 
455
+        TextureTile* t = new TextureTile(attribute, tile);
456
+
455
         // The four corner vertices of the texture
457
         // The four corner vertices of the texture
456
         // The Pixel values are the actual coordinates of the vertexs pixel
458
         // The Pixel values are the actual coordinates of the vertexs pixel
457
         // The Coordinate values depend on where the other vertices are in
459
         // The Coordinate values depend on where the other vertices are in
458
         // the object texture. And if the object texture is used to specify
460
         // the object texture. And if the object texture is used to specify
459
         // a triangle, then the fourth vertexs values will all be zero
461
         // a triangle, then the fourth vertexs values will all be zero
460
         // Coordinate is 1 if Pixel is the low val, 255 if high val in object texture
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…
Отказ
Запис