Thomas Buck пре 10 година
родитељ
комит
a74c620a72
16 измењених фајлова са 175 додато и 151 уклоњено
  1. 7
    0
      ChangeLog.md
  2. 1
    1
      include/Entity.h
  3. 5
    17
      include/TextureManager.h
  4. 42
    32
      include/global.h
  5. 2
    3
      include/utils/pcx.h
  6. 4
    4
      include/utils/png.h
  7. 1
    1
      src/Camera.cpp
  8. 20
    30
      src/Command.cpp
  9. 4
    3
      src/Entity.cpp
  10. 4
    3
      src/FontSDL.cpp
  11. 4
    3
      src/Game.cpp
  12. 2
    1
      src/StaticMesh.cpp
  13. 61
    33
      src/TextureManager.cpp
  14. 3
    8
      src/WindowSDL.cpp
  15. 3
    2
      src/utils/pcx.cpp
  16. 12
    10
      src/utils/png.cpp

+ 7
- 0
ChangeLog.md Прегледај датотеку

@@ -2,6 +2,13 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140626 ]
6
+    * ColorMode enum now global
7
+    * Entities setAngles now sets all three angles
8
+    * Added loadPNG to TextureManager
9
+    * Added loadImage to TextureManager, _detecting_ the file type
10
+    * Re-Implemented the move command
11
+
5 12
     [ 20140624 ]
6 13
     * Some changes to allow compilation with Ubuntu 14.04 / gcc
7 14
     * Modified utils/png to allow compilation with different integer sizes

+ 1
- 1
include/Entity.h Прегледај датотеку

@@ -34,7 +34,7 @@ public:
34 34
     MoveType getMoveType();
35 35
     void setMoveType(MoveType m);
36 36
     int getObjectId();
37
-    void setAngle(vec_t yaw);
37
+    void setAngles(vec3_t a);
38 38
     vec_t getPos(unsigned int i);
39 39
     vec_t getAngle(unsigned int i);
40 40
     int getRoom();

+ 5
- 17
include/TextureManager.h Прегледај датотеку

@@ -17,15 +17,6 @@
17 17
 class TextureManager {
18 18
 public:
19 19
 
20
-    enum ColorMode {
21
-        GREYSCALE,
22
-        RGB,
23
-        RGBA,
24
-        ARGB,
25
-        BGR,
26
-        BGRA
27
-    };
28
-
29 20
     enum TextureFlag {
30 21
         fUseMultiTexture = (1 << 0),
31 22
     };
@@ -89,14 +80,7 @@ public:
89 80
                         ColorMode mode, unsigned int bpp,
90 81
                         unsigned int slot);
91 82
 
92
-    /*!
93
-     * \brief Loads TGA file as texture
94
-     * \param filename Existing TGA file
95
-     * \returns ID of new texture or -1 on error
96
-     */
97
-    int loadTGA(const char *filename);
98
-
99
-    int loadPCX(const char *filename);
83
+    int loadImage(const char *filename);
100 84
 
