diff --git a/include/ZE_Utility.h b/include/ZE_Utility.h
index e2178c3..c0a388b 100755
--- a/include/ZE_Utility.h
+++ b/include/ZE_Utility.h
@@ -14,7 +14,7 @@
Definition file for ZEngine Utilities which are used throughout the engine and can be used in
conjunction with ZEngine.
-
$Id: ZE_Utility.h,v 1.8 2003/10/13 21:40:05 cozman Exp $
+
$Id: ZE_Utility.h,v 1.9 2003/10/13 21:48:12 cozman Exp $
\author James Turk
**/
@@ -51,31 +51,6 @@ std::string FormatStr(const char *fmtstr, ...);
**/
SDL_RWops* RWFromZip(std::string zipname, std::string filename);
-/*!
- \brief Rounds a number up to the nearest power of two.
-
- Rounds a number up to the next highest power of two, used for OpenGL textures. (From testgl.c)
- Used internally, generally shouldn't be called by users.
- \param in Number to round up.
- \return num rounded up to closest power of two.
- \since 0.8.6
-**/
-int PowerOfTwo(int num);
-
-/*!
- \brief Converts an SDL_Surface to an OpenGL texture ID.
-
- Given an SDL_Surface returns a texture ID representing the OpenGL
- texture assigned to that surface. Also returns texture coordinates
- via texcoord parameter. (From SDL_GL_LoadTexture in testgl.c)
- Used internally, generally shouldn't be called by users.
- \param surface SDL_Surface to assign an OpenGL ID, returns unmodified.
- \param texcoord Should be an array of 4 GLfloat, assigned texture coordinates for OpenGL use.
- \return OpenGL texture ID for SDL_Surface, 0 if an error occurs.
- \since 0.8.6
-**/
-GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord);
-
/*!
\brief Properly free SDL_Surface.
diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h
index 67b2251..361186e 100644
--- a/include/ZE_ZImage.h
+++ b/include/ZE_ZImage.h
@@ -13,7 +13,7 @@
\brief Definition file for ZImage.
Definition file for ZImage, the ZImage class for ZEngine.
-
$Id: ZE_ZImage.h,v 1.27 2003/09/24 01:49:52 cozman Exp $
+
$Id: ZE_ZImage.h,v 1.28 2003/10/13 21:48:13 cozman Exp $
\author James Turk
**/
@@ -55,6 +55,31 @@ class ZImage
GLfloat rWidth;
//! Current draw height of Texture.
GLfloat rHeight;
+
+ /*!
+ \brief Rounds a number up to the nearest power of two.
+
+ Rounds a number up to the next highest power of two, used for OpenGL textures. (From testgl.c)
+ Used internally, generally shouldn't be called by users.
+ \param in Number to round up.
+ \return num rounded up to closest power of two.
+ \since 0.8.6
+ **/
+ int PowerOfTwo(int num);
+
+ /*!
+ \brief Converts an SDL_Surface to an OpenGL texture ID.
+
+ Given an SDL_Surface returns a texture ID representing the OpenGL
+ texture assigned to that surface. Also returns texture coordinates
+ via texcoord parameter. (From SDL_GL_LoadTexture in testgl.c)
+ Used internally, generally shouldn't be called by users.
+ \param surface SDL_Surface to assign an OpenGL ID, returns unmodified.
+ \param texcoord Should be an array of 4 GLfloat, assigned texture coordinates for OpenGL use.
+ \return OpenGL texture ID for SDL_Surface, 0 if an error occurs.
+ \since 0.8.6
+ **/
+ GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord);
#endif //GFX_BACKEND == OGL
public:
diff --git a/src/ZE_Utility.cpp b/src/ZE_Utility.cpp
index 3d0fa37..2d61dc6 100755
--- a/src/ZE_Utility.cpp
+++ b/src/ZE_Utility.cpp
@@ -13,7 +13,7 @@
\brief Source file for ZEngine utility functions.
Source file containing open utilities for use inside and alongside ZEngine.
-
$Id: ZE_Utility.cpp,v 1.12 2003/10/13 21:40:05 cozman Exp $
+
$Id: ZE_Utility.cpp,v 1.13 2003/10/13 21:48:13 cozman Exp $
\author James Turk
**/
@@ -75,82 +75,6 @@ SDL_RWops* RWFromZip(std::string zipname, std::string filename)
return SDL_RWFromMem(buffer, info.uncompressed_size); //return buffer in RW form
}
-//from SDL's testgl.c power_of_two
-int PowerOfTwo(int num)
-{
- int value = 1;
-
- while(value < num) //texture coord must be >= input
- value <<= 1; //value <<= 1 is the same as value *= 2
- return value;
-}
-
-//from SDL's testgl.c SDL_GL_LoadTexture
-GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord)
-{
- GLuint texture;
- int w, h;
- SDL_Surface *temp;
- SDL_Rect area;
- Uint32 saved_flags;
- Uint8 saved_alpha;
-
- //expand width and height to nearest powers of 2
- w = PowerOfTwo(surface->w);
- h = PowerOfTwo(surface->h);
- texcoord[0] = 0.0f; //min X
- texcoord[1] = 0.0f; //min Y
- texcoord[2] = (GLfloat)surface->w / w; //max X
- texcoord[3] = (GLfloat)surface->h / h; //max Y
-
- temp = SDL_CreateRGBSurface(
- SDL_SWSURFACE,
- w, h,
- 32,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN //endian specific color masks
- 0x000000FF,
- 0x0000FF00,
- 0x00FF0000,
- 0xFF000000
-#else
- 0xFF000000,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF
-#endif
- );
- if(!temp) //failure in CreateRGBSurface
- return 0;
-
- //save alpha
- saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
- saved_alpha = surface->format->alpha;
- if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
- SDL_SetAlpha(surface, 0, 0);
-
- //copy surface (do not alter passed surface to allow this function to be used in special situations)
- area.x = 0;
- area.y = 0;
- area.w = static_cast(surface->w);
- area.h = static_cast(surface->h);
- SDL_BlitSurface(surface, &area, temp, &area);
-
- //restore saved alpha
- if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
- SDL_SetAlpha(surface, saved_flags, saved_alpha);
-
- //create the OpenGL texture
- glGenTextures(1, &texture);
- //setup texture parmaters
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels);
- SDL_FreeSurface(temp); //temp surface no longer needed
-
- return texture;
-}
-
//Each of the Free*s safely frees & NULLs the pointer
void FreeImage(SDL_Surface *&image)
{
diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp
index 0888325..6ebf0ec 100644
--- a/src/ZE_ZImage.cpp
+++ b/src/ZE_ZImage.cpp
@@ -13,7 +13,7 @@
\brief Source file for ZImage.
Implementation of ZImage, the Image class for ZEngine.
-
$Id: ZE_ZImage.cpp,v 1.49 2003/10/13 21:40:05 cozman Exp $
+
$Id: ZE_ZImage.cpp,v 1.50 2003/10/13 21:48:13 cozman Exp $
\author James Turk
**/
@@ -22,6 +22,85 @@
namespace ZE
{
+#if (GFX_BACKEND == ZE_OGL)
+
+//from SDL's testgl.c power_of_two
+int ZImage::PowerOfTwo(int num)
+{
+ int value = 1;
+
+ while(value < num) //texture coord must be >= input
+ value <<= 1; //value <<= 1 is the same as value *= 2
+ return value;
+}
+
+//from SDL's testgl.c SDL_GL_LoadTexture
+GLuint ZImage::SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord)
+{
+ GLuint texture;
+ int w, h;
+ SDL_Surface *temp;
+ SDL_Rect area;
+ Uint32 saved_flags;
+ Uint8 saved_alpha;
+
+ //expand width and height to nearest powers of 2
+ w = PowerOfTwo(surface->w);
+ h = PowerOfTwo(surface->h);
+ texcoord[0] = 0.0f; //min X
+ texcoord[1] = 0.0f; //min Y
+ texcoord[2] = (GLfloat)surface->w / w; //max X
+ texcoord[3] = (GLfloat)surface->h / h; //max Y
+
+ temp = SDL_CreateRGBSurface(
+ SDL_SWSURFACE,
+ w, h,
+ 32,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN //endian specific color masks
+ 0x000000FF,
+ 0x0000FF00,
+ 0x00FF0000,
+ 0xFF000000
+#else
+ 0xFF000000,
+ 0x00FF0000,
+ 0x0000FF00,
+ 0x000000FF
+#endif
+ );
+ if(!temp) //failure in CreateRGBSurface
+ return 0;
+
+ //save alpha
+ saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+ saved_alpha = surface->format->alpha;
+ if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
+ SDL_SetAlpha(surface, 0, 0);
+
+ //copy surface (do not alter passed surface to allow this function to be used in special situations)
+ area.x = 0;
+ area.y = 0;
+ area.w = static_cast(surface->w);
+ area.h = static_cast(surface->h);
+ SDL_BlitSurface(surface, &area, temp, &area);
+
+ //restore saved alpha
+ if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
+ SDL_SetAlpha(surface, saved_flags, saved_alpha);
+
+ //create the OpenGL texture
+ glGenTextures(1, &texture);
+ //setup texture parmaters
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels);
+ SDL_FreeSurface(temp); //temp surface no longer needed
+
+ return texture;
+}
+#endif //GFX_BACKEND == ZE_OGL
+
ZImage::ZImage() :
rEngine(ZEngine::GetInstance()),
rImage(NULL),