Sfoglia il codice sorgente

Mesh now RoomMesh, _fixed_ texture bleeding

Thomas Buck 10 anni fa
parent
commit
ff5b921c84
13 ha cambiato i file con 212 aggiunte e 277 eliminazioni
  1. 4
    0
      ChangeLog.md
  2. 1
    4
      TODO.md
  3. 24
    18
      include/Mesh.h
  4. 5
    5
      include/Room.h
  5. 55
    0
      include/RoomMesh.h
  6. 1
    2
      include/TextureManager.h
  7. 0
    28
      include/loader/LoaderTR2.h
  8. 1
    0
      src/CMakeLists.txt
  9. 1
    113
      src/Mesh.cpp
  10. 2
    70
      src/Room.cpp
  11. 96
    0
      src/RoomMesh.cpp
  12. 16
    31
      src/TextureManager.cpp
  13. 6
    6
      src/loader/LoaderTR2.cpp

+ 4
- 0
ChangeLog.md Vedi File

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141217 ]
6
+    * Introduced texel-offset in getUV() in an attempt to fix the texture-bleeding
7
+    * Mesh is now called RoomMesh
8
+
5 9
     [ 20141216 ]
6 10
     * Allow navigation with a free-floating Camera
7 11
     * Room Meshes are displayed more or less correctly

+ 1
- 4
TODO.md Vedi File

@@ -2,10 +2,6 @@
2 2
 
3 3
 ## General
4 4
 
5
-* Move to newer OpenGL (GL ES or 2.1 or 3.x or 4.x?)
6
-* Don't use C-Style code, try to replace with C++ lib
7
-* Mesh has 2 different approaches of storing the same data (eg. mColors and mColorArray), but half of ‘em isn’t implemented. Unify this, probably even combining Mesh and StaticMesh...
8
-* Don’t use float everywhere just because (eg. float colors)
9 5
 * Add verbose command line flag for debug output also in release builds
10 6
 * Don’t depend on setup: no data or config files should be necessary
11 7
 * Be able to change configuration from within OpenRaider
@@ -15,6 +11,7 @@
15 11
 * Screenshots are sometimes not written, sometimes distorted?
16 12
     * Seems to happen if OpenRaider.ini sets a resolution larger than the window can be
17 13
 * When the freeGLUT windowing interface is used, the first pressed button seems to be repeated
14
+    * Replace freeGLUT with glfw?
18 15
 
19 16
 ## Cmake
20 17
 

+ 24
- 18
include/Mesh.h Vedi File

@@ -2,37 +2,43 @@
2 2
  * \file include/Mesh.h
3 3
  * \brief OpenGL Mesh
4 4
  *
5
- * \author Mongoose
6
- *
7
- * \todo Unify the parallel systems here, arrays and the allocate/set
5
+ * \author xythobuz
8 6
  */
9 7
 
10 8
 #ifndef _MESH_H_
11 9
 #define _MESH_H_
12 10
 
13
-#include <vector>
14
-#include <glm/mat4x4.hpp>
11
+#include <map>
15 12
 #include <glm/vec2.hpp>
16 13
 #include <glm/vec3.hpp>
17 14
 
18
-#include "loader/LoaderTR2.h"
19
-
20 15
 class Mesh {
21
-  public:
22
-    Mesh(const std::vector<RoomVertexTR2>& vertices,
23
-         const std::vector<RoomRectangleTR2>& rectangles,
24
-         const std::vector<RoomTriangleTR2>& triangles);
25 16
 
26
-    void prepare();
17
+};
27 18
 
28
-    void display(glm::mat4 model, glm::mat4 view, glm::mat4 projection);
19
+// --------------------------------------
29 20
 
