Browse Source

Added texture debugging

Thomas Buck 10 years ago
parent
commit
f570706e20
7 changed files with 88 additions and 13 deletions
  1. 1
    0
      README.md
  2. 7
    0
      include/Render.h
  3. 17
    0
      include/Texture.h
  4. 3
    3
      src/CMakeLists.txt
  5. 8
    0
      src/OpenRaider.cpp
  6. 7
    0
      src/Render.cpp
  7. 45
    10
      src/Texture.cpp

+ 1
- 0
README.md View File

152
 
152
 
153
 | Command          | Action                                       |
153
 | Command          | Action                                       |
154
 | ----------------:|:-------------------------------------------- |
154
 | ----------------:|:-------------------------------------------- |
155
+| texture INT      | Display the specified 2D texture for 2s      |
155
 | wireframe        | Render in wireframe (for debugging)          |
156
 | wireframe        | Render in wireframe (for debugging)          |
156
 | solid            | Render solid color polygons                  |
157
 | solid            | Render solid color polygons                  |
157
 | texture          | Render with textures                         |
158
 | texture          | Render with textures                         |

+ 7
- 0
include/Render.h View File

232
 
232
 
233
     void addSkeletalModel(SkeletalModel *mdl);
233
     void addSkeletalModel(SkeletalModel *mdl);
234
 
234
 
235
+    /*!
236
+     * \brief Show a texture for a second, for debugging
237
+     * \param textureId texture id to show
238
+     * \returns GL texture id on success, < 0 on error
239
+     */
240
+    int showTextureDebug(int textureId);
241
+
235
 private:
242
 private:
236
 
243
 
237
     /*!
244
     /*!

+ 17
- 0
include/Texture.h View File

231
 
231
 
232
     void useMultiTexture(float aU, float aV, float bU, float bV);
232
     void useMultiTexture(float aU, float aV, float bU, float bV);
233
 
233
 
234
+    /*!
235
+     * \brief Show a texture for a second, for debugging
236
+     * \param textureId texture id to show
237
+     * \returns GL texture id on success, < 0 on error
238
+     */
239
+    int showTextureDebug(int textureId);
240
+
241
+    /*!
242
+     * \brief Renders debug texture.
243
+     *
244
+     * Called in 2D mode from Texture::Display().
245
+     */
246
+    void debugTextureRender(int width, int height);
247
+
234
 private:
248
 private:
235
 
249
 
236
     int nextPower(int seed);
250
     int nextPower(int seed);
238
     unsigned char *scaleBuffer(unsigned char *image, int width, int height,
252
     unsigned char *scaleBuffer(unsigned char *image, int width, int height,
239
                                 int components);
253
                                 int components);
240
 
254
 
255
+    int textureDebug;
256
+    int textureDebugFrames;
257
+
241
     unsigned int *mTextureIds;  //!< GL texture list
258
     unsigned int *mTextureIds;  //!< GL texture list
242
     unsigned int mTextureCount; //!< Texture counter
259
     unsigned int mTextureCount; //!< Texture counter
243
     unsigned int mTextureLimit; //!< The texture limit
260
     unsigned int mTextureLimit; //!< The texture limit

+ 3
- 3
src/CMakeLists.txt View File

26
     set (MACOSX_BUNDLE_INFO_STRING "OpenSource TombRaider Game Engine")
26
     set (MACOSX_BUNDLE_INFO_STRING "OpenSource TombRaider Game Engine")
27
     set (MACOSX_BUNDLE_ICON_FILE "AppIcon")
27
     set (MACOSX_BUNDLE_ICON_FILE "AppIcon")
28
     set (MACOSX_BUNDLE_GUI_IDENTIFIER "de.xythobuz.OpenRaider")
28
     set (MACOSX_BUNDLE_GUI_IDENTIFIER "de.xythobuz.OpenRaider")
29
-    set (MACOSX_BUNDLE_LONG_VERSION_STRING "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}-${OpenRaider_VERSION_RELEASE}")
30
     set (MACOSX_BUNDLE_BUNDLE_NAME "OpenRaider")
29
     set (MACOSX_BUNDLE_BUNDLE_NAME "OpenRaider")
31
-    set (MACOSX_BUNDLE_SHORT_VERSION_STRING "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}-${OpenRaider_VERSION_RELEASE}")
32
-    set (MACOSX_BUNDLE_BUNDLE_VERSION "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}-${OpenRaider_VERSION_RELEASE}")
30
+    set (MACOSX_BUNDLE_SHORT_VERSION_STRING "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}${OpenRaider_VERSION_RELEASE}")
31
+    set (MACOSX_BUNDLE_LONG_VERSION_STRING "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}${OpenRaider_VERSION_RELEASE} (${CMAKE_BUILD_TYPE})")
32
+    set (MACOSX_BUNDLE_BUNDLE_VERSION "${OpenRaider_VERSION_MAJOR}.${OpenRaider_VERSION_MINOR}.${OpenRaider_VERSION_MICRO}${OpenRaider_VERSION_RELEASE} (${CMAKE_BUILD_TYPE})")
33
     set (MACOSX_BUNDLE_COPYRIGHT "2001 - 2014")
33
     set (MACOSX_BUNDLE_COPYRIGHT "2001 - 2014")
34
 
34
 
35
     # Copy Icon
35
     # Copy Icon