101 85
     /*!
102 86
      * \brief Sets an option flag
@@ -107,6 +91,10 @@ public:
107 91
     void useMultiTexture(float aU, float aV, float bU, float bV);
108 92
 
109 93
 private:
94
+    int loadTGA(const char *filename);
95
+    int loadPCX(const char *filename);
96
+    int loadPNG(const char *filename);
97
+
110 98
     std::vector<unsigned int> mTextureIds;
111 99
     unsigned int mFlags;
112 100
 };

+ 42
- 32
include/global.h Прегледај датотеку

@@ -15,38 +15,15 @@
15 15
 #define DEFAULT_WIDTH 640
16 16
 #define DEFAULT_HEIGHT 480
17 17
 
18
-// Visual C++ does not understand __attribute__
19
-#ifdef _MSC_VER
20
-#define __attribute__(x)
21
-#endif
22
-
23
-//! \todo Replace NULL usage with nullptr
24
-#ifndef NULL
25
-#define NULL nullptr
26
-#endif
27
-
28
-// Globally include OpenGL header
29
-#ifdef __APPLE__
30
-#include <OpenGL/gl.h>
31
-#else
32
-#ifdef HAVE_WINDOWS_H
33
-#include <windows.h>
34
-#endif
35
-#include <GL/gl.h>
36
-#endif
37
-
38
-// If available, use our own assert that prints the call stack
39
-#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
40
-#ifndef NDEBUG
41
-[[noreturn]] void assertImplementation(const char *exp, const char *file, int line);
42
-#define assert(x) (void)((x) || (assertImplementation(#x, __FILE__, __LINE__),0))
43
-#else
44
-#define assert(x)
45
-#endif
46
-#else
47
-// Fall back to the default C assert
48
-#include <cassert>
49
-#endif
18
+// Supported pixelmap color formats
19
+enum ColorMode {
20
+    GREYSCALE,
21
+    RGB,
22
+    RGBA,
23
+    ARGB,
24
+    BGR,
25
+    BGRA
26
+};
50 27
 
51 28
 // Colors used where ever needed
52 29
 const unsigned char BLACK[]  = {   0,   0,   0, 255 };
@@ -107,5 +84,38 @@ ActionEvents stringToActionEvent(const char *action);
107 84
 
108 85
 KeyboardButton stringToKeyboardButton(const char *key);
109 86
 
87
+// Visual C++ does not understand __attribute__
88
+#ifdef _MSC_VER
89
+#define __attribute__(x)
90
+#endif
91
+
92
+//! \todo Replace NULL usage with nullptr
93
+#ifndef NULL
94
+#define NULL nullptr
95
+#endif
96
+
97
+// Globally include OpenGL header
98
+#ifdef __APPLE__
99
+#include <OpenGL/gl.h>
100
+#else
101
+#ifdef HAVE_WINDOWS_H
102
+#include <windows.h>
103
+#endif
104
+#include <GL/gl.h>
105
+#endif
106
+
107
+// If available, use our own assert that prints the call stack
108
+#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS)
109
+#ifndef NDEBUG
110
+[[noreturn]] void assertImplementation(const char *exp, const char *file, int line);
111
+#define assert(x) (void)((x) || (assertImplementation(#x, __FILE__, __LINE__),0))
112
+#else
113
+#define assert(x)
114
+#endif
115
+#else
116
+// Fall back to the default C assert
117
+#include <cassert>
118
+#endif
119
+
110 120
 #endif
111 121
 

+ 2
- 3
include/utils/pcx.h Прегледај датотеку

@@ -11,8 +11,6 @@
11 11
 #ifndef _UTILS_PCX_H_
12 12
 #define _UTILS_PCX_H_
13 13
 
14
-#include "TextureManager.h"
15
-
16 14
 /*!
17 15
  * \brief Check if a file is a valid PCX image
18 16
  * \param filename path of file to read
@@ -30,7 +28,8 @@ int pcxCheck(const char *filename);
30 28
  * \param bpp place where pixel width will be stored (8, 24, 32)
31 29
  * \returns 0 on success
32 30
  */
33
-int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, unsigned int *height, TextureManager::ColorMode *mode, unsigned int *bpp);
31
+int pcxLoad(const char *filename, unsigned char **image,
32
+        unsigned int *width, unsigned int *height, ColorMode *mode, unsigned int *bpp);
34 33
 
35 34
 #endif
36 35
 

+ 4
- 4
include/utils/png.h Прегледај датотеку

@@ -8,8 +8,6 @@
8 8
 #ifndef _UTILS_PNG_H_
9 9
 #define _UTILS_PNG_H_
10 10
 
11
-#include "TextureManager.h"
12
-
13 11
 /*!
14 12
  * \brief Check if a file is a valid PNG image
15 13
  * \param filename path of file to read
@@ -27,7 +25,8 @@ int pngCheck(const char *filename);
27 25
  * \param bpp place where pixel width will be stored (8, 24, 32)
28 26
  * \returns 0 on success
29 27
  */
30
-int pngLoad(const char *filename, unsigned char **image, unsigned int *width, unsigned int *height, TextureManager::ColorMode *mode, unsigned int *bpp);
28
+int pngLoad(const char *filename, unsigned char **image,
29
+        unsigned int *width, unsigned int *height, ColorMode *mode, unsigned int *bpp);
31 30
 
