diff --git a/changelog.txt b/changelog.txt index 17b0c19..d955323 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,11 +1,12 @@ ZEngine Version Log for Version 0.7.8 -$Id: changelog.txt,v 1.5 2002/12/02 00:42:20 cozman Exp $ +$Id: changelog.txt,v 1.6 2002/12/02 05:18:52 cozman Exp $ 0.7.8 -Added ZRect::Draw using OpenGL. -Fixed ZRectTest to use new ZRect. -Added ZImage rotation and 2 forms of stretching using OpenGL. -Added some testing to ZImageTest of new stretching. + -Added ZImage::Flip. 0.7.7 -Changed behavior of core ZEngine class methods to reflect new OpenGL behavior. diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h index e93bcb9..19f74a7 100644 --- a/include/ZE_ZImage.h +++ b/include/ZE_ZImage.h @@ -13,7 +13,7 @@ File: ZE_ZImage.h
Description: Header file for core ZEngine Image and Texture Object.
Author(s): James Turk, Gamer Tazar
-$Id: ZE_ZImage.h,v 1.3 2002/12/02 00:36:35 cozman Exp $
+$Id: ZE_ZImage.h,v 1.4 2002/12/02 05:18:52 cozman Exp $
\file ZE_ZImage.h \brief Definition file for ZImage. @@ -37,6 +37,10 @@ namespace ZE class ZImage : public ZObject { protected: + //! Texture lower X, used internally for flip. + GLfloat rTexMinX; + //! Texture lower Y, used internally for flip + GLfloat rTexMinY; //! Texture X width ratio, used internally by OpenGL. GLfloat rTexMaxX; //! Texture Y width ratio, used internally by OpenGL. @@ -149,6 +153,15 @@ class ZImage : public ZObject **/ void SetColorKey(Uint8 red, Uint8 green, Uint8 blue); + /*! + \brief Flip image over one or both axes. + + Flip image vertical and/or horizontal. + \param horizontal Boolean, true will flip image horizontally. + \param vertical Boolean, true will flip image vertically. + **/ + void Flip(bool horizontal, bool vertical); + /*! \brief Stretch the image by a certain X and Y factor. diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp index 0ba382c..b632d67 100644 --- a/src/ZE_ZImage.cpp +++ b/src/ZE_ZImage.cpp @@ -13,7 +13,7 @@ File: ZE_ZImage.cpp
Description: Implementation source file for core ZEngine Image or Texture Object.
Author(s): James Turk, Gamer Tazar
-$Id: ZE_ZImage.cpp,v 1.4 2002/12/02 00:36:35 cozman Exp $
+$Id: ZE_ZImage.cpp,v 1.5 2002/12/02 05:18:52 cozman Exp $
\file ZE_ZImage.cpp \brief Source file for ZImage. @@ -98,13 +98,14 @@ void ZImage::Attach(SDL_Surface *surface) { GLfloat coord[4]; - //Release(); if(surface) { rWidth = surface->w; rHeight = surface->h; rTexID = SDL_GL_LoadTexture(surface,coord); - rTexMaxX = coord[2]; //ignore first coords because they are always 0.0f + rTexMinX = coord[0]; + rTexMinY = coord[1]; + rTexMaxX = coord[2]; rTexMaxY = coord[3]; rImage = surface; } @@ -116,7 +117,7 @@ void ZImage::Release() { if(glIsTexture(rTexID)) glDeleteTextures(1,&rTexID); - rTexMaxX = rTexMaxY = 0.0f; + rTexMinX = rTexMinY = rTexMaxX = rTexMaxY = 0.0f; rTexID = rWidth = rHeight = 0; FreeImage(rImage); } @@ -151,6 +152,23 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) LogError("ZImage not initialized in ZImage::SetColorKey."); } +void ZImage::Flip(bool horizontal, bool vertical) +{ + GLfloat temp; + if(horizontal) + { + temp = rTexMinX; + rTexMinX = rTexMaxX; + rTexMaxX = temp; + } + if(vertical) + { + temp = rTexMinY; + rTexMinY = rTexMaxY; + rTexMaxY = temp; + } +} + void ZImage::Stretch(float xFactor, float yFactor) { rWidth = static_cast(xFactor*rWidth); @@ -173,10 +191,10 @@ void ZImage::Draw(float x, float y) Bind(); glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(0.0f,0.0f); glVertex2f(x, y); - glTexCoord2f(rTexMaxX,0.0f); glVertex2f(x+rWidth, y); - glTexCoord2f(0.0f,rTexMaxY); glVertex2f(x, y+rHeight); - glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth, y+rHeight); + glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(x,y); + glTexCoord2f(rTexMaxX,rTexMinY); glVertex2f(x+rWidth,y); + glTexCoord2f(rTexMinX,rTexMaxY); glVertex2f(x,y+rHeight); + glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth,y+rHeight); glEnd(); }