+ 8
- 0
src/OpenRaider.cpp View File

2762
     {
2762
     {
2763
         m_mouseY = static_cast<float>(atof(cmd));
2763
         m_mouseY = static_cast<float>(atof(cmd));
2764
     }
2764
     }
2765
+    else if (rc_command("texture", cmd))
2766
+    {
2767
+        int error, tex = atoi(cmd);
2768
+        if ((error = m_render.showTextureDebug(tex)) < 0)
2769
+            print(false, "Could not load texture %d (%d)!", tex, error);
2770
+        else
2771
+            print(false, "Displaying texture %d in %d...", tex, error);
2772
+    }
2765
     else if (rc_command("r_pigtails", cmd))
2773
     else if (rc_command("r_pigtails", cmd))
2766
     {
2774
     {
2767
         if (gLaraModel)
2775
         if (gLaraModel)

+ 7
- 0
src/Render.cpp View File

161
 // Public Mutators
161
 // Public Mutators
162
 ////////////////////////////////////////////////////////////
162
 ////////////////////////////////////////////////////////////
163
 
163
 
164
+
165
+int Render::showTextureDebug(int textureId) {
166
+    return mTexture.showTextureDebug(textureId);
167
+}
168
+
169
+
164
 void Render::addRoom(RenderRoom *room)
170
 void Render::addRoom(RenderRoom *room)
165
 {
171
 {
166
     mRooms.pushBack(room);
172
     mRooms.pushBack(room);
959
     glEnterMode2d(mWidth, mHeight);
965
     glEnterMode2d(mWidth, mHeight);
960
     glColor3fv(OR_BLUE);
966
     glColor3fv(OR_BLUE);
961
     mString.Render();
967
     mString.Render();
968
+    mTexture.debugTextureRender(mWidth, mHeight);
962
     glExitMode2d();
969
     glExitMode2d();
963
 
970
 
964
 #ifdef USING_EMITTER
971
 #ifdef USING_EMITTER

+ 45
- 10
src/Texture.cpp View File

44
     //gTextureManager = this;
44
     //gTextureManager = this;
45
 
45
 
46
     initSDL_TTF();
46
     initSDL_TTF();
47
+
48
+    textureDebug = -1;
47
 }
49
 }
48
 
50
 
49
 
51
 
210
 }
212
 }
211
 
213
 
212
 
214
 
215
+int Texture::showTextureDebug(int textureId) {
216
+    if (textureId >= getTextureCount())
217
+        return -1;
218
+
219
+    textureDebug = textureId;
220
+    textureDebugFrames = 100;
221
+
222
+    return mTextureIds[textureId];
223
+}
224
+
225
+
226
+void Texture::debugTextureRender(int width, int height) {
227
+    int xMin, xMax, yMin, yMax;
228
+
229
+    xMin = yMin = 0;
230
+    xMax = width;
231
+    yMax = height;
232
+
233
+    if ((textureDebug >= 0) && (textureDebugFrames > 0)) {
234
+        glColor3f(1, 1, 1);
235
+        bindTextureId(textureDebug);
236
+
237
+        // Draw a textured quad
238
+        glBegin(GL_QUADS);
239
+        glTexCoord2f(0, 0); glVertex3f(xMin, yMin, 0);
240
+        glTexCoord2f(0, 1); glVertex3f(xMin, yMax, 0);
241
+        glTexCoord2f(1, 1); glVertex3f(xMax, yMax, 0);
242
+        glTexCoord2f(1, 0); glVertex3f(xMax, yMin, 0);
243
+
244
+        glEnd();
245
+
246
+        textureDebugFrames--;
247
+    }
248
+}
249
+
250
+
213
 int Texture::loadFontTTF(const char *filename,
251
 int Texture::loadFontTTF(const char *filename,
214
         unsigned int utf8Offset, unsigned int count)
252
         unsigned int utf8Offset, unsigned int count)
215
 {
253
 {
653
     }
691
     }
654
 }
692
 }
655
 
693
 
656
-GLint deprecated_gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data);
694
+// http://mmmovania.blogspot.de/2011/01/opengl-30-and-above-deprecated-func-and.html
695
+// http://www.g-truc.net/post-0256.html
696
+GLint deprecated_gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data) {
697
+    glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE);
698
+    glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, data);
699
+    return 0;
700
+}
657
 
701
 
658
 int Texture::loadBufferSlot(unsigned char *image,
702
 int Texture::loadBufferSlot(unsigned char *image,
659
         unsigned int width, unsigned int height,
703
         unsigned int width, unsigned int height,
758
 }
802
 }
759
 
803
 
760
 
804
 
761
-// http://mmmovania.blogspot.de/2011/01/opengl-30-and-above-deprecated-func-and.html
762
-// http://www.g-truc.net/post-0256.html
763
-GLint deprecated_gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *data) {
764
-    glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE);
765
-    glTexImage2D(target, 0, internalFormat, width, height, 0, format, type, data);
766
-    return 0;
767
-}
768
-
769
-
770
 void Texture::bindTextureId(unsigned int n)
805
 void Texture::bindTextureId(unsigned int n)
771
 {
806
 {
772
     if ((int)n == mTextureId || !mTextureIds || n > mTextureCount)
807
     if ((int)n == mTextureId || !mTextureIds || n > mTextureCount)

Loading…
Cancel
Save