32 31
 /*!
33 32
  * \brief Create a PNG image file from an RGBA buffer
@@ -39,7 +38,8 @@ int pngLoad(const char *filename, unsigned char **image, unsigned int *width, un
39 38
  * \param bpp bits per pixel (8, 24, 32)
40 39
  * \returns 0 on success
41 40
  */
42
-int pngSave(const char *filename, unsigned char *image, unsigned int width, unsigned int height, TextureManager::ColorMode mode, unsigned int bpp);
41
+int pngSave(const char *filename, unsigned char *image,
42
+        unsigned int width, unsigned int height, ColorMode mode, unsigned int bpp);
43 43
 
44 44
 #endif
45 45
 

+ 1
- 1
src/Camera.cpp Прегледај датотеку

@@ -64,7 +64,7 @@ void Camera::update() {
64 64
 
65 65
 void Camera::rotate(float angle, float x, float y, float z) {
66 66
     Quaternion t, n;
67
-    vec_t look[4] = { 0.0f, 0.0f, -1.0f, 1.0f };
67
+    float look[4] = { 0.0f, 0.0f, -1.0f, 1.0f };
68 68
 
69 69
     t.set(angle, x, y, z);
70 70
     n = mQ * t;

+ 20
- 30
src/Command.cpp Прегледај датотеку

@@ -100,9 +100,9 @@ int OpenRaider::command(std::string &c) {
100 100
             getConsole().print("  set       - set a parameter");
101 101
             getConsole().print("  bind      - bind a keyboard/mouse action");
102 102
             getConsole().print("  animate   - [BOOL|n|p] - Animate models");
103
+            getConsole().print("  move      - [walk|fly|noclip]");
103 104
 /*
104 105
             getConsole().print("  sshot     - make a screenshot");
105
-            getConsole().print("  move      - [walk|fly|noclip]");
106 106
             getConsole().print("  sound     - INT - Test play sound");
107 107
             getConsole().print("  mode      - MODE - Render mode");
108 108
             getConsole().print("  light     - BOOL - GL Lights");
@@ -174,6 +174,25 @@ int OpenRaider::command(std::string &c) {
174 174
                 getRender().clearFlags(Render::fAnimateAllModels);
175 175
             getConsole().print(b ? "Animating all models" : "No longer animating all models");
176 176
         }
177
+    } else if (cmd.compare("move") == 0) {
178
+        if ((!mRunning) || (!getGame().isLoaded())) {
179
+            getConsole().print("Use move command interactively!");
180
+            return -999;
181
+        }
182
+        std::string temp;
183
+        command >> temp;
184
+        if (temp.compare("walk") == 0) {
185
+            getGame().getLara().setMoveType(Entity::MoveTypeWalk);
186
+        } else if (temp.compare("fly") == 0) {
187
+            getGame().getLara().setMoveType(Entity::MoveTypeFly);
188
+        } else if (temp.compare("noclip") == 0) {
189
+            getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
190
+        } else {
191
+            getConsole().print("Invalid use of move command (%s)!", temp.c_str());
192
+            return -9;
193
+        }
194
+        getConsole().print("%sing", temp.c_str());
195
+
177 196
 /*
178 197
     } else if (cmd.compare("mode") == 0) {
179 198
         std::string mode;
@@ -384,35 +403,6 @@ int OpenRaider::command(std::string &c) {
384 403
         }
385 404
         getConsole().print("Screenshot stored...");
386 405
         delete filename;
387
-    } else if (cmd.compare("move") == 0) {
388
-        if (!mRunning) {
389
-            getConsole().print("Use move command interactively!");
390
-            return -999;
391
-        }
392
-        if (args->size() > 0) {
393
-            if (getGame().isLoaded()) {
394
-                char *move = args->at(0);
395
-                if (strcmp(move, "walk") == 0) {
396
-                    getGame().getLara().setMoveType(Entity::MoveTypeWalk);
397
-                    getConsole().print("Lara is walking...");
398
-                } else if (strcmp(move, "fly") == 0) {
399
-                    getGame().getLara().setMoveType(Entity::MoveTypeFly);
400
-                    getConsole().print("Lara is flying...");
401
-                } else if (strcmp(move, "noclip") == 0) {
402
-                    getGame().getLara().setMoveType(Entity::MoveTypeNoClipping);
403
-                    getConsole().print("Lara is noclipping...");
404
-                } else {
405
-                    getConsole().print("Invalid use of move command (%s)!", move);
406
-                    return -9;
407
-                }
408
-            } else {
409
-                getConsole().print("Load a level to change the movement type!");
410
-                return -10;
411
-            }
412
-        } else {
413
-            getConsole().print("Invalid use of move command!");
414
-            return -11;
415
-        }
416 406
     } else if (cmd.compare("sound") == 0) {
417 407
         if ((!mRunning) || (!getGame().isLoaded())) {
418 408
             getConsole().print("Use sound command interactively!");

+ 4
- 3
src/Entity.cpp Прегледај датотеку

@@ -44,7 +44,7 @@ void Entity::display() {
44 44
     glTranslatef(pos[0], pos[1], pos[2]);
45 45
     glRotatef(OR_RAD_TO_DEG(angles[1]), 0, 1, 0);
46 46
     glRotatef(OR_RAD_TO_DEG(angles[0]), 1, 0, 0);
47
-    glRotatef(OR_RAD_TO_DEG(angles[2]), 0, 0, 1);
47
+    //glRotatef(OR_RAD_TO_DEG(angles[2]), 0, 0, 1);
48 48
     getWorld().getSkeletalModel(skeletalModel).display(animationFrame, boneFrame);
49 49
     glPopMatrix();
50 50
 
@@ -236,8 +236,9 @@ int Entity::getObjectId() {
236 236
     return objectId;
237 237
 }
238 238
 
239
-void Entity::setAngle(vec_t yaw) {
240
-    angles[1] = yaw;
239
+void Entity::setAngles(vec3_t a) {
240
+    for (unsigned int i = 0; i < 3; i++)
241
+        angles[i] = a[i];
241 242
 }
242 243
 
243 244
 vec_t Entity::getPos(unsigned int i) {

+ 4
- 3
src/FontSDL.cpp Прегледај датотеку

@@ -19,8 +19,10 @@ FontSDL::~FontSDL() {
19 19
     if (mFont)
20 20
         TTF_CloseFont(mFont);
21 21
 
22
-    if (mFontInit)
22
+    if (mFontInit) {
23 23
         TTF_Quit();
24
+        glDeleteTextures(1, &mFontTexture);
25
+    }
24 26
 }
25 27
 
26 28
 int FontSDL::initialize() {
@@ -81,6 +83,7 @@ void FontSDL::writeString(FontString &s) {
81 83
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
82 84
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
83 85
     glTexImage2D(GL_TEXTURE_2D, 0, surface->format->BytesPerPixel, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
86
+    SDL_FreeSurface(surface);
84 87
 
85 88
     GLuint xMin = s.x;
86 89
     GLuint yMin = s.y;
@@ -102,7 +105,5 @@ void FontSDL::writeString(FontString &s) {
102 105
     glTexCoord2f(1.0f, 0.0f);
103 106
     glVertex2i(xMax, yMin);
104 107
     glEnd();
105
-
106
-    SDL_FreeSurface(surface);
107 108
 }
108 109
 

+ 4
- 3
src/Game.cpp Прегледај датотеку

@@ -164,7 +164,8 @@ void Game::handleMouseMotion(int xrel, int yrel) {
164 164
                 getCamera().command(CAMERA_ROTATE_DOWN);
165 165
 
166 166
         // Fix Laras rotation
167
-        getLara().setAngle(getCamera().getRadianYaw());
167
+        vec3_t angles = { 0.0f, getCamera().getRadianYaw(), getCamera().getRadianPitch() };
168
+        getLara().setAngles(angles);
168 169
     }
169 170
 }
170 171
 
@@ -259,7 +260,7 @@ void Game::processTextures()
259 260
 
260 261
         // Overwrite any previous level textures on load
261 262
         getTextureManager().loadBufferSlot(image, 256, 256,
262
-                TextureManager::RGBA, 32, (mTextureStart - 1) + i);
263
+                RGBA, 32, (mTextureStart - 1) + i);
263 264
 
264 265
 #ifdef MULTITEXTURE
265 266
         gMapTex2Bump[(mTextureStart - 1) + i] = -1;
@@ -272,7 +273,7 @@ void Game::processTextures()
272 273
                     mTombRaider.NumTextures();
273 274
 #endif
274 275
             getTextureManager().loadBufferSlot(bumpmap, 256, 256,
275
-                    TextureManager::RGBA, 32,
276
+                    RGBA, 32,
276 277
                     (mTextureStart - 1) + i + mTombRaider.NumTextures());
277 278
         }
278 279
 

+ 2
- 1
src/StaticMesh.cpp Прегледај датотеку

@@ -117,12 +117,13 @@ int setupTextureColor(float *colorf) {
117 117
     } catch (...) {
118 118
         unsigned char *image = generateColorTexture(color, 32, 32, 32);
119 119
         texture = getTextureManager().loadBufferSlot(image, 32, 32,
120
-                TextureManager::RGBA, 32, getTextureManager().getTextureCount());
120
+                RGBA, 32, getTextureManager().getTextureCount());
121 121
         delete [] image;
122 122
     }
123 123
 
124 124
     return texture;
125 125
 }
126
+
126 127
 #endif
127 128
 
128 129
 StaticMesh::StaticMesh(TombRaider &tr, unsigned int index) {

+ 61
- 33
src/TextureManager.cpp Прегледај датотеку

@@ -19,6 +19,10 @@
19 19
 #include "utils/tga.h"
20 20
 #include "TextureManager.h"
21 21
 
22
+#ifdef USING_PNG
23
+#include "utils/png.h"
24
+#endif
25
+
22 26
 TextureManager::TextureManager() {
23 27
     mFlags = 0;
24 28
 }
@@ -107,23 +111,7 @@ int TextureManager::loadBufferSlot(unsigned char *image,
107 111
     assert((mode == GREYSCALE) || (mode == RGB)
108 112
             || (mode == BGR) || (mode == ARGB)
109 113
             || (mode == RGBA) || (mode ==  BGRA));
110
-
111
-    switch (mode) {
112
-        case GREYSCALE:
113
-            assert(bpp == 8);
114
-            break;
115
-
116
-        case RGB:
117
-        case BGR:
118
-            assert(bpp == 24);
119
-            break;
120
-
121
-        case ARGB:
122
-        case RGBA:
123
-        case BGRA:
124
-            assert(bpp == 32);
125
-            break;
126
-    }
114
+    assert((bpp == 8) || (bpp == 24) || (bpp == 32));
127 115
 
128 116
     while (mTextureIds.size() <= slot) {
129 117
         unsigned int id;
@@ -131,39 +119,33 @@ int TextureManager::loadBufferSlot(unsigned char *image,
131 119
         mTextureIds.push_back(id);
132 120
     }
133 121
 
134
-    unsigned char bytes;
135 122
     unsigned int glcMode;
136
-
137 123
     switch (mode) {
138 124
         case GREYSCALE:
139
-            bytes = 1;
140 125
             glcMode = GL_LUMINANCE;
141 126
             break;
142 127
 
128
+        case BGR:
129
+            bgr2rgb24(image, width, height);
130
+            glcMode = GL_RGB;
131
+            break;
132
+
143 133
         case RGB:
144
-            bytes = 3;
145 134
             glcMode = GL_RGB;
146 135
             break;
147 136
 
148 137
         case ARGB:
149 138
             argb2rgba32(image, width, height);
150
-            bytes = 4;
151 139
             glcMode = GL_RGBA;
152 140
             break;
153 141
 
154
-        case RGBA:
155
-            bytes = 4;
142
+        case BGRA:
143
+            bgra2rgba32(image, width, height);
156 144
             glcMode = GL_RGBA;
157 145
             break;
158 146
 
159
-        case BGR:
160
-            bytes = 3;
161
-            glcMode = GL_BGR_EXT;
162
-            break;
163
-
164
-        case BGRA:
165
-            bytes = 4;
166
-            glcMode = GL_BGRA_EXT;
147
+        case RGBA:
148
+            glcMode = GL_RGBA;
167 149
             break;
168 150
     }
169 151
 
@@ -185,7 +167,7 @@ int TextureManager::loadBufferSlot(unsigned char *image,
185 167
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
186 168
 
187 169
     glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
188
-    glTexImage2D(GL_TEXTURE_2D, 0, bytes, width, height, 0, glcMode, GL_UNSIGNED_BYTE, image);
170
+    glTexImage2D(GL_TEXTURE_2D, 0, bpp / 8, width, height, 0, glcMode, GL_UNSIGNED_BYTE, image);
189 171
 
190 172
     //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
191 173
 
@@ -201,6 +183,20 @@ void TextureManager::bindTextureId(unsigned int n) {
201 183
     glBindTexture(GL_TEXTURE_2D, mTextureIds.at(n));
202 184
 }
203 185
 
186
+int TextureManager::loadImage(const char *filename) {
187
+    if (stringEndsWith(filename, ".pcx") || stringEndsWith(filename, ".PCX")) {
188
+        return loadPCX(filename);
189
+    } else if (stringEndsWith(filename, ".png") || stringEndsWith(filename, ".PNG")) {
190
+        return loadPNG(filename);
191
+    } else if (stringEndsWith(filename, ".tga") || stringEndsWith(filename, ".TGA")) {
192
+        return loadTGA(filename);
193
+    } else {
194
+        getConsole().print("No known image file type? (%s)", filename);
195
+    }
196
+
197
+    return -1;
198
+}
199
+
204 200
 int TextureManager::loadPCX(const char *filename) {
205 201
     assert(filename != NULL);
206 202
     assert(filename[0] != '\0');
@@ -224,6 +220,38 @@ int TextureManager::loadPCX(const char *filename) {
224 220
     return id;
225 221
 }
226 222
 
223
+int TextureManager::loadPNG(const char *filename) {
224
+#ifdef USING_PNG
225
+    assert(filename != NULL);
226
+    assert(filename[0] != '\0');
227
+
228
+    if (pngCheck(filename) != 0) {
229
+        return -1;
230
+    }
231
+
232
+    unsigned char *image;
233
+    unsigned int w, h, bpp;
234
+    ColorMode c;
235
+    int id = -1;
236
+    int error = pngLoad(filename, &image, &w, &h, &c, &bpp);
237
+
238
+    if (error == 0) {
239
+        unsigned char *image2 = scaleBuffer(image, &w, &h, bpp);
240
+        if (image2) {
241
+            delete [] image;
242
+            image = image2;
243
+        }
244
+        id = loadBufferSlot(image, w, h, c, bpp, mTextureIds.size());
245
+        delete [] image;
246
+    }
247
+
248
+    return id;
249
+#else
250
+    getConsole().print("No PNG support available (%s)", filename);
251
+    return -1;
252
+#endif
253
+}
254
+
227 255
 int TextureManager::loadTGA(const char *filename) {
228 256
     assert(filename != NULL);
229 257
     assert(filename[0] != '\0');

+ 3
- 8
src/WindowSDL.cpp Прегледај датотеку

@@ -90,14 +90,9 @@ int WindowSDL::initialize() {
90 90
 
91 91
     if (SDL_GL_LoadLibrary(mDriver) < 0) {
92 92
         SDL_ClearError();
93
-        if (SDL_GL_LoadLibrary("libGL.so") < 0) {
94
-            SDL_ClearError();
95
-            if (SDL_GL_LoadLibrary("libGL.so.1") < 0) {
96
-                printf("Could not load OpenGL driver!\n");
97
-                printf("SDL_GL_LoadLibrary Error: %s\n", SDL_GetError());
98
-                return -2;
99
-            }
100
-        }
93
+        printf("Could not load OpenGL driver!\n");
94
+        printf("SDL_GL_LoadLibrary Error: %s\n", SDL_GetError());
95
+        return -2;
101 96
     }
102 97
 #endif
103 98
 

+ 3
- 2
src/utils/pcx.cpp Прегледај датотеку

@@ -67,7 +67,8 @@ int pcxCheck(const char *filename) {
67 67
     return 0;
68 68
 }
69 69
 
70
-int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, unsigned int *height, TextureManager::ColorMode *mode, unsigned int *bpp) {
70
+int pcxLoad(const char *filename, unsigned char **image,
71
+        unsigned int *width, unsigned int *height, ColorMode *mode, unsigned int *bpp) {
71 72
     assert(filename != NULL);
72 73
     assert(filename[0] != '\0');
73 74
     assert(image != NULL);
@@ -240,7 +241,7 @@ int pcxLoad(const char *filename, unsigned char **image, unsigned int *width, un
240 241
         }
241 242
     }
242 243
 
243
-    *mode = TextureManager::RGBA;
244
+    *mode = RGBA;
244 245
     *bpp = 32;
245 246
 
246 247
     delete [] buffer;

+ 12
- 10
src/utils/png.cpp Прегледај датотеку

@@ -41,7 +41,8 @@ int pngCheck(const char *filename) {
41 41
     return 0;
42 42
 }
43 43
 
44
-int pngLoad(const char *filename, unsigned char **image, unsigned int *width, unsigned int *height, TextureManager::ColorMode *mode, unsigned int *bpp) {
44
+int pngLoad(const char *filename, unsigned char **image,
45
+        unsigned int *width, unsigned int *height, ColorMode *mode, unsigned int *bpp) {
45 46
     png_byte header[8];
46 47
 
47 48
     assert(filename != NULL);
@@ -131,13 +132,13 @@ int pngLoad(const char *filename, unsigned char **image, unsigned int *width, un
131 132
     fclose(fp);
132 133
 
133 134
     if (color_type == PNG_COLOR_TYPE_GRAY) {
134
-        *mode = TextureManager::GREYSCALE;
135
+        *mode = GREYSCALE;
135 136
         *bpp = 8;
136 137
     } else if (color_type == PNG_COLOR_TYPE_RGB) {
137
-        *mode = TextureManager::RGB;
138
+        *mode = RGB;
138 139
         *bpp = 24;
139 140
     } else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
140
-        *mode = TextureManager::RGBA;
141
+        *mode = RGBA;
141 142
         *bpp = 32;
142 143
     } else {
143 144
         pngPrint("%s: Unknown libpng color type %d.", filename, color_type);
@@ -164,7 +165,8 @@ int pngLoad(const char *filename, unsigned char **image, unsigned int *width, un
164 165
     return 0;
165 166
 }
166 167
 
167
-int pngSave(const char *filename, unsigned char *image, unsigned int width, unsigned int height, TextureManager::ColorMode mode, unsigned int bpp) {
168
+int pngSave(const char *filename, unsigned char *image,
169
+        unsigned int width, unsigned int height, ColorMode mode, unsigned int bpp) {
168 170
     assert(filename != NULL);
169 171
     assert(filename[0] != '\0');
170 172
     assert(image != NULL);
@@ -207,15 +209,15 @@ int pngSave(const char *filename, unsigned char *image, unsigned int width, unsi
207 209
     }
208 210
 
209 211
     int color_type;
210
-    if ((mode == TextureManager::GREYSCALE) && (bpp == 8)) {
212
+    if ((mode == GREYSCALE) && (bpp == 8)) {
211 213
         color_type = PNG_COLOR_TYPE_GRAY;
212
-    } else if (((mode == TextureManager::RGB) || (mode == TextureManager::BGR)) && (bpp == 24)) {
213
-        if (mode == TextureManager::BGR) {
214
+    } else if (((mode == RGB) || (mode == BGR)) && (bpp == 24)) {
215
+        if (mode == BGR) {
214 216
             bgr2rgb24(image, width, height);
215 217
         }
216 218
         color_type = PNG_COLOR_TYPE_RGB;
217
-    } else if (((mode == TextureManager::RGBA) || (mode == TextureManager::BGRA)) && (bpp == 32)) {
218
-        if (mode == TextureManager::BGRA) {
219
+    } else if (((mode == RGBA) || (mode == BGRA)) && (bpp == 32)) {
220
+        if (mode == BGRA) {
219 221
             bgra2rgba32(image, width, height);
220 222
         }
221 223
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;

Loading…
Откажи
Сачувај