ZImage::Flip

This commit is contained in:
James Turk 2002-12-02 05:18:52 +00:00
parent 6078830a56
commit 8447c8d43a
3 changed files with 42 additions and 10 deletions

View File

@ -1,11 +1,12 @@
ZEngine Version Log for Version 0.7.8 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 0.7.8
-Added ZRect::Draw using OpenGL. -Added ZRect::Draw using OpenGL.
-Fixed ZRectTest to use new ZRect. -Fixed ZRectTest to use new ZRect.
-Added ZImage rotation and 2 forms of stretching using OpenGL. -Added ZImage rotation and 2 forms of stretching using OpenGL.
-Added some testing to ZImageTest of new stretching. -Added some testing to ZImageTest of new stretching.
-Added ZImage::Flip.
0.7.7 0.7.7
-Changed behavior of core ZEngine class methods to reflect new OpenGL behavior. -Changed behavior of core ZEngine class methods to reflect new OpenGL behavior.

View File

@ -13,7 +13,7 @@
File: ZE_ZImage.h <br> File: ZE_ZImage.h <br>
Description: Header file for core ZEngine Image and Texture Object. <br> Description: Header file for core ZEngine Image and Texture Object. <br>
Author(s): James Turk, Gamer Tazar <br> Author(s): James Turk, Gamer Tazar <br>
$Id: ZE_ZImage.h,v 1.3 2002/12/02 00:36:35 cozman Exp $<br> $Id: ZE_ZImage.h,v 1.4 2002/12/02 05:18:52 cozman Exp $<br>
\file ZE_ZImage.h \file ZE_ZImage.h
\brief Definition file for ZImage. \brief Definition file for ZImage.
@ -37,6 +37,10 @@ namespace ZE
class ZImage : public ZObject class ZImage : public ZObject
{ {
protected: 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. //! Texture X width ratio, used internally by OpenGL.
GLfloat rTexMaxX; GLfloat rTexMaxX;
//! Texture Y width ratio, used internally by OpenGL. //! Texture Y width ratio, used internally by OpenGL.
@ -149,6 +153,15 @@ class ZImage : public ZObject
**/ **/
void SetColorKey(Uint8 red, Uint8 green, Uint8 blue); 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. \brief Stretch the image by a certain X and Y factor.

View File

@ -13,7 +13,7 @@
File: ZE_ZImage.cpp <br> File: ZE_ZImage.cpp <br>
Description: Implementation source file for core ZEngine Image or Texture Object. <br> Description: Implementation source file for core ZEngine Image or Texture Object. <br>
Author(s): James Turk, Gamer Tazar <br> Author(s): James Turk, Gamer Tazar <br>
$Id: ZE_ZImage.cpp,v 1.4 2002/12/02 00:36:35 cozman Exp $<br> $Id: ZE_ZImage.cpp,v 1.5 2002/12/02 05:18:52 cozman Exp $<br>
\file ZE_ZImage.cpp \file ZE_ZImage.cpp
\brief Source file for ZImage. \brief Source file for ZImage.
@ -98,13 +98,14 @@ void ZImage::Attach(SDL_Surface *surface)
{ {
GLfloat coord[4]; GLfloat coord[4];
//Release();
if(surface) if(surface)
{ {
rWidth = surface->w; rWidth = surface->w;
rHeight = surface->h; rHeight = surface->h;
rTexID = SDL_GL_LoadTexture(surface,coord); 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]; rTexMaxY = coord[3];
rImage = surface; rImage = surface;
} }
@ -116,7 +117,7 @@ void ZImage::Release()
{ {
if(glIsTexture(rTexID)) if(glIsTexture(rTexID))
glDeleteTextures(1,&rTexID); glDeleteTextures(1,&rTexID);
rTexMaxX = rTexMaxY = 0.0f; rTexMinX = rTexMinY = rTexMaxX = rTexMaxY = 0.0f;
rTexID = rWidth = rHeight = 0; rTexID = rWidth = rHeight = 0;
FreeImage(rImage); FreeImage(rImage);
} }
@ -151,6 +152,23 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
LogError("ZImage not initialized in ZImage::SetColorKey."); 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) void ZImage::Stretch(float xFactor, float yFactor)
{ {
rWidth = static_cast<unsigned int>(xFactor*rWidth); rWidth = static_cast<unsigned int>(xFactor*rWidth);
@ -173,10 +191,10 @@ void ZImage::Draw(float x, float y)
Bind(); Bind();
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0f,0.0f); glVertex2f(x, y); glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(x,y);
glTexCoord2f(rTexMaxX,0.0f); glVertex2f(x+rWidth, y); glTexCoord2f(rTexMaxX,rTexMinY); glVertex2f(x+rWidth,y);
glTexCoord2f(0.0f,rTexMaxY); glVertex2f(x, y+rHeight); glTexCoord2f(rTexMinX,rTexMaxY); glVertex2f(x,y+rHeight);
glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth, y+rHeight); glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth,y+rHeight);
glEnd(); glEnd();
} }