Bläddra i källkod

LoaderTR2 starts filling Rooms

Thomas Buck 10 år sedan
förälder
incheckning
c3c681e66f
14 ändrade filer med 192 tillägg och 48 borttagningar
  1. 3
    0
      ChangeLog.md
  2. 31
    13
      include/Mesh.h
  3. 9
    1
      include/Room.h
  4. 1
    0
      include/RoomData.h
  5. 6
    0
      include/Sprite.h
  6. 7
    0
      include/loader/Loader.h
  7. 2
    1
      src/Game.cpp
  8. 47
    2
      src/Mesh.cpp
  9. 39
    9
      src/Room.cpp
  10. 4
    0
      src/RoomData.cpp
  11. 4
    0
      src/Sprite.cpp
  12. 3
    1
      src/UI.cpp
  13. 20
    11
      src/loader/LoaderTR2.cpp
  14. 16
    10
      src/utils/pixel.cpp

+ 3
- 0
ChangeLog.md Visa fil

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20141124 ]
6
+    * LoaderTR2 is starting to populate Room structures
7
+
5
     [ 20141123 ]
8
     [ 20141123 ]
6
     * Added texture viewer debug UI
9
     * Added texture viewer debug UI
7
 
10
 

+ 31
- 13
include/Mesh.h Visa fil

10
 #ifndef _MESH_H_
10
 #ifndef _MESH_H_
11
 #define _MESH_H_
11
 #define _MESH_H_
12
 
12
 
13
+#include "loader/Loader.h"
14
+
13
 /*!
15
 /*!
14
  * \brief OpenGL Mesh
16
  * \brief OpenGL Mesh
15
  */
17
  */
