Browse Source

loadImage(), move command

Thomas Buck 10 years ago
parent
commit
a74c620a72

+ 7
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
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
     [ 20140624 ]
12
     [ 20140624 ]
6
     * Some changes to allow compilation with Ubuntu 14.04 / gcc
13
     * Some changes to allow compilation with Ubuntu 14.04 / gcc
7
     * Modified utils/png to allow compilation with different integer sizes
14
     * Modified utils/png to allow compilation with different integer sizes

+ 1
- 1
include/Entity.h View File

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

+ 5
- 17
include/TextureManager.h View File

17
 class TextureManager {
17
 class TextureManager {
18
 public:
18
 public:
19
 
19
 
20
-    enum ColorMode {
21
-        GREYSCALE,
22
-        RGB,
23
-        RGBA,
24
-        ARGB,
25
-        BGR,
26
-        BGRA
27
-    };
28
-
29
     enum TextureFlag {
20
     enum TextureFlag {
30
         fUseMultiTexture = (1 << 0),
21
         fUseMultiTexture = (1 << 0),
31
     };
22
     };
89
                         ColorMode mode, unsigned int bpp,
80
                         ColorMode mode, unsigned int bpp,
90
                         unsigned int slot);
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
      * \brief Sets an option flag
86
      * \brief Sets an option flag
107
     void useMultiTexture(float aU, float aV, float bU, float bV);
91
     void useMultiTexture(float aU, float aV, float bU, float bV);
108
 
92
 
109
 private:
93
 private:
94
+    int loadTGA(const char *filename);
95
+    int loadPCX(const char *filename);
96
+    int loadPNG(const char *filename);
97
+
110
     std::vector<unsigned int> mTextureIds;
98
     std::vector<unsigned int> mTextureIds;
111
     unsigned int mFlags;
99
     unsigned int mFlags;
112
 };
100
 };

+ 42
- 32
include/global.h View File

15
 #define DEFAULT_WIDTH 640
15
 #define DEFAULT_WIDTH 640
16
 #define DEFAULT_HEIGHT 480
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
 // Colors used where ever needed
28
 // Colors used where ever needed
52
 const unsigned char BLACK[]  = {   0,   0,   0, 255 };
29
 const unsigned char BLACK[]  = {   0,   0,   0, 255 };
107
 
84
 
108
 KeyboardButton stringToKeyboardButton(const char *key);
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
 #endif
120
 #endif
111
 
121
 

+ 2
- 3
include/utils/pcx.h View File

11
 #ifndef _UTILS_PCX_H_
11
 #ifndef _UTILS_PCX_H_
12
 #define _UTILS_PCX_H_
12
 #define _UTILS_PCX_H_
13
 
13
 
