Browse Source

textile triangle display

Thomas Buck 9 years ago
parent
commit
def2a75125
6 changed files with 85 additions and 20 deletions
  1. 1
    0
      ChangeLog.md
  2. 4
    1
      include/TextureManager.h
  3. 7
    9
      src/Game.cpp
  4. 1
    1
      src/Render.cpp
  5. 65
    5
      src/TextureManager.cpp
  6. 7
    4
      src/UI.cpp

+ 1
- 0
ChangeLog.md View File

@@ -4,6 +4,7 @@
4 4
 
5 5
     [ 20141127 ]
6 6
     * Started work on loading the object texture mapping, with debug UI
7
+    * Textiles debug UI also draws triangles “properly”
7 8
 
8 9
     [ 20141126 ]
9 10
     * Reduced code duplication for BinaryFile/BinaryMemory

+ 4
- 1
include/TextureManager.h View File

@@ -30,10 +30,13 @@ class TextureTile {
30 30
     ~TextureTile();
31 31
 
32 32
     void add(TextureTileVertex* t);
33
+    bool isTriangle();
34
+    void display(float x, float y, float w, float h, float z);
33 35
 
36
+  private:
37
+    void displayTriangle(float x, float y, float w, float h, float z);
34 38
     void displayRectangle(float x, float y, float w, float h, float z);
35 39
 
36
-  private:
37 40
     uint16_t attribute;
38 41
     uint16_t texture;
39 42
     std::vector<TextureTileVertex*> vertices;

+ 7
- 9
src/Game.cpp View File

@@ -73,20 +73,16 @@ int Game::loadLevel(const char* level) {
73 73
     auto loader = Loader::createLoader(level);
74 74
     if (loader) {
75 75
         // First Loader test
76
+        getLog() << "Trying to load using new loader..." << Log::endl;
76 77
         error = loader->load(level);
77
-        if (error == 0) {
78
-            getLog() << "Tried new Loader (0)..." << Log::endl;
79
-        } else {
78
+        if (error != 0) {
80 79
             getLog() << "Error while trying new loader (" << error << ")..." << Log::endl;
80
+            destroy();
81 81
         }
82 82
     }
83 83
 
84 84
     if ((!loader) || (error != 0)) {
85
-        // Clean-Up between new & old loader
86
-        if (error != 0)
87
-            destroy();
88
-
89
-        // Old TombRaider level loader
85
+        getLog() << "Falling back to old level loader..." << Log::endl;
90 86
         error = mTombRaider.Load(levelName.c_str());
91 87
         if (error != 0)
92 88
             return error;
@@ -99,7 +95,9 @@ int Game::loadLevel(const char* level) {
99 95
             tmp += "MAIN.SFX";
100 96
             error = mTombRaider.loadSFX(tmp.c_str());
101 97
             if (error != 0)
102
-                getLog() << "Could not load " << tmp << Log::endl;
98
+                getLog() << "Could not load SFX " << tmp << Log::endl;
99
+            else
100
+                getLog() << "Loaded external SFX file!" << Log::endl;
103 101
         }
104 102
 
105 103
         // Process data

+ 1
- 1
src/Render.cpp View File

@@ -539,7 +539,7 @@ void Render::drawTextile(float x, float y, float w, float h, unsigned int textil
539 539
     if (mFlags & Render::fGL_Lights)
540 540
         glDisable(GL_LIGHTING);
541 541
 
542
-    getTextureManager().getTile(textile).displayRectangle(x, y, w, h, z);
542
+    getTextureManager().getTile(textile).display(x, y, w, h, z);
543 543
 
544 544
     if (mFlags & Render::fGL_Lights)
545 545
         glEnable(GL_LIGHTING);

+ 65
- 5
src/TextureManager.cpp View File

@@ -40,14 +40,75 @@ void TextureTile::add(TextureTileVertex* t) {
40 40
     vertices.push_back(t);
41 41
 }
42 42
 
43
-void TextureTile::displayRectangle(float x, float y, float w, float h, float z) {
44
-    assert(vertices.size() == 4);
43
+bool TextureTile::isTriangle() {
44
+    assert(vertices.size() >= 3);
45
+
46
+    if (vertices.size() == 3)
47
+        return true;
48
+
49
+    return ((vertices.at(3)->xPixel == 0)
50
+            & (vertices.at(3)->xCoordinate == 0)
51
+            & (vertices.at(3)->yPixel == 0)
52
+            & (vertices.at(3)->yCoordinate == 0));
53
+}
45 54
 
55
+void TextureTile::display(float x, float y, float w, float h, float z) {
46 56
     getTextureManager().bindTextureId(texture);
47
-    //glBegin(GL_TRIANGLE_STRIP);
48
-    glBegin(GL_QUADS);
49 57
 
58
+    //! \fixme TR Rosetta Stone says this, but looks strange?
59
+    /*
60
+    if (attribute == 0) {
61
+        // Ignore transparency
62
+        glDisable(GL_BLEND);
63
+    }
64
+    */
65
+
66
+    if (isTriangle())
67
+        displayTriangle(x, y, w, h, z);
68
+    else
69
+        displayRectangle(x, y, w, h, z);
70
+
71
+    /*
72
+    if (attribute == 0) {
73
+        glEnable(GL_BLEND);
74
+    }
75
+    */
76
+}
77
+
78
+void TextureTile::displayRectangle(float x, float y, float w, float h, float z) {
79
+    float xmin = 256.0f, xmax = 0.0f;
80
+    float ymin = 256.0f, ymax = 0.0f;
50 81
     for (int i = 0; i < 4; i++) {
82
+        if (vertices.at(i)->xCoordinate == 255) {
83
+            if (vertices.at(i)->xPixel > xmax)
84
+                xmax = vertices.at(i)->xPixel;
85
+        } else {
86
+            if (vertices.at(i)->xPixel < xmin)
87
+                xmin = vertices.at(i)->xPixel;
88
+        }
89
+
90
+        if (vertices.at(i)->yCoordinate == 255) {
91
+            ymax = vertices.at(i)->yPixel;
92
+        } else {
93
+            ymin = vertices.at(i)->yPixel;
94
+        }
95
+    }
96
+
97
+    glBegin(GL_QUADS);
98
+    glTexCoord2f(xmin / 256.0f, ymin / 256.0f);
99
+    glVertex3f(x, y, z);
100
+    glTexCoord2f(xmax / 256.0f, ymin / 256.0f);
101
+    glVertex3f(x + w, y, z);
102
+    glTexCoord2f(xmax / 256.0f, ymax / 256.0f);
103
+    glVertex3f(x + w, y + h, z);
104
+    glTexCoord2f(xmin / 256.0f, ymax / 256.0f);
105
+    glVertex3f(x, y + h, z);
106
+    glEnd();
107
+}
108
+
109
+void TextureTile::displayTriangle(float x, float y, float w, float h, float z) {
110
+    glBegin(GL_TRIANGLE_STRIP);
111
+    for (int i = 0; i < 3; i++) {
51 112
         glTexCoord2f(vertices.at(i)->xPixel / 256.0f,
52 113
                 vertices.at(i)->yPixel / 256.0f);
53 114
 
@@ -65,7 +126,6 @@ void TextureTile::displayRectangle(float x, float y, float w, float h, float z)
65 126
             }
66 127
         }
67 128
     }
68
-
69 129
     glEnd();
70 130
 }
71 131
 

+ 7
- 4
src/UI.cpp View File

@@ -200,7 +200,7 @@ void UI::display() {
200 200
                         : TextureManager::TextureStorage::SYSTEM) - 1);
201 201
             ImGui::PopItemWidth();
202 202
             ImGui::SameLine();
203
-            if (ImGui::Button("+##texplus")) {
203
+            if (ImGui::Button("+##texplus", ImVec2(0, 0), true)) {
204 204
                 if (index < (getTextureManager().numTextures(
205 205
                                 game ? TextureManager::TextureStorage::GAME
206 206
                                 : TextureManager::TextureStorage::SYSTEM) - 1))
@@ -209,7 +209,7 @@ void UI::display() {
209 209
                     index = 0;
210 210
             }
211 211
             ImGui::SameLine();
212
-            if (ImGui::Button("-##texminus")) {
212
+            if (ImGui::Button("-##texminus", ImVec2(0, 0), true)) {
213 213
                 if (index > 0)
214 214
                     index--;
215 215
                 else
@@ -250,14 +250,14 @@ void UI::display() {
250 250
                 ImGui::SliderInt("##tileslide", &index, 0, getTextureManager().numTiles() - 1);
251 251
                 ImGui::PopItemWidth();
252 252
                 ImGui::SameLine();
253
-                if (ImGui::Button("+##tileplus")) {
253
+                if (ImGui::Button("+##tileplus", ImVec2(0, 0), true)) {
254 254
                     if (index < (getTextureManager().numTiles() - 1))
255 255
                         index++;
256 256
                     else
257 257
                         index = 0;
258 258
                 }
259 259
                 ImGui::SameLine();
260
-                if (ImGui::Button("-##tileminus")) {
260
+                if (ImGui::Button("-##tileminus", ImVec2(0, 0), true)) {
261 261
                     if (index > 0)
262 262
                         index--;
263 263
                     else
@@ -273,6 +273,9 @@ void UI::display() {
273 273
                     getRender().debugDisplayTextile();
274 274
                     visibleTile = false;
275 275
                 }
276
+                if (visibleTile && (index < getTextureManager().numTiles())) {
277
+                    ImGui::Text(getTextureManager().getTile(index).isTriangle() ? "Triangle" : "Rectangle");
278
+                }
276 279
                 if (visibleTile) {
277 280
                     getRender().debugDisplayTextile(index,
278 281
                             ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),

Loading…
Cancel
Save