30
-  private:
31
-    std::vector<unsigned short> indices;
32
-    std::vector<glm::vec3> vertices;
33
-    std::vector<glm::vec2> uvs;
34
-    std::vector<unsigned int> textures;
21
+struct PackedVertex {
22
+    glm::vec3 pos;
23
+    glm::vec2 uv;
24
+    unsigned int tex;
25
+
26
+    PackedVertex(glm::vec3 p, glm::vec2 u, unsigned int t) : pos(p), uv(u), tex(t) { }
27
+    bool operator<(const PackedVertex& v) const { return memcmp(this, &v, sizeof(PackedVertex)) > 0; }
35 28
 };
36 29
 
30
+template <typename T>
31
+bool findSimilarVertex(T& v,
32
+                       std::map<T, unsigned short> m,
33
+                       unsigned short& s) {
34
+    auto it = m.find(v);
35
+    if (it == m.end())
36
+        return false;
37
+    else {
38
+        s = it->second;
39
+        return true;
40
+    }
41
+}
42
+
37 43
 #endif
38 44
 

+ 5
- 5
include/Room.h Vedi File

@@ -13,9 +13,9 @@
13 13
 #include <glm/mat4x4.hpp>
14 14
 #include <glm/vec3.hpp>
15 15
 
16
-#include "Mesh.h"
17 16
 #include "Sprite.h"
18 17
 #include "RoomData.h"
18
+#include "RoomMesh.h"
19 19
 