16
 class Mesh {
18
 class Mesh {
17
   public:
19
   public:
18
 
20
 
21
+    struct rectangle_t {
22
+        struct vertex_t a, b, c, d;
23
+        uint16_t texture;
24
+    }
25
+
26
+    Mesh();
27
+    ~Mesh();
28
+
29
+    void drawAlpha();
30
+    void drawSolid();
31
+
32
+    // Warning: texture is not the GL texture id,
33
+    // it is an index into the object texture list!
34
+    void addTexturedRectangle(struct vertex_t a, struct vertex_t b,
35
+            struct vertex_t c, struct vertex_t d, uint16_t texture);
36
+    void addTexturedTriangle(struct vertex_t a, struct vertex_t b,
37
+            struct vertex_t c, uint16_t texture);
38
+
39
+    std::vector<struct rectangle_t> texturedRectangles;
40
+    std::vector<struct rectangle_t> coloredRectangles;
41
+    std::vector<struct rectangle_t> texturedTriangles;
42
+    std::vector<struct rectangle_t> coloredTriangles;
43
+
44
+
45
+
46
+    // Old API
47
+
19
     typedef enum {
48
     typedef enum {
20
         MeshModeSolid,
49
         MeshModeSolid,
21
         MeshModeWireframe,
50
         MeshModeWireframe,
77
 
106
 
78
     } rect_t;
107
     } rect_t;
79
 
108
 
80
-    /*!
81
-     * \brief Constructs an object of Mesh
82
-     */
83
-    Mesh();
84
-
85
-    /*!
86
-     * \brief Deconstructs an object of Mesh
87
-     */
88
-    ~Mesh();
89
-
90
-    void drawAlpha();
91
-
92
-    void drawSolid();
109
+    void drawAlphaOld();
110
+    void drawSolidOld();
93
 
111
 
94
     void allocateColors(unsigned int n);
112
     void allocateColors(unsigned int n);
95
 
113
 

+ 9
- 1
include/Room.h Visa fil

21
 class Room {
21
 class Room {
22
   public:
22
   public:
23
     Room(TombRaider& tr, unsigned int index);
23
     Room(TombRaider& tr, unsigned int index);
24
+
25
+    Room();
24
     ~Room();
26
     ~Room();
25
 
27
 
26
     BoundingBox& getBoundingBox();
28
     BoundingBox& getBoundingBox();
27
-    Mesh& getMesh();
28
     void display(bool alpha);
29
     void display(bool alpha);
29
 
30
 
30
     bool isWall(unsigned long sector);
31
     bool isWall(unsigned long sector);
43
 
44
 
44
     unsigned long sizeAdjacentRooms();
45
     unsigned long sizeAdjacentRooms();
45
     long getAdjacentRoom(unsigned long index);
46
     long getAdjacentRoom(unsigned long index);
47
+    void addAdjacentRoom(long r);
46
 
48
 
47
     unsigned long sizePortals();
49
     unsigned long sizePortals();
48
     Portal& getPortal(unsigned long index);
50
     Portal& getPortal(unsigned long index);
51
+    void addPortal(Portal* p);
49
 
52
 
50
     unsigned long sizeSectors();
53
     unsigned long sizeSectors();
51
     Sector& getSector(unsigned long index);
54
     Sector& getSector(unsigned long index);
55
+    void addSector(Sector* s);
52
 
56
 
53
     unsigned long sizeBox();
57
     unsigned long sizeBox();
54
     Box& getBox(unsigned long index);
58
     Box& getBox(unsigned long index);
59
+    void addBox(Box* b);
55
 
60
 
56
     unsigned long sizeModels();
61
     unsigned long sizeModels();
57
     StaticModel& getModel(unsigned long index);
62
     StaticModel& getModel(unsigned long index);
63
+    void addModel(StaticModel* s);
58
 
64
 
59
     unsigned long sizeLights();
65
     unsigned long sizeLights();
60
     Light& getLight(unsigned long index);
66
     Light& getLight(unsigned long index);
67
+    void addLight(Light* l);
61
 
68
 
62
     unsigned long sizeSprites();
69
     unsigned long sizeSprites();
63
     Sprite& getSprite(unsigned long index);
70
     Sprite& getSprite(unsigned long index);
71
+    void addSprite(Sprite* s);
64
 
72
 
65
   private:
73
   private:
66
     void sortModels();
74
     void sortModels();

+ 1
- 0
include/RoomData.h Visa fil

75
 
75
 
76
 class Portal {
76
 class Portal {
77
   public:
77
   public:
78
+    Portal(float vert[4][3], float norm[3], int adj);
78
     Portal(TombRaider& tr, unsigned int room, unsigned int index, Matrix& transform);
79
     Portal(TombRaider& tr, unsigned int room, unsigned int index, Matrix& transform);
79
 
80
 
80
     void getVertices(float vert[4][3]);
81
     void getVertices(float vert[4][3]);

+ 6
- 0
include/Sprite.h Visa fil

8
 #ifndef _SPRITE_H_
8
 #ifndef _SPRITE_H_
9
 #define _SPRITE_H_
9
 #define _SPRITE_H_
10
 
10
 
11
+#include <cstdint>
12
+
13
+#include "loader/Loader.h"
11
 #include "TombRaider.h"
14
 #include "TombRaider.h"
12
 
15
 
13
 class Sprite {
16
 class Sprite {
14
   public:
17
   public:
18
+    Sprite(struct vertex_t vert, uint16_t tex);
19
+
20
+    // Old API
15
     Sprite(TombRaider& tr, unsigned int room, unsigned int index);
21
     Sprite(TombRaider& tr, unsigned int room, unsigned int index);
16
     Sprite(TombRaider& tr, unsigned int item, unsigned int sequence, unsigned int index);
22
     Sprite(TombRaider& tr, unsigned int item, unsigned int sequence, unsigned int index);
17
     void display();
23
     void display();

+ 7
- 0
include/loader/Loader.h Visa fil

10
 
10
 
11
 #include <memory>
11
 #include <memory>
12
 #include <string>
12
 #include <string>
13
+#include <cstdint>
13
 
14
 
14
 #include "utils/binary.h"
15
 #include "utils/binary.h"
15
 
16
 
17
+struct vertex_t {
18
+    int16_t x, y, z;
19
+    int16_t light1, light2;
20
+    int16_t attributes;
21
+};
22
+
16
 class Loader {
23
 class Loader {
17
   public:
24
   public:
18
 
25
 

+ 2
- 1
src/Game.cpp Visa fil

120
         } else {
120
         } else {
121
             mLoaded = true;
121
             mLoaded = true;
122
             getRender().setMode(Render::modeVertexLight);
122
             getRender().setMode(Render::modeVertexLight);
123
-            return 0;
124
         }
123
         }
125
     }
124
     }
125
+
126
+    return 0;
126
 }
127
 }
127
 
128
 
128
 void Game::handleAction(ActionEvents action, bool isFinished) {
129
 void Game::handleAction(ActionEvents action, bool isFinished) {

+ 47
- 2
src/Mesh.cpp Visa fil

11
 #include "TextureManager.h"
11
 #include "TextureManager.h"
12
 #include "Mesh.h"
12
 #include "Mesh.h"
13
 
13
 
14
+void Mesh::addTexturedRectangle(struct vertex_t a, struct vertex_t b,
15
+        struct vertex_t c, struct vertex_t d, uint16_t texture) {
16
+    struct rectangle_t r;
17
+    r.a = a;
18
+    r.b = b;
19
+    r.c = c;
20
+    r.d = d;
21
+    r.texture = texture;
22
+    texturedRectangles.push_back(r);
23
+}
24
+
25
+void Mesh::addTexturedTriangle(struct vertex_t a, struct vertex_t b,
26
+        struct vertex_t c, uint16_t texture) {
27
+    struct rectangle_t r;
28
+    r.a = a;
29
+    r.b = b;
30
+    r.c = c;
31
+    r.texture = texture;
32
+    texturedTriangles.push_back(r);
33
+}
34
+
35
+void Mesh::drawAlpha() {
36
+    if ((texturedRectangles.size() == 0)
37
+            && (texturedTriangles.size() == 0)
38
+            && (coloredRectangles.size() == 0)
39
+            && (coloredTriangles.size() == 0)) {
40
+        drawAlphaOld();
41
+        return;
42
+    }
43
+
44
+    // TODO replicate drawAlphaOld, but get object texture coord from World
45
+}
46
+
47
+void Mesh::drawSolid() {
48
+    if ((texturedRectangles.size() == 0)
49
+            && (texturedTriangles.size() == 0)
50
+            && (coloredRectangles.size() == 0)
51
+            && (coloredTriangles.size() == 0)) {
52
+        drawSolidOld();
53
+        return;
54
+    }
55
+
56
+
57
+}
58
+
14
 
59
 
15
 ////////////////////////////////////////////////////////////
60
 ////////////////////////////////////////////////////////////
16
 // Constructors
61
 // Constructors
114
 // Public Accessors
159
 // Public Accessors
115
 ////////////////////////////////////////////////////////////
160
 ////////////////////////////////////////////////////////////
116
 
161
 
117
-void Mesh::drawAlpha() {
162
+void Mesh::drawAlphaOld() {
118
     unsigned int i, j, k, index;
163
     unsigned int i, j, k, index;
119
 
164
 
120
 
165
 
186
 }
231
 }
187
 
232
 
188
 
233
 
189
-void Mesh::drawSolid() {
234
+void Mesh::drawSolidOld() {
190
     unsigned int i, j, k, index;
235
     unsigned int i, j, k, index;
191
 
236
 
192
 
237
 

+ 39
- 9
src/Room.cpp Visa fil

391
 #endif
391
 #endif
392
 }
392
 }
393
 
393
 
394
+Room::Room() : flags(0), numXSectors(0), numZSectors(0) {
395
+    pos[0] = 0;
396
+    pos[1] = 0;
397
+    pos[2] = 0;
398
+}
399
+
394
 #define EMPTY_VECTOR(x)     \
400
 #define EMPTY_VECTOR(x)     \
395
 while (!x.empty()) {        \
401
 while (!x.empty()) {        \
396
     delete x[x.size() - 1]; \
402
     delete x[x.size() - 1]; \
443
 
449
 
444
     switch (getRender().getMode()) {
450
     switch (getRender().getMode()) {
445
         case Render::modeWireframe:
451
         case Render::modeWireframe:
446
-            getMesh().mMode = Mesh::MeshModeWireframe;
452
+            mesh.mMode = Mesh::MeshModeWireframe;
447
             break;
453
             break;
448
         case Render::modeSolid:
454
         case Render::modeSolid:
449
-            getMesh().mMode = Mesh::MeshModeSolid;
455
+            mesh.mMode = Mesh::MeshModeSolid;
450
             break;
456
             break;
451
         default:
457
         default:
452
-            getMesh().mMode = Mesh::MeshModeTexture;
458
+            mesh.mMode = Mesh::MeshModeTexture;
453
             break;
459
             break;
454
     }
460
     }
455
 
461
 
456
     if (alpha)
462
     if (alpha)
457
-        getMesh().drawAlpha();
463
+        mesh.drawAlpha();
458
     else
464
     else
459
-        getMesh().drawSolid();
465
+        mesh.drawSolid();
460
 
466
 
461
     glPopMatrix();
467
     glPopMatrix();
462
 
468
 
553
     return adjacentRooms.at(index);
559
     return adjacentRooms.at(index);
554
 }
560
 }
555
 
561
 
562
+void Room::addAdjacentRoom(long r) {
563
+    adjacentRooms.push_back(r);
564
+}
565
+
556
 unsigned long Room::sizePortals() {
566
 unsigned long Room::sizePortals() {
557
     return portals.size();
567
     return portals.size();
558
 }
568
 }
562
     return *portals.at(index);
572
     return *portals.at(index);
563
 }
573
 }
564
 
574
 
575
+void Room::addPortal(Portal* p) {
576
+    portals.push_back(p);
577
+}
578
+
565
 unsigned long Room::sizeSectors() {
579
 unsigned long Room::sizeSectors() {
566
     return sectors.size();
580
     return sectors.size();
567
 }
581
 }
571
     return *sectors.at(index);
585
     return *sectors.at(index);
572
 }
586
 }
573
 
587
 
588
+void Room::addSector(Sector* s) {
589
+    sectors.push_back(s);
590
+}
591
+
574
 unsigned long Room::sizeBox() {
592
 unsigned long Room::sizeBox() {
575
     return boxes.size();
593
     return boxes.size();
576
 }
594
 }
580
     return *boxes.at(index);
598
     return *boxes.at(index);
581
 }
599
 }
