diff --git a/changelog.txt b/changelog.txt
index 8003410..4ce608f 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,5 +1,5 @@
-ZEngine Version Log for Version 0.8.4
-$Id: changelog.txt,v 1.43 2003/08/31 22:15:00 cozman Exp $
+ZEngine Version Log for Version 0.8.5
+$Id: changelog.txt,v 1.44 2003/09/05 19:44:13 cozman Exp $
Changes are marked with symbols that describe them:
! is code that breaks backwards compatibility (used after 0.8.0-rc1, previous versions broke compatibility)
@@ -9,9 +9,11 @@ Changes are marked with symbols that describe them:
# general changes
0.8.5
- + Addition of limited SDL graphics backend.
+ + Addition of DrawClipped and DrawClipped example in ZImageTest
+ + New limited SDL graphics backend for platforms without OpenGL.
- Removal of VC6 project files and official support.
- Removal of SDL_net support.
+ # Tiny optimizations within newer ZImage code.
# Changed ZImage stretching to floating-point.
# New linux build system (by Atani).
diff --git a/include/ZE_Defines.h b/include/ZE_Defines.h
index 0f73746..1ba85c6 100644
--- a/include/ZE_Defines.h
+++ b/include/ZE_Defines.h
@@ -13,7 +13,7 @@
\brief Define file for ZEngine where all #define statements to control compilation options are placed.
Definition file, holds #define statements describing optional features of ZEngine.
-
$Id: ZE_Defines.h,v 1.22 2003/08/08 04:24:42 cozman Exp $
+
$Id: ZE_Defines.h,v 1.23 2003/09/05 19:44:13 cozman Exp $
\author James Turk
**/
@@ -22,7 +22,6 @@
//Defines- undefine any of these if you dont have the indicated SDL extension//
-
//! OpenGL 2D Rendering Target.
#define ZE_OGL (1)
//! SDL Rendering Target.
diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h
index f87c5df..a003add 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 OpenGL version of the ZImage class for ZEngine.
-
$Id: ZE_ZImage.h,v 1.24 2003/09/01 03:30:39 cozman Exp $
+
$Id: ZE_ZImage.h,v 1.25 2003/09/05 19:44:13 cozman Exp $
\author James Turk
**/
@@ -216,9 +216,11 @@ class ZImage
void Draw(int x, int y) const;
/*!
- \brief Draw Clipped Image to screen.
+ \brief Draw Image, clipped within a given rectangle to the screen.
- Image is drawn such that only portions of image which fall within a certain area appear.
+ Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle
+ can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a
+ map on a HUD.
\since 0.8.5
\param x X coord to draw Image to.
\param y Y coord to draw Image to.
@@ -259,9 +261,11 @@ class ZImage
void DrawRotated(float x, float y, float angle) const;
/*!
- \brief Draw Clipped Image to screen.
+ \brief Draw Image, clipped within a given rectangle to the screen.
- Image is drawn such that only portions of image which fall within a certain area appear.
+ Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle
+ can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a
+ map on a HUD.
\since 0.8.5
\param x X coord to draw Image to.
\param y Y coord to draw Image to.
diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp
index c186766..664c7e8 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.44 2003/09/01 06:01:34 cozman Exp $
+
$Id: ZE_ZImage.cpp,v 1.45 2003/09/05 19:44:13 cozman Exp $
\author James Turk
**/
@@ -244,10 +244,7 @@ void ZImage::DrawRotated(float x, float y, float angle) const
void ZImage::DrawClipped(float x, float y, ZRect clipRect) const
{
- ZRect imgRect(x,y,rWidth,rHeight),inRect;
- float xDiff,yDiff,nx,ny,nw,nh;
- xDiff = rTexMaxX - rTexMinX;
- yDiff = rTexMaxY - rTexMinY;
+ ZRect imgRect(x,y,rWidth,rHeight);
if(clipRect.Contains(imgRect))
{
@@ -255,20 +252,30 @@ void ZImage::DrawClipped(float x, float y, ZRect clipRect) const
}
else if(clipRect.Intersects(imgRect))
{
- inRect = clipRect.Intersection(imgRect);
+ //This is some pretty complex code, it is broken down in 4 steps.
- nx = rTexMinX + (inRect.X()-imgRect.X())/imgRect.Width()*xDiff;
- ny = rTexMinY + (inRect.Y()-imgRect.Y())/imgRect.Height()*yDiff;
- nw = nx + (inRect.Width()/imgRect.Width())*xDiff;
- nh = ny + (inRect.Height()/imgRect.Height())*yDiff;
+ //Step 1: The intersection rectangle (inRect) is compared to the image rectangle and the overlapping area is found.
+ ZRect inRect = clipRect.Intersection(imgRect);
- glColor4ub(255,255,255,rAlpha); //sets the color correctly
+ //Step 2: The portion of the image that needs to be drawn is being mapped to triangle strips the same size as the intersection
+ // of the clipping and image rectangles and then transformed to texture coordinates via xScale and yScale.
+ // (double is used for needed precision when dealing with the scaling)
+ double xScale = (rTexMaxX - rTexMinX)*rWidth; //texCoordWidth/imgWidth
+ double yScale = (rTexMaxY - rTexMinY)*rHeight; //texCoordHeight/imgHeight
+ double nx = rTexMinX + (inRect.X()-x)/xScale; //cut off left side
+ double ny = rTexMinY + (inRect.Y()-y)/yScale; //cut off top
+ double nw = nx + inRect.Width()/xScale; //cut off right side
+ double nh = ny + inRect.Height()/yScale; //cut off bottom
+
+ glColor4ub(255,255,255,rAlpha);
Bind();
glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2f(nx,ny); glVertex2f(inRect.Left(),inRect.Top());
- glTexCoord2f(nw,ny); glVertex2f(inRect.Right(),inRect.Top());
- glTexCoord2f(nx,nh); glVertex2f(inRect.Left(),inRect.Bottom());
- glTexCoord2f(nw,nh); glVertex2f(inRect.Right(),inRect.Bottom());
+ //Step 3: The texture coords are modified to only specify the portion of the texture which falls within the clipping rect.
+ //Step 4: The vertices are changed to the sides of the clipping rectangle in glVertex2f.
+ glTexCoord2d(nx,ny); glVertex2f(inRect.Left(),inRect.Top());
+ glTexCoord2d(nw,ny); glVertex2f(inRect.Right(),inRect.Top());
+ glTexCoord2d(nx,nh); glVertex2f(inRect.Left(),inRect.Bottom());
+ glTexCoord2d(nw,nh); glVertex2f(inRect.Right(),inRect.Bottom());
glEnd();
glColor4ub(255,255,255,255); //be responsible, return to standard color state
}
@@ -280,21 +287,11 @@ void ZImage::DrawClipped(float x, float y, ZRect clipRect) const
void ZImage::Flip(bool horizontal, bool vertical)
{
- GLfloat temp;
//all that a flip does is invert the Min/Max coordinates
if(horizontal)
- {
- temp = rTexMinX;
- rTexMinX = rTexMaxX;
- rTexMaxX = temp;
- }
-
+ std::swap(rTexMinX,rTexMaxX);
if(vertical)
- {
- temp = rTexMinY;
- rTexMinY = rTexMaxY;
- rTexMaxY = temp;
- }
+ std::swap(rTexMinY,rTexMaxY);
}
//stretching and resizing is very inexpensive, done via variables
diff --git a/test/ZImageTest.cpp b/test/ZImageTest.cpp
index bf03774..ab8451b 100644
--- a/test/ZImageTest.cpp
+++ b/test/ZImageTest.cpp
@@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
-/*$Id: ZImageTest.cpp,v 1.22 2003/09/01 06:01:06 cozman Exp $*/
+/*$Id: ZImageTest.cpp,v 1.23 2003/09/05 19:44:13 cozman Exp $*/
#include
#include
@@ -55,12 +55,13 @@ void Test()
image1.Attach(temp); //this attaches the surface into itself
image2.Open("data/test01.bmp");
image3.OpenFromImage(image2.Surface(),5,5,20,20);
- image4.Open("data/rainbow.bmp");
+ image4.Open("data/test02.bmp");
temp = NULL; //and temp will now be controlled and freed by image1
image1.SetColorKey(255,0,255);
image2.SetColorKey(255,0,255);
#if (GFX_BACKEND == ZE_OGL)
image4.Resize(400,300);
+ image4.Flip(true,false);
#endif
font.DrawShadedText("ZImage Test.",textImage);