14
-#include "TextureManager.h"
15
-
16
 /*!
14
 /*!
17
  * \brief Check if a file is a valid PCX image
15
  * \brief Check if a file is a valid PCX image
18
  * \param filename path of file to read
16
  * \param filename path of file to read
30
  * \param bpp place where pixel width will be stored (8, 24, 32)
28
  * \param bpp place where pixel width will be stored (8, 24, 32)
31
  * \returns 0 on success
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
 #endif
34
 #endif
36
 
35
 

+ 4
- 4
include/utils/png.h View File

8
 #ifndef _UTILS_PNG_H_
8
 #ifndef _UTILS_PNG_H_
9
 #define _UTILS_PNG_H_
9
 #define _UTILS_PNG_H_
10
 
10
 
11
-#include "TextureManager.h"
12
-
13
 /*!
11
 /*!
14
  * \brief Check if a file is a valid PNG image
12
  * \brief Check if a file is a valid PNG image
15
  * \param filename path of file to read
13
  * \param filename path of file to read
27
  * \param bpp place where pixel width will be stored (8, 24, 32)
25
  * \param bpp place where pixel width will be stored (8, 24, 32)
28
  * \returns 0 on success
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
  * \brief Create a PNG image file from an RGBA buffer
32
  * \brief Create a PNG image file from an RGBA buffer
39
  * \param bpp bits per pixel (8, 24, 32)
38
  * \param bpp bits per pixel (8, 24, 32)
40
  * \returns 0 on success
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
 #endif
44
 #endif
45
 
45
 

+ 1
- 1
src/Camera.cpp View File

64
 
64
 
65
 void Camera::rotate(float angle, float x, float y, float z) {
65
 void Camera::rotate(float angle, float x, float y, float z) {
66
     Quaternion t, n;
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
     t.set(angle, x, y, z);
69
     t.set(angle, x, y, z);
70
     n = mQ * t;
70
     n = mQ * t;

+ 20
- 30
src/Command.cpp View File

100
             getConsole().print("  set       - set a parameter");
100
             getConsole().print("  set       - set a parameter");
101
             getConsole().print("  bind      - bind a keyboard/mouse action");
101
             getConsole().print("  bind      - bind a keyboard/mouse action");
102
             getConsole().print("  animate   - [BOOL|n|p] - Animate models");
102
             getConsole().print("  animate   - [BOOL|n|p] - Animate models");
103
+            getConsole().print("  move      - [walk|fly|noclip]");
103
 /*
104
 /*
104
             getConsole().print("  sshot     - make a screenshot");
105
             getConsole().print("  sshot     - make a screenshot");
105
-            getConsole().print("  move      - [walk|fly|noclip]");
106
             getConsole().print("  sound     - INT - Test play sound");
106
             getConsole().print("  sound     - INT - Test play sound");
107
             getConsole().print("  mode      - MODE - Render mode");
107
             getConsole().print("  mode      - MODE - Render mode");
108
             getConsole().print("  light     - BOOL - GL Lights");
108
             getConsole().print("  light     - BOOL - GL Lights");
174
                 getRender().clearFlags(Render::fAnimateAllModels);
174
                 getRender().clearFlags(Render::fAnimateAllModels);
175
             getConsole().print(b ? "Animating all models" : "No longer animating all models");
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
     } else if (cmd.compare("mode") == 0) {
197
     } else if (cmd.compare("mode") == 0) {
179
         std::string mode;
198
         std::string mode;
384
         }
403
         }
385
         getConsole().print("Screenshot stored...");
404
         getConsole().print("Screenshot stored...");
386
         delete filename;
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
     } else if (cmd.compare("sound") == 0) {
406
     } else if (cmd.compare("sound") == 0) {
417
         if ((!mRunning) || (!getGame().isLoaded())) {
407
         if ((!mRunning) || (!getGame().isLoaded())) {
418
             getConsole().print("Use sound command interactively!");
408
             getConsole().print("Use sound command interactively!");

+ 4
- 3
src/Entity.cpp View File

44
     glTranslatef(pos[0], pos[1], pos[2]);
44
     glTranslatef(pos[0], pos[1], pos[2]);
45
     glRotatef(OR_RAD_TO_DEG(angles[1]), 0, 1, 0);
45
     glRotatef(OR_RAD_TO_DEG(angles[1]), 0, 1, 0);
46
     glRotatef(OR_RAD_TO_DEG(angles[0]), 1, 0, 0);
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
     getWorld().getSkeletalModel(skeletalModel).display(animationFrame, boneFrame);
48
     getWorld().getSkeletalModel(skeletalModel).display(animationFrame, boneFrame);
49
     glPopMatrix();
49
     glPopMatrix();
50
 
50
 
236
     return objectId;
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
 vec_t Entity::getPos(unsigned int i) {
244
 vec_t Entity::getPos(unsigned int i) {

+ 4
- 3
src/FontSDL.cpp View File

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

+ 4
- 3
src/Game.cpp View File

164
                 getCamera().command(CAMERA_ROTATE_DOWN);
164
                 getCamera().command(CAMERA_ROTATE_DOWN);
165
 
165
 
166
         // Fix Laras rotation
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
 
260
 
260
         // Overwrite any previous level textures on load
261
         // Overwrite any previous level textures on load
261
         getTextureManager().loadBufferSlot(image, 256, 256,
262
         getTextureManager().loadBufferSlot(image, 256, 256,
262
-                TextureManager::RGBA, 32, (mTextureStart - 1) + i);
263
+                RGBA, 32, (mTextureStart - 1) + i);
263
 
264
 
264
 #ifdef MULTITEXTURE
265
 #ifdef MULTITEXTURE
265
         gMapTex2Bump[(mTextureStart - 1) + i] = -1;
266
         gMapTex2Bump[(mTextureStart - 1) + i] = -1;
272
                     mTombRaider.NumTextures();
273
                     mTombRaider.NumTextures();
273
 #endif
274
 #endif
274
             getTextureManager().loadBufferSlot(bumpmap, 256, 256,
275
             getTextureManager().loadBufferSlot(bumpmap, 256, 256,
275
-                    TextureManager::RGBA, 32,
276
+                    RGBA, 32,
276
                     (mTextureStart - 1) + i + mTombRaider.NumTextures());
277
                     (mTextureStart - 1) + i + mTombRaider.NumTextures());
277
         }
278
         }
278
 
279
 

+ 2
- 1
src/StaticMesh.cpp View File

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

+ 61
- 33
src/TextureManager.cpp View File

19
 #include "utils/tga.h"
19
 #include "utils/tga.h"
20
 #include "TextureManager.h"
20
 #include "TextureManager.h"
21
 
21
 
22
+#ifdef USING_PNG
23
+#include "utils/png.h"
24
+#endif
25
+
22
 TextureManager::TextureManager() {
26
 TextureManager::TextureManager() {
23
     mFlags = 0;
27
     mFlags = 0;
24
 }
28
 }
107
     assert((mode == GREYSCALE) || (mode == RGB)
111
     assert((mode == GREYSCALE) || (mode == RGB)
108
             || (mode == BGR) || (mode == ARGB)
112
             || (mode == BGR) || (mode == ARGB)
109
             || (mode == RGBA) || (mode ==  BGRA));
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
     while (mTextureIds.size() <= slot) {
116
     while (mTextureIds.size() <= slot) {
129
         unsigned int id;
117
         unsigned int id;
131
         mTextureIds.push_back(id);
119
         mTextureIds.push_back(id);
132
     }
120
     }
133
 
121
 
134
-    unsigned char bytes;
135
     unsigned int glcMode;
122
     unsigned int glcMode;
136
-
137
     switch (mode) {
123
     switch (mode) {
138
         case GREYSCALE:
124
         case GREYSCALE:
139
-            bytes = 1;
140
             glcMode = GL_LUMINANCE;
125
             glcMode = GL_LUMINANCE;
141
             break;
126
             break;
142
 
127
 
128
+        case BGR:
129
+            bgr2rgb24(image, width, height);
130
+            glcMode = GL_RGB;
131
+            break;
132
+
143
         case RGB:
133
         case RGB:
144
-            bytes = 3;
145
             glcMode = GL_RGB;
134
             glcMode = GL_RGB;
146
             break;
135
             break;
147
 
136
 
148
         case ARGB:
137
         case ARGB:
149
             argb2rgba32(image, width, height);
138
             argb2rgba32(image, width, height);
150
-            bytes = 4;
151
             glcMode = GL_RGBA;
139
             glcMode = GL_RGBA;
152
             break;
140
             break;
153
 
141
 
154
-        case RGBA:
155
-            bytes = 4;
142
+        case BGRA:
143
+            bgra2rgba32(image, width, height);
156
             glcMode = GL_RGBA;
144
             glcMode = GL_RGBA;
157
             break;
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
             break;
149
             break;
168
     }
150
     }
169
 
151
 
185
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
167
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
186
 
168
 
187
     glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
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
     //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
172
     //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
191
 
173
 
201
     glBindTexture(GL_TEXTURE_2D, mTextureIds.at(n));
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
 int TextureManager::loadPCX(const char *filename) {
200
 int TextureManager::loadPCX(const char *filename) {
205
     assert(filename != NULL);
201
     assert(filename != NULL);
206
     assert(filename[0] != '\0');
202
     assert(filename[0] != '\0');
224
     return id;
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
 int TextureManager::loadTGA(const char *filename) {
255
 int TextureManager::loadTGA(const char *filename) {
228
     assert(filename != NULL);
256
     assert(filename != NULL);
229
     assert(filename[0] != '\0');
257
     assert(filename[0] != '\0');

+ 3
- 8
src/WindowSDL.cpp View File

90
 
90
 
91
     if (SDL_GL_LoadLibrary(mDriver) < 0) {
91
     if (SDL_GL_LoadLibrary(mDriver) < 0) {
92
         SDL_ClearError();
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
 #endif
97
 #endif
103
 
98
 

+ 3
- 2
src/utils/pcx.cpp View File

67
     return 0;
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
     assert(filename != NULL);
72
     assert(filename != NULL);
72
     assert(filename[0] != '\0');
73
     assert(filename[0] != '\0');
73
     assert(image != NULL);
74
     assert(image != NULL);
240
         }
241
         }
241
     }
242
     }
242
 
243
 
243
-    *mode = TextureManager::RGBA;
244
+    *mode = RGBA;
244
     *bpp = 32;
245
     *bpp = 32;
245
 
246
 
246
     delete [] buffer;
247
     delete [] buffer;

+ 12
- 10
src/utils/png.cpp View File

41
     return 0;
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
     png_byte header[8];
46
     png_byte header[8];
46
 
47
 
47
     assert(filename != NULL);
48
     assert(filename != NULL);
131
     fclose(fp);
132
     fclose(fp);
132
 
133
 
133
     if (color_type == PNG_COLOR_TYPE_GRAY) {
134
     if (color_type == PNG_COLOR_TYPE_GRAY) {
134
-        *mode = TextureManager::GREYSCALE;
135
+        *mode = GREYSCALE;
135
         *bpp = 8;
136
         *bpp = 8;
136
     } else if (color_type == PNG_COLOR_TYPE_RGB) {
137
     } else if (color_type == PNG_COLOR_TYPE_RGB) {
137
-        *mode = TextureManager::RGB;
138
+        *mode = RGB;
138
         *bpp = 24;
139
         *bpp = 24;
139
     } else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
140
     } else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
140
-        *mode = TextureManager::RGBA;
141
+        *mode = RGBA;
141
         *bpp = 32;
142
         *bpp = 32;
142
     } else {
143
     } else {
143
         pngPrint("%s: Unknown libpng color type %d.", filename, color_type);
144
         pngPrint("%s: Unknown libpng color type %d.", filename, color_type);
164
     return 0;
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
     assert(filename != NULL);
170
     assert(filename != NULL);
169
     assert(filename[0] != '\0');
171
     assert(filename[0] != '\0');
170
     assert(image != NULL);
172
     assert(image != NULL);
207
     }
209
     }
208
 
210
 
209
     int color_type;
211
     int color_type;
210
-    if ((mode == TextureManager::GREYSCALE) && (bpp == 8)) {
212
+    if ((mode == GREYSCALE) && (bpp == 8)) {
211
         color_type = PNG_COLOR_TYPE_GRAY;
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
             bgr2rgb24(image, width, height);
216
             bgr2rgb24(image, width, height);
215
         }
217
         }
216
         color_type = PNG_COLOR_TYPE_RGB;
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
             bgra2rgba32(image, width, height);
221
             bgra2rgba32(image, width, height);
220
         }
222
         }
221
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
223
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;

Loading…
Cancel
Save