582
 
600
 
601
+void Room::addBox(Box* b) {
602
+    boxes.push_back(b);
603
+}
604
+
583
 unsigned long Room::sizeModels() {
605
 unsigned long Room::sizeModels() {
584
     return models.size();
606
     return models.size();
585
 }
607
 }
589
     return *models.at(index);
611
     return *models.at(index);
590
 }
612
 }
591
 
613
 
614
+void Room::addModel(StaticModel* s) {
615
+    models.push_back(s);
616
+}
617
+
592
 void Room::sortModels() {
618
 void Room::sortModels() {
593
     std::sort(models.begin(), models.end(), StaticModel::compare);
619
     std::sort(models.begin(), models.end(), StaticModel::compare);
594
 }
620
 }
602
     return *lights.at(index);
628
     return *lights.at(index);
603
 }
629
 }
604
 
630
 
631
+void Room::addLight(Light* l) {
632
+    lights.push_back(l);
633
+}
634
+
605
 unsigned long Room::sizeSprites() {
635
 unsigned long Room::sizeSprites() {
606
     return sprites.size();
636
     return sprites.size();
607
 }
637
 }
611
     return *sprites.at(index);
641
     return *sprites.at(index);
612
 }
642
 }
613
 
643
 
614
-BoundingBox& Room::getBoundingBox() {
615
-    return bbox;
644
+void Room::addSprite(Sprite* s) {
645
+    sprites.push_back(s);
616
 }
646
 }
