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

textile triangle display

Thomas Buck преди 10 години
родител
ревизия
def2a75125
променени са 6 файла, в които са добавени 85 реда и са изтрити 20 реда
  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 Целия файл

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

+ 4
- 1
include/TextureManager.h Целия файл

30
     ~TextureTile();
30
     ~TextureTile();
31
 
31
 
32
     void add(TextureTileVertex* t);
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
     void displayRectangle(float x, float y, float w, float h, float z);
38
     void displayRectangle(float x, float y, float w, float h, float z);
35
 
39
 
36
-  private:
37
     uint16_t attribute;
40
     uint16_t attribute;
38
     uint16_t texture;
41
     uint16_t texture;
39
     std::vector<TextureTileVertex*> vertices;
42
     std::vector<TextureTileVertex*> vertices;

+ 7
- 9
src/Game.cpp Целия файл

73
     auto loader = Loader::createLoader(level);
73
     auto loader = Loader::createLoader(level);
74
     if (loader) {
74
     if (loader) {
75
         // First Loader test
75
         // First Loader test
76
+        getLog() << "Trying to load using new loader..." << Log::endl;
76
         error = loader->load(level);
77
         error = loader->load(level);
77
-        if (error == 0) {
78
-            getLog() << "Tried new Loader (0)..." << Log::endl;
79
-        } else {
78
+        if (error != 0) {
80
             getLog() << "Error while trying new loader (" << error << ")..." << Log::endl;
79
             getLog() << "Error while trying new loader (" << error << ")..." << Log::endl;
80
+            destroy();
81
         }
81
         }
82
     }
82
     }
83
 
83
 
84
     if ((!loader) || (error != 0)) {
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
         error = mTombRaider.Load(levelName.c_str());
86
         error = mTombRaider.Load(levelName.c_str());
91
         if (error != 0)
87
         if (error != 0)
92
             return error;
88
             return error;
99
             tmp += "MAIN.SFX";
95
             tmp += "MAIN.SFX";
100
             error = mTombRaider.loadSFX(tmp.c_str());
96
             error = mTombRaider.loadSFX(tmp.c_str());
101
             if (error != 0)
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
         // Process data
103
         // Process data

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

539
     if (mFlags & Render::fGL_Lights)
539
     if (mFlags & Render::fGL_Lights)
540
         glDisable(GL_LIGHTING);
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
     if (mFlags & Render::fGL_Lights)
544
     if (mFlags & Render::fGL_Lights)
545
         glEnable(GL_LIGHTING);
545
         glEnable(GL_LIGHTING);

+ 65
- 5
src/TextureManager.cpp Целия файл

40
     vertices.push_back(t);
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
     getTextureManager().bindTextureId(texture);
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
     for (int i = 0; i < 4; i++) {
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
         glTexCoord2f(vertices.at(i)->xPixel / 256.0f,
112
         glTexCoord2f(vertices.at(i)->xPixel / 256.0f,
52
                 vertices.at(i)->yPixel / 256.0f);
113
                 vertices.at(i)->yPixel / 256.0f);
53
 
114
 
65
             }
126
             }
66
         }
127
         }
67
     }
128
     }
68
-
69
     glEnd();
129
     glEnd();
70
 }
130
 }
71
 
131
 

+ 7
- 4
src/UI.cpp Целия файл

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

Loading…
Отказ
Запис