20 20
 enum RoomFlags {
21 21
     RoomFlagUnderWater = (1 << 0)
@@ -23,10 +23,10 @@ enum RoomFlags {
23 23
 
24 24
 class Room {
25 25
   public:
26
-    Room(glm::vec3 _pos, BoundingBox* _bbox, Mesh* _mesh, unsigned int f)
26
+    Room(glm::vec3 _pos, BoundingBox* _bbox, RoomMesh* _mesh, unsigned int f)
27 27
         : pos(_pos), bbox(_bbox), mesh(_mesh), flags(f) { }
28 28
 
29
-    void prepare();
29
+    void prepare() { mesh->prepare(); }
30 30
     void display(glm::mat4 view, glm::mat4 projection);
31 31
 
32 32
     bool isWall(unsigned long sector);
@@ -37,7 +37,7 @@ class Room {
37 37
                          float x2, float y2, float z2);
38 38
 
39 39
     BoundingBox& getBoundingBox() { return *bbox; }
40
-    Mesh& getMesh() { return *mesh; }
40
+    RoomMesh& getMesh() { return *mesh; }
41 41
 
42 42
     void setNumXSectors(unsigned int n) { numXSectors = n; }
43 43
     unsigned int getNumXSectors() { return numXSectors; }
@@ -74,7 +74,7 @@ class Room {
74 74
   private:
75 75
     glm::vec3 pos;
76 76
     std::unique_ptr<BoundingBox> bbox;
77
-    std::unique_ptr<Mesh> mesh;
77
+    std::unique_ptr<RoomMesh> mesh;
78 78
 
79 79
     unsigned int flags;
80 80
     unsigned int numXSectors;

+ 55
- 0
include/RoomMesh.h Vedi File

@@ -0,0 +1,55 @@
1
+/*!
2
+ * \file include/RoomMesh.h
3
+ * \brief World Room Mesh
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _ROOM_MESH_H_
9
+#define _ROOM_MESH_H_
10
+
11
+#include <cstdint>
12
+#include <vector>
13
+#include <glm/mat4x4.hpp>
14
+#include <glm/vec2.hpp>
15
+#include <glm/vec3.hpp>
16
+
17
+struct RoomVertexTR2 {
18
+    int16_t x, y, z; // Vertex coordinates, relative to x/zOffset
19
+    int16_t light1, light2; // Almost always equal
20
+
21
+    // Set of flags for special rendering effects
22
+    // 0x8000 - Something to do with water surface?
23
+    // 0x4000 - Underwater lighting modulation/movement if seen from above
24
+    // 0x2000 - Water/Quicksand surface movement
25
+    // 0x0010 - Normal?
26
+    uint16_t attributes;
27
+};
28
+
29
+struct IndexedRectangle {
30
+    unsigned int v1, v2, v3, v4; // Vertex list indices
31
+    unsigned int texture; // Index into object-texture list
32
+
33
+    IndexedRectangle(uint16_t t, uint16_t _v1, uint16_t _v2, uint16_t _v3, uint16_t _v4 = 0)
34
+        : v1(_v1), v2(_v2), v3(_v3), v4(_v4), texture(t) { }
35
+};
36
+
37
+class RoomMesh {
38
+  public:
39
+    RoomMesh(const std::vector<RoomVertexTR2>& vertices,
40
+         const std::vector<IndexedRectangle>& rectangles,
41
+         const std::vector<IndexedRectangle>& triangles);
42
+
43
+    void prepare();
44
+
45
+    void display(glm::mat4 model, glm::mat4 view, glm::mat4 projection);
46
+
47
+  private:
48
+    std::vector<unsigned short> indices;
49
+    std::vector<glm::vec3> vertices;
50
+    std::vector<glm::vec2> uvs;
51
+    std::vector<unsigned int> textures;
52
+};
53
+
54
+#endif
55
+

+ 1
- 2
include/TextureManager.h Vedi File

@@ -32,8 +32,7 @@ class TextureTile {
32 32
     void add(TextureTileVertex t) { vertices.push_back(t); }
33 33
 
34 34
     unsigned int getTexture() { return texture; }
35
-    glm::vec2 getUV(unsigned int i) { return glm::vec2(vertices.at(i).xPixel / 255.0f,
36
-                                                       vertices.at(i).yPixel / 255.0f); }
35
+    glm::vec2 getUV(unsigned int i);
37 36
 
38 37
   private:
39 38
     unsigned int attribute;

+ 0
- 28
include/loader/LoaderTR2.h Vedi File

@@ -45,33 +45,5 @@ class LoaderTR2 : public Loader {
45 45
     std::array<uint32_t, 256> palette;
46 46
 };
47 47
 
48
-struct RoomVertexTR2 {
49
-    int16_t x, y, z; // Vertex coordinates, relative to x/zOffset
50
-    int16_t light1, light2; // Almost always equal
51
-
52
-    // Set of flags for special rendering effects
53
-    // 0x8000 - Something to do with water surface?
54
-    // 0x4000 - Underwater lighting modulation/movement if seen from above
55
-    // 0x2000 - Water/Quicksand surface movement
56
-    // 0x0010 - Normal?
57
-    uint16_t attributes;
58
-};
59
-
60
-struct RoomRectangleTR2 {
61
-    uint16_t v1, v2, v3, v4; // Vertex list indices
62
-    uint16_t texture; // Index into object-texture list
63
-
64
-    RoomRectangleTR2(uint16_t _v1, uint16_t _v2, uint16_t _v3, uint16_t _v4, uint16_t t)
65
-        : v1(_v1), v2(_v2), v3(_v3), v4(_v4), texture(t) { }
66
-};
67
-
68
-struct RoomTriangleTR2 {
69
-    uint16_t v1, v2, v3; // Vertex list indices
70
-    uint16_t texture; // Index into object-texture list
71
-
72
-    RoomTriangleTR2(uint16_t _v1, uint16_t _v2, uint16_t _v3, uint16_t t)
73
-        : v1(_v1), v2(_v2), v3(_v3), texture(t) { }
74
-};
75
-
76 48
 #endif
77 49
 

+ 1
- 0
src/CMakeLists.txt Vedi File

@@ -77,6 +77,7 @@ set (SRCS ${SRCS} "Mesh.cpp" "../include/Mesh.h")
77 77
 set (SRCS ${SRCS} "Render.cpp" "../include/Render.h")
78 78
 set (SRCS ${SRCS} "Room.cpp" "../include/Room.h")
79 79
 set (SRCS ${SRCS} "RoomData.cpp" "../include/RoomData.h")
80
+set (SRCS ${SRCS} "RoomMesh.cpp" "../include/RoomMesh.h")
80 81
 set (SRCS ${SRCS} "RunTime.cpp" "../include/RunTime.h")
81 82
 set (SRCS ${SRCS} "Script.cpp" "../include/Script.h")
82 83
 set (SRCS ${SRCS} "SkeletalModel.cpp" "../include/SkeletalModel.h")

+ 1
- 113
src/Mesh.cpp Vedi File

@@ -2,118 +2,6 @@
2 2
  * \file src/Mesh.cpp
3 3
  * \brief OpenGL Mesh
4 4
  *
5
- * \author Mongoose
5
+ * \author xythobuz
6 6
  */
7 7
 
8
-#include <map>
9
-#include <stdlib.h>
10
-
11
-#include "global.h"
12
-#include "TextureManager.h"
13
-#include "system/Window.h"
14
-#include "Mesh.h"
15
-
16
-Mesh::Mesh(const std::vector<RoomVertexTR2>& vert,
17
-     const std::vector<RoomRectangleTR2>& rect,
18
-     const std::vector<RoomTriangleTR2>& tri) {
19
-    for (auto& t : rect) {
20
-        indices.push_back(0);
21
-        vertices.push_back(glm::vec3(vert.at(t.v1).x, vert.at(t.v1).y, vert.at(t.v1).z));
22
-        vertices.push_back(glm::vec3(vert.at(t.v2).x, vert.at(t.v2).y, vert.at(t.v2).z));
23
-        vertices.push_back(glm::vec3(vert.at(t.v3).x, vert.at(t.v3).y, vert.at(t.v3).z));
24
-        vertices.push_back(glm::vec3(vert.at(t.v4).x, vert.at(t.v4).y, vert.at(t.v4).z));
25
-        textures.push_back(t.texture);
26
-    }
27
-
28
-    for (auto& t : tri) {
29
-        indices.push_back(1);
30
-        vertices.push_back(glm::vec3(vert.at(t.v1).x, vert.at(t.v1).y, vert.at(t.v1).z));
31
-        vertices.push_back(glm::vec3(vert.at(t.v2).x, vert.at(t.v2).y, vert.at(t.v2).z));
32
-        vertices.push_back(glm::vec3(vert.at(t.v3).x, vert.at(t.v3).y, vert.at(t.v3).z));
33
-        textures.push_back(t.texture);
34
-    }
35
-}
36
-
37
-struct PackedVertex {
38
-    glm::vec3 pos;
39
-    glm::vec2 uv;
40
-    unsigned int tex;
41
-
42
-    PackedVertex(glm::vec3 p, glm::vec2 u, unsigned int t) : pos(p), uv(u), tex(t) { }
43
-    bool operator<(const PackedVertex& v) const { return memcmp(this, &v, sizeof(PackedVertex)) > 0; }
44
-};
45
-
46
-static bool findSimilarVertex(PackedVertex& v,
47
-                              std::map<PackedVertex, unsigned short> m,
48
-                              unsigned short& s) {
49
-    auto it = m.find(v);
50
-    if (it == m.end())
51
-        return false;
52
-    else {
53
-        s = it->second;
54
-        return true;
55
-    }
56
-}
57
-
58
-void Mesh::prepare() {
59
-    std::vector<unsigned short> ind;
60
-    std::vector<glm::vec3> vert;
61
-    std::vector<unsigned int> tex;
62
-
63
-    std::map<PackedVertex, unsigned short> vertexMap;
64
-
65
-    int vertIndex = 0;
66
-    for (int i = 0; i < indices.size(); i++) {
67
-        unsigned int texture = getTextureManager().getTile(textures.at(i)).getTexture();
68
-        for (int v = 0; v < ((indices.at(i) == 0) ? 4 : 3); v++) {
69
-            glm::vec2 uv = getTextureManager().getTile(textures.at(i)).getUV(v);
70
-            PackedVertex p(vertices.at(vertIndex + v), uv, texture);
71
-            unsigned short s;
72
-            if (findSimilarVertex(p, vertexMap, s)) {
73
-                ind.push_back(s); // Vertex already cached
74
-            } else {
75
-                vertexMap[p] = vert.size();
76
-                ind.push_back(vert.size());
77
-                vert.push_back(p.pos);
78
-                uvs.push_back(p.uv);
79
-                tex.push_back(p.tex);
80
-            }
81
-        }
82
-
83
-        if (indices.at(i) == 0) {
84
-            ind.push_back(ind.at(ind.size() - 2));
85
-            ind.push_back(ind.at(ind.size() - 5));
86
-        }
87
-
88
-        vertIndex += (indices.at(i) == 0) ? 4 : 3;
89
-    }
90
-
91
-    indices = ind;
92
-    vertices = vert;
93
-    textures = tex;
94
-
95
-    assert((indices.size() % 3) == 0);
96
-}
97
-
98
-void Mesh::display(glm::mat4 model, glm::mat4 view, glm::mat4 projection) {
99
-    glm::mat4 MVP = projection * view * model;
100
-
101
-    unsigned int indexStart = 0;
102
-    unsigned int indexPos = 1;
103
-    unsigned int texture = textures.at(indices.at(0));
104
-
105
-    while ((indexStart != indexPos) && (indexPos < indices.size())) {
106
-        while ((indexPos < indices.size()) && (textures.at(indices.at(indexPos)) == texture))
107
-            indexPos++;
108
-
109
-        std::vector<unsigned short> ind(indices.begin() + indexStart, indices.begin() + indexPos);
110
-        Window::drawGL(vertices, uvs, ind, MVP, texture);
111
-
112
-        if (indexPos < indices.size()) {
113
-            indexStart = indexPos;
114
-            indexPos += 1;
115
-            texture = textures.at(indices.at(indexStart));
116
-        }
117
-    }
118
-}
119
-

+ 2
- 70
src/Room.cpp Vedi File

@@ -21,76 +21,6 @@ void Room::display(glm::mat4 view, glm::mat4 projection) {
21 21
     mesh->display(model, view, projection);
22 22
 }
23 23
 
24
-void Room::prepare() {
25
-    mesh->prepare();
26
-}
27
-
28
-/*
29
-void Room::display(bool alpha) {
30
-    glPushMatrix();
31
-    //LightingSetup();
32
-
33
-    getTextureManager().bindTextureId(TEXTURE_WHITE, TextureManager::TextureStorage::SYSTEM);
34
-
35
-    if ((!alpha) && Render::getMode() == RenderMode::Wireframe) {
36
-        glLineWidth(2.0);
37
-        glColor3ubv(RED);
38
-
39
-        for (unsigned int i = 0; i < sizePortals(); i++) {
40
-            Portal& portal = getPortal(i);
41
-            float vertices[4][3];
42
-            portal.getVertices(vertices);
43
-
44
-            glBegin(GL_LINE_LOOP);
45
-            glVertex3fv(vertices[0]);
46
-            glVertex3fv(vertices[1]);
47
-            glVertex3fv(vertices[2]);
48
-            glVertex3fv(vertices[3]);
49
-            glEnd();
50
-        }
51
-
52
-        glLineWidth(1.0);
53
-
54
-        bbox.display(true, RED, GREEN);
55
-    }
56
-
57
-    glTranslated(pos[0], pos[1], pos[2]);
58
-
59
-    // Reset since GL_MODULATE used, reset to WHITE
60
-    glColor3ubv(WHITE);
61
-
62
-    switch (Render::getMode()) {
63
-        case RenderMode::Wireframe:
64
-            mesh.mMode = Mesh::MeshModeWireframe;
65
-            break;
66
-        case RenderMode::Solid:
67
-            mesh.mMode = Mesh::MeshModeSolid;
68
-            break;
69
-        default:
70
-            mesh.mMode = Mesh::MeshModeTexture;
71
-            break;
72
-    }
73
-
74
-    if (alpha)
75
-        mesh.drawAlpha();
76
-    else
77
-        mesh.drawSolid();
78
-
79
-    glPopMatrix();
80
-
81
-    // Draw other room meshes and sprites
82
-    if (alpha || (Render::getMode() == RenderMode::Wireframe)
83
-        || (Render::getMode() == RenderMode::Solid)) {
84
-        //sortModels(); // TODO
85
-        for (unsigned int i = 0; i < sizeModels(); i++)
86
-            getModel(i).display();
87
-
88
-        for (unsigned int i = 0; i < sizeSprites(); i++)
89
-            getSprite(i).display();
90
-    }
91
-}
92
-*/
93
-
94 24
 bool Room::isWall(unsigned long sector) {
95 25
     assert(sector < sectors.size());
96 26
 
@@ -151,6 +81,8 @@ int Room::getAdjoiningRoom(float x, float y, float z,
151 81
     return -1;
152 82
 }
153 83
 
84
+// --------------------------------------
85
+
154 86
 unsigned long Room::sizeAdjacentRooms() {
155 87
     return adjacentRooms.size();
156 88
 }

+ 96
- 0
src/RoomMesh.cpp Vedi File

@@ -0,0 +1,96 @@
1
+/*!
2
+ * \file src/RoomMesh.cpp
3
+ * \brief World Room Mesh
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "Mesh.h"
10
+#include "TextureManager.h"
11
+#include "system/Window.h"
12
+#include "RoomMesh.h"
13
+
14
+RoomMesh::RoomMesh(const std::vector<RoomVertexTR2>& vert,
15
+     const std::vector<IndexedRectangle>& rect,
16
+     const std::vector<IndexedRectangle>& tri) {
17
+    for (auto& t : rect) {
18
+        indices.push_back(0);
19
+        vertices.push_back(glm::vec3(vert.at(t.v1).x, vert.at(t.v1).y, vert.at(t.v1).z));
20
+        vertices.push_back(glm::vec3(vert.at(t.v2).x, vert.at(t.v2).y, vert.at(t.v2).z));
21
+        vertices.push_back(glm::vec3(vert.at(t.v3).x, vert.at(t.v3).y, vert.at(t.v3).z));
22
+        vertices.push_back(glm::vec3(vert.at(t.v4).x, vert.at(t.v4).y, vert.at(t.v4).z));
23
+        textures.push_back(t.texture);
24
+    }
25
+
26
+    for (auto& t : tri) {
27
+        indices.push_back(1);
28
+        vertices.push_back(glm::vec3(vert.at(t.v1).x, vert.at(t.v1).y, vert.at(t.v1).z));
29
+        vertices.push_back(glm::vec3(vert.at(t.v2).x, vert.at(t.v2).y, vert.at(t.v2).z));
30
+        vertices.push_back(glm::vec3(vert.at(t.v3).x, vert.at(t.v3).y, vert.at(t.v3).z));
31
+        textures.push_back(t.texture);
32
+    }
33
+}
34
+
35
+void RoomMesh::prepare() {
36
+    std::vector<unsigned short> ind;
37
+    std::vector<glm::vec3> vert;
38
+    std::vector<unsigned int> tex;
39
+
40
+    std::map<PackedVertex, unsigned short> vertexMap;
41
+
42
+    int vertIndex = 0;
43
+    for (int i = 0; i < indices.size(); i++) {
44
+        unsigned int texture = getTextureManager().getTile(textures.at(i)).getTexture();
45
+        for (int v = 0; v < ((indices.at(i) == 0) ? 4 : 3); v++) {
46
+            glm::vec2 uv = getTextureManager().getTile(textures.at(i)).getUV(v);
47
+            PackedVertex p(vertices.at(vertIndex + v), uv, texture);
48
+            unsigned short s;
49
+            if (findSimilarVertex(p, vertexMap, s)) {
50
+                ind.push_back(s); // Vertex already cached
51
+            } else {
52
+                vertexMap[p] = vert.size();
53
+                ind.push_back(vert.size());
54
+                vert.push_back(p.pos);
55
+                uvs.push_back(p.uv);
56
+                tex.push_back(p.tex);
57
+            }
58
+        }
59
+
60
+        if (indices.at(i) == 0) {
61
+            ind.push_back(ind.at(ind.size() - 2));
62
+            ind.push_back(ind.at(ind.size() - 5));
63
+        }
64
+
65
+        vertIndex += (indices.at(i) == 0) ? 4 : 3;
66
+    }
67
+
68
+    assert((ind.size() % 3) == 0);
69
+
70
+    indices = ind;
71
+    vertices = vert;
72
+    textures = tex;
73
+}
74
+
75
+void RoomMesh::display(glm::mat4 model, glm::mat4 view, glm::mat4 projection) {
76
+    glm::mat4 MVP = projection * view * model;
77
+
78
+    unsigned int indexStart = 0;
79
+    unsigned int indexPos = 1;
80
+    unsigned int texture = textures.at(indices.at(0));
81
+
82
+    while ((indexStart != indexPos) && (indexPos < indices.size())) {
83
+        while ((indexPos < indices.size()) && (textures.at(indices.at(indexPos)) == texture))
84
+            indexPos++;
85
+
86
+        std::vector<unsigned short> ind(indices.begin() + indexStart, indices.begin() + indexPos);
87
+        Window::drawGL(vertices, uvs, ind, MVP, texture);
88
+
89
+        if (indexPos < indices.size()) {
90
+            indexStart = indexPos;
91
+            indexPos += 1;
92
+            texture = textures.at(indices.at(indexStart));
93
+        }
94
+    }
95
+}
96
+

+ 16
- 31
src/TextureManager.cpp Vedi File

@@ -24,42 +24,27 @@
24 24
 #include "utils/png.h"
25 25
 #endif
26 26
 
27
-/*
28
-void TextureTile::displayRectangle(float a[3], float b[3], float c[3], float d[3]) {
29
-    //! \fixme TR Rosetta Stone says this, but looks strange?
30
-    if (attribute == 0) {
31
-        // Ignore transparency
32
-        glDisable(GL_BLEND);
27
+glm::vec2 TextureTile::getUV(unsigned int i) {
28
+    glm::vec2 uv(vertices.at(i).xPixel,
29
+                 vertices.at(i).yPixel);
30
+
31
+    /*! \fixme
32
+     * This is my somewhat hacky approach to fixing
33
+     * the bad texture-bleeding problems everywhere.
34
+     * That's better, but makes the seams between
35
+     * each sector much more visible!
36
+     */
37
+
38
+    if (vertices.at(i).xCoordinate == 1) {
39
+        uv.x += 0.375f;
33 40
     }
34 41
 
35
-    float xmin = 256.0f, xmax = 0.0f;
36
-    float ymin = 256.0f, ymax = 0.0f;
37
-    for (int i = 0; i < 4; i++) {
38
-        if (vertices.at(i)->xCoordinate == 255) {
39
-            xmax = vertices.at(i)->xPixel;
40
-        } else {
41
-            xmin = vertices.at(i)->xPixel;
42
-        }
43
-
44
-        if (vertices.at(i)->yCoordinate == 255) {
45
-            ymax = vertices.at(i)->yPixel;
46
-        } else {
47
-            ymin = vertices.at(i)->yPixel;
48
-        }
42
+    if (vertices.at(i).yCoordinate == 1) {
43
+        uv.y += 0.375f;
49 44
     }
50 45
 
51
-    glBegin(GL_QUADS);
52
-    glTexCoord2f(xmin / 256.0f, ymin / 256.0f);
53
-    glVertex3f(a.x, a.y, a.z);
54
-    glTexCoord2f(xmax / 256.0f, ymin / 256.0f);
55
-    glVertex3f(b.x, b.y, b.z);
56
-    glTexCoord2f(xmax / 256.0f, ymax / 256.0f);
57
-    glVertex3f(c.x, c.y, c.z);
58
-    glTexCoord2f(xmin / 256.0f, ymax / 256.0f);
59
-    glVertex3f(d.x, d.y, d.z);
60
-    glEnd();
46
+    return uv / 256.0f;
61 47
 }
62
-*/
63 48
 
64 49
 // ----------------------------------------------------------------------------
65 50
 

+ 6
- 6
src/loader/LoaderTR2.cpp Vedi File

@@ -12,7 +12,6 @@
12 12
 #include "global.h"
13 13
 #include "Game.h"
14 14
 #include "Log.h"
15
-#include "Mesh.h"
16 15
 #include "Room.h"
17 16
 #include "SoundManager.h"
18 17
 #include "TextureManager.h"
@@ -236,7 +235,7 @@ void LoaderTR2::loadRooms() {
236 235
         bbox[1] += pos;
237 236
 
238 237
         uint16_t numRectangles = file.readU16();
239
-        std::vector<RoomRectangleTR2> rectangles;
238
+        std::vector<IndexedRectangle> rectangles;
240 239
         for (unsigned int r = 0; r < numRectangles; r++) {
241 240
             // Indices into the vertex list read just before
242 241
             uint16_t vertex1 = file.readU16();
@@ -247,11 +246,11 @@ void LoaderTR2::loadRooms() {
247 246
             // Index into the object-texture list
248 247
             uint16_t texture = file.readU16();
249 248
 
250
-            rectangles.emplace_back(vertex1, vertex2, vertex3, vertex4, texture);
249
+            rectangles.emplace_back(texture, vertex1, vertex2, vertex3, vertex4);
251 250
         }
252 251
 
253 252
         uint16_t numTriangles = file.readU16();
254
-        std::vector<RoomTriangleTR2> triangles;
253
+        std::vector<IndexedRectangle> triangles;
255 254
         for (unsigned int t = 0; t < numTriangles; t++) {
256 255
             // Indices into the room vertex list
257 256
             uint16_t vertex1 = file.readU16();
@@ -261,7 +260,7 @@ void LoaderTR2::loadRooms() {
261 260
             // Index into the object-texture list
262 261
             uint16_t texture = file.readU16();
263 262
 
264
-            triangles.emplace_back(vertex1, vertex2, vertex3, texture);
263
+            triangles.emplace_back(texture, vertex1, vertex2, vertex3);
265 264
         }
266 265
 
267 266
         uint16_t numSprites = file.readU16();
@@ -331,6 +330,7 @@ void LoaderTR2::loadRooms() {
331 330
             }
332 331
 
333 332
             //room->addSector(new Sector(floor * 256.0f, ceiling * 256.0f, wall));
333
+            // TODO store sectors
334 334
         }
335 335
 
336 336
         int16_t intensity1 = file.read16();
@@ -383,7 +383,7 @@ void LoaderTR2::loadRooms() {
383 383
         }
384 384
 
385 385
         BoundingBox* boundingbox = new BoundingBox(bbox[0], bbox[1]);
386
-        Mesh* mesh = new Mesh(vertices, rectangles, triangles);
386
+        RoomMesh* mesh = new RoomMesh(vertices, rectangles, triangles);
387 387
         Room* room = new Room(pos, boundingbox, mesh, roomFlags);
388 388
 
389 389
         getWorld().addRoom(room);

Loading…
Annulla
Salva