617
 
647
 
618
-Mesh& Room::getMesh() {
619
-    return mesh;
648
+BoundingBox& Room::getBoundingBox() {
649
+    return bbox;
620
 }
650
 }
621
 
651
 

+ 4
- 0
src/RoomData.cpp Visa fil

218
     }
218
     }
219
 }
219
 }
220
 
220
 
221
+Portal::Portal(float vert[4][3], float norm[3], int adj) {
222
+
223
+}
224
+
221
 void Portal::getVertices(float vert[4][3]) {
225
 void Portal::getVertices(float vert[4][3]) {
222
     for (unsigned int i = 0; i < 4; i++) {
226
     for (unsigned int i = 0; i < 4; i++) {
223
         for (unsigned int j = 0; j < 3; j++) {
227
         for (unsigned int j = 0; j < 3; j++) {

+ 4
- 0
src/Sprite.cpp Visa fil

100
     radius = 0.0f;
100
     radius = 0.0f;
101
 }
101
 }
102
 
102
 
103
+Sprite::Sprite(struct vertex_t vert, uint16_t tex) {
104
+
105
+}
106
+
103
 void Sprite::display() {
107
 void Sprite::display() {
104
     if (!getRender().isVisible(pos[0], pos[1], pos[2], radius))
108
     if (!getRender().isVisible(pos[0], pos[1], pos[2], radius))
105
         return;
109
         return;

+ 3
- 1
src/UI.cpp Visa fil

200
             ImGui::PopItemWidth();
200
             ImGui::PopItemWidth();
201
             ImGui::SameLine();
201
             ImGui::SameLine();
202
             if (ImGui::Checkbox("Game", &game)) {
202
             if (ImGui::Checkbox("Game", &game)) {
203
-                if (game && !getGame().isLoaded())
203
+                if (game && (getTextureManager().numTextures(
204
+                        game ? TextureManager::TextureStorage::GAME
205
+                        : TextureManager::TextureStorage::SYSTEM) <= 0))
204
                     game = false;
206
                     game = false;
205
             }
207
             }
206
             ImGui::SameLine();
208
             ImGui::SameLine();

+ 20
- 11
src/loader/LoaderTR2.cpp Visa fil

11
 
11
 
12
 #include "global.h"
12
 #include "global.h"
13
 #include "Log.h"
13
 #include "Log.h"
14
+#include "Mesh.h"
14
 #include "TextureManager.h"
15
 #include "TextureManager.h"
15
 #include "utils/pixel.h"
16
 #include "utils/pixel.h"
16
 #include "loader/LoaderTR2.h"
17
 #include "loader/LoaderTR2.h"
55
     loadSoundDetails();
56
     loadSoundDetails();
56
     loadSampleIndices();
57
     loadSampleIndices();
57
 
58
 
58
-    return 42; // TODO Not finished with implementation!
59
+    return 0; // TODO Not finished with implementation!
59
 }
60
 }
60
 
61
 
61
 void LoaderTR2::loadPaletteTextiles() {
62
 void LoaderTR2::loadPaletteTextiles() {
101
         // Number of data words (2 bytes) to follow
102
         // Number of data words (2 bytes) to follow
102
         uint32_t dataToFollow = file.readU32();
103
         uint32_t dataToFollow = file.readU32();
103
 
104
 
105
+
106
+        std::vector<struct vertex> vertices;
107
+
104
         uint16_t numVertices = file.readU16();
108
         uint16_t numVertices = file.readU16();
105
         for (unsigned int v = 0; v < numVertices; v++) {
109
         for (unsigned int v = 0; v < numVertices; v++) {
110
+            struct vertex v;
106
             // Vertex coordinates, relative to x/zOffset
111
             // Vertex coordinates, relative to x/zOffset
107
-            int16_t relativeX = file.read16();
108
-            int16_t relativeY = file.read16();
109
-            int16_t relativeZ = file.read16();
112
+            v.x = file.read16();
113
+            v.y = file.read16();
114
+            v.z = file.read16();
110
 
115
 
111
-            int16_t lighting1 = file.read16();
116
+            v.light1 = file.read16();
112
 
117
 
113
             // Set of flags for special rendering effects
118
             // Set of flags for special rendering effects
114
             // 0x8000 - Something to do with water surface?
119
             // 0x8000 - Something to do with water surface?
115
             // 0x4000 - Underwater lighting modulation/movement if seen from above
120
             // 0x4000 - Underwater lighting modulation/movement if seen from above
116
             // 0x2000 - Water/Quicksand surface movement
121
             // 0x2000 - Water/Quicksand surface movement
117
             // 0x0010 - Normal?
122
             // 0x0010 - Normal?
118
-            uint16_t attributes = file.readU16();
123
+            v.attributes = file.readU16();
119
 
124
 
120
-            int16_t lighting2 = file.read16(); // Almost always equal to lighting1
125
+            v.light2 = file.read16(); // Almost always equal to light1
121
 
126
 
122
-            // TODO store vertex somewhere
127
+            vertices.push_back(v);
123
         }
128
         }
124
 
129
 
130
+        Room* room = new Room();
131
+
125
         uint16_t numRectangles = file.readU16();
132
         uint16_t numRectangles = file.readU16();
126
         for (unsigned int r = 0; r < numRectangles; r++) {
133
         for (unsigned int r = 0; r < numRectangles; r++) {
127
             // Indices into the vertex list read just before
134
             // Indices into the vertex list read just before
133
             // Index into the object-texture list
140
             // Index into the object-texture list
134
             uint16_t texture = file.readU16();
141
             uint16_t texture = file.readU16();
135
 
142
 
136
-            // TODO store rectangles somewhere
143
+            room->getMesh().addTexturedRectangle(vertices.at(vertex1), vertices.at(vertex2),
144
+                    vertices.at(vertex3), vertices.at(vertex4), texture);
137
         }
145
         }
138
 
146
 
139
         uint16_t numTriangles = file.readU16();
147
         uint16_t numTriangles = file.readU16();
146
             // Index into the object-texture list
154
             // Index into the object-texture list
147
             uint16_t texture = file.readU16();
155
             uint16_t texture = file.readU16();
148
 
156
 
149
-            // TODO store triangles somewhere
157
+            room->getMesh().addTexturedTriangle(vertices.at(vertex1), vertices.at(vertex2),
158
+                    vertices.at(vertex3), texture);
150
         }
159
         }
151
 
160
 
152
         uint16_t numSprites = file.readU16();
161
         uint16_t numSprites = file.readU16();
154
             uint16_t vertex = file.readU16(); // Index into vertex list
163
             uint16_t vertex = file.readU16(); // Index into vertex list
155
             uint16_t texture = file.readU16(); // Index into object-texture list
164
             uint16_t texture = file.readU16(); // Index into object-texture list
156
 
165
 
157
-            // TODO store sprites somewhere
166
+            room->addSprite(new Sprite(vertices.at(vertex), texture));
158
         }
167
         }
159
 
168
 
160
         uint16_t numPortals = file.readU16();
169
         uint16_t numPortals = file.readU16();

+ 16
- 10
src/utils/pixel.cpp Visa fil

32
     for (unsigned int i = 0; i < (w * h); ++i) {
32
     for (unsigned int i = 0; i < (w * h); ++i) {
33
         /* 24-bit BGR to RGB */
33
         /* 24-bit BGR to RGB */
34
         unsigned char swap = image[(i * 3) + 2];
34
         unsigned char swap = image[(i * 3) + 2];
35
-        image[(i * 3) + 2] = image[(i * 3)];
36
-        image[(i * 3)] = swap;
35
+        image[(i * 3) + 2] = image[i * 3];
36
+        image[i * 3] = swap;
37
     }
37
     }
38
 }
38
 }
39
 
39
 
46
         /* 32-bit BGRA to RGBA */
46
         /* 32-bit BGRA to RGBA */
47
         unsigned char swap = image[(i * 4) + 2];
47
         unsigned char swap = image[(i * 4) + 2];
48
         image[(i * 4) + 2] = image[(i * 4)];
48
         image[(i * 4) + 2] = image[(i * 4)];
49
-        image[(i * 4)] = swap;
49
+        image[i * 4] = swap;
50
     }
50
     }
51
 }
51
 }
52
 
52
 
56
     assert(h > 0);
56
     assert(h > 0);
57
 
57
 
58
     for (unsigned int i = 0; i < (w * h); ++i) {
58
     for (unsigned int i = 0; i < (w * h); ++i) {
59
-        /* 32-bit ARGB to RGBA */
60
-        unsigned char swap = image[(i * 4) + 3];
61
-        image[(i * 4)] = image[(i * 4) + 1];
59
+        // 32-bit ARGB to RGBA
60
+        unsigned char swap = image[i * 4];
61
+        image[i * 4] = image[(i * 4) + 1];
62
         image[(i * 4) + 1] = image[(i * 4) + 2];
62
         image[(i * 4) + 1] = image[(i * 4) + 2];
63
         image[(i * 4) + 2] = image[(i * 4) + 3];
63
         image[(i * 4) + 2] = image[(i * 4) + 3];
64
         image[(i * 4) + 3] = swap;
64
         image[(i * 4) + 3] = swap;
72
 
72
 
73
     unsigned char* img = new unsigned char[w * h * 4];
73
     unsigned char* img = new unsigned char[w * h * 4];
74
     for (unsigned int i = 0; i < (w * h); ++i) {
74
     for (unsigned int i = 0; i < (w * h); ++i) {
75
-        img[i * 4] = ((image[i] >> 10) & 0x1F) * 8;
76
-        img[(i * 4) + 1] = ((image[i] >> 5) & 0x1F) * 8;
77
-        img[(i * 4) + 2] = (image[i] & 0x1F) * 8;
78
-        img[(i * 4) + 3] = (image[i] & 0x8000) ? 0xFF : 0;
75
+        // arrr.rrgg gggb.bbbb shift to 5bit
76
+        img[i * 4] = (image[(i * 2) + 1] & 0x80) ? 0xFF : 0; // A
77
+        img[(i * 4) + 1] = (image[(i * 2) + 1] & 0x7C) >> 2; // R
78
+        img[(i * 4) + 2] = (image[(i * 2) + 1] & 0x03) << 3;
79
+        img[(i * 4) + 2] |= (image[i * 2] & 0xE0) >> 5; // G
80
+        img[(i * 4) + 3] = image[i * 2] & 0x1F; // B
81
+
82
+        img[(i * 4) + 1] <<= 3; // R
83
+        img[(i * 4) + 2] <<= 3; // G
84
+        img[(i * 4) + 3] <<= 3; // B
79
     }
85
     }
80
     return img;
86
     return img;
81
 }
87
 }

Laddar…
Avbryt
Spara