addition of 'vc' shaded vertex overloads for the draws

This commit is contained in:
James Turk 2003-09-07 20:59:20 +00:00
parent 2e0ee12b48
commit 7f71704b67
3 changed files with 124 additions and 3 deletions

View File

@ -1,5 +1,5 @@
ZEngine Version Log for Version 0.8.5 ZEngine Version Log for Version 0.8.5
$Id: changelog.txt,v 1.45 2003/09/07 18:28:01 cozman Exp $ $Id: changelog.txt,v 1.46 2003/09/07 20:59:20 cozman Exp $
Changes are marked with symbols that describe them: Changes are marked with symbols that describe them:
! is code that breaks backwards compatibility (used after 0.8.0-rc1, previous versions broke compatibility) ! is code that breaks backwards compatibility (used after 0.8.0-rc1, previous versions broke compatibility)
@ -8,7 +8,10 @@ Changes are marked with symbols that describe them:
- removed features - removed features
# general changes # general changes
(Note: Depreciated code (that marked with a *) is likely to disappear completely at the next major version.)
0.8.5 0.8.5
+ New Draw,DrawRotated, and DrawClipped overloads with vertex coloring parameter for advanced needs.
+ Addition of Dev-C++ project files and more Dev-C++ support. + Addition of Dev-C++ project files and more Dev-C++ support.
+ Addition of DrawClipped and DrawClipped example in ZImageTest + Addition of DrawClipped and DrawClipped example in ZImageTest
+ New limited SDL graphics backend for platforms without OpenGL. + New limited SDL graphics backend for platforms without OpenGL.

View File

@ -13,7 +13,7 @@
\brief Definition file for ZImage. \brief Definition file for ZImage.
Definition file for ZImage, the OpenGL version of the ZImage class for ZEngine. Definition file for ZImage, the OpenGL version of the ZImage class for ZEngine.
<br>$Id: ZE_ZImage.h,v 1.25 2003/09/05 19:44:13 cozman Exp $<br> <br>$Id: ZE_ZImage.h,v 1.26 2003/09/07 20:59:20 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -239,6 +239,19 @@ class ZImage
**/ **/
void Draw(float x, float y) const; void Draw(float x, float y) const;
/*!
\brief Draw Image to screen with shaded/colored vertices.
Draw Image to screen using OpenGL to shade and color vertices.
\since 0.8.5
\param x X coord to draw Image to.
\param y Y coord to draw Image to.
\param vc Uint8 vcolor[16] - Vertex colors for the four vertices.
Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively)
of top left corner (after top-left corner goes around clockwise).
**/
void Draw(float x, float y, Uint8 vc[]) const;
/*! /*!
\brief Draw Image rotated to screen. \brief Draw Image rotated to screen.
@ -260,6 +273,20 @@ class ZImage
**/ **/
void DrawRotated(float x, float y, float angle) const; void DrawRotated(float x, float y, float angle) const;
/*!
\brief Draw Image rotated to screen with shaded/colored vertices.
Image is rotated about it's own center by specified angle, then drawn to screen with shaded or colored vertices.
\since 0.8.5
\param x X coord to draw Image to.
\param y Y coord to draw Image to.
\param angle Angle in degrees to rotate image.
\param vc Uint8 vcolor[16] - Vertex colors for the four vertices.
Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively)
of top left corner (after top-left corner goes around clockwise).
**/
void DrawRotated(float x, float y, float angle, Uint8 vc[]) const;
/*! /*!
\brief Draw Image, clipped within a given rectangle to the screen. \brief Draw Image, clipped within a given rectangle to the screen.
@ -273,6 +300,22 @@ class ZImage
**/ **/
void DrawClipped(float x, float y, ZRect clipRect) const; void DrawClipped(float x, float y, ZRect clipRect) const;
/*!
\brief Draw Image, clipped within a given rectangle to the screen with colored/shaded vertices.
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. Image is drawn with colored/shaded vertices.
\since 0.8.5
\param x X coord to draw Image to.
\param y Y coord to draw Image to.
\param clipRect Rectangle to clip within.
\param vc Uint8 vcolor[16] - Vertex colors for the four vertices.
Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively)
of top left corner (after top-left corner goes around clockwise).
**/
void DrawClipped(float x, float y, ZRect clipRect, Uint8 vc[]) const;
/*! /*!
\brief Flip image over one or both axes. \brief Flip image over one or both axes.

View File

@ -13,7 +13,7 @@
\brief Source file for ZImage. \brief Source file for ZImage.
Implementation of ZImage, the Image class for ZEngine. Implementation of ZImage, the Image class for ZEngine.
<br>$Id: ZE_ZImage.cpp,v 1.45 2003/09/05 19:44:13 cozman Exp $<br> <br>$Id: ZE_ZImage.cpp,v 1.46 2003/09/07 20:59:20 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -215,6 +215,18 @@ void ZImage::Draw(float x, float y) const
glColor4ub(255,255,255,255); //be responsible, return to standard color state glColor4ub(255,255,255,255); //be responsible, return to standard color state
} }
void ZImage::Draw(float x, float y, Uint8 vc[]) const
{
Bind();
glBegin(GL_TRIANGLE_STRIP); //triangle strips, speedier?
glTexCoord2f(rTexMinX,rTexMinY); glColor4ub(vc[0],vc[1],vc[2],vc[3]); glVertex2f(x,y);
glTexCoord2f(rTexMaxX,rTexMinY); glColor4ub(vc[4],vc[5],vc[6],vc[7]); glVertex2f(x+rWidth,y);
glTexCoord2f(rTexMinX,rTexMaxY); glColor4ub(vc[12],vc[13],vc[14],vc[15]); glVertex2f(x,y+rHeight); //12-15 here to keep counterclockwise
glTexCoord2f(rTexMaxX,rTexMaxY); glColor4ub(vc[8],vc[9],vc[10],vc[11]); glVertex2f(x+rWidth,y+rHeight);
glEnd();
glColor4ub(255,255,255,255); //be responsible, return to standard color state
}
void ZImage::DrawRotated(int x, int y, float angle) const void ZImage::DrawRotated(int x, int y, float angle) const
{ {
DrawRotated(static_cast<float>(x),static_cast<float>(y),angle); DrawRotated(static_cast<float>(x),static_cast<float>(y),angle);
@ -242,6 +254,27 @@ void ZImage::DrawRotated(float x, float y, float angle) const
glPopMatrix(); glPopMatrix();
} }
void ZImage::DrawRotated(float x, float y, float angle, Uint8 vc[]) const
{
//center point
float cX,cY;
cX = rWidth/2.0f;
cY = rHeight/2.0f;
glPushMatrix();
glTranslatef(x+cX,y+cY,0); //translate to center
glRotatef(angle,0,0,1.0f); //rotate on z axis, to keep x&y parallel to 2D plane
Bind();
//draw is modified to be based around center//
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(rTexMinX,rTexMinY); glColor4ub(vc[0],vc[1],vc[2],vc[3]); glVertex2f(-cX,-cY);
glTexCoord2f(rTexMaxX,rTexMinY); glColor4ub(vc[4],vc[6],vc[6],vc[7]); glVertex2f(-cX+rWidth,-cY);
glTexCoord2f(rTexMinX,rTexMaxY); glColor4ub(vc[12],vc[13],vc[14],vc[15]); glVertex2f(-cX,-cY+rHeight);
glTexCoord2f(rTexMaxX,rTexMaxY); glColor4ub(vc[8],vc[9],vc[10],vc[11]); glVertex2f(-cX+rWidth,-cY+rHeight);
glEnd();
glPopMatrix();
}
void ZImage::DrawClipped(float x, float y, ZRect clipRect) const void ZImage::DrawClipped(float x, float y, ZRect clipRect) const
{ {
ZRect imgRect(x,y,rWidth,rHeight); ZRect imgRect(x,y,rWidth,rHeight);
@ -285,6 +318,48 @@ void ZImage::DrawClipped(float x, float y, ZRect clipRect) const
} }
} }
void ZImage::DrawClipped(float x, float y, ZRect clipRect, Uint8 vc[]) const
{
ZRect imgRect(x,y,rWidth,rHeight);
if(clipRect.Contains(imgRect))
{
Draw(x,y);
}
else if(clipRect.Intersects(imgRect))
{
//This is some pretty complex code, it is broken down in 4 steps.
//Step 1: The intersection rectangle (inRect) is compared to the image rectangle and the overlapping area is found.
ZRect inRect = clipRect.Intersection(imgRect);
//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
Bind();
glBegin(GL_TRIANGLE_STRIP);
//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); glColor4ub(vc[0],vc[1],vc[2],vc[3]); glVertex2f(inRect.Left(),inRect.Top());
glTexCoord2d(nw,ny); glColor4ub(vc[4],vc[5],vc[6],vc[7]); glVertex2f(inRect.Right(),inRect.Top());
glTexCoord2d(nx,nh); glColor4ub(vc[12],vc[13],vc[14],vc[15]); glVertex2f(inRect.Left(),inRect.Bottom());
glTexCoord2d(nw,nh); glColor4ub(vc[8],vc[9],vc[10],vc[11]); glVertex2f(inRect.Right(),inRect.Bottom());
glEnd();
glColor4ub(255,255,255,255); //be responsible, return to standard color state
}
else //doesn't contain nor intersect
{
//draw nothing
}
}
void ZImage::Flip(bool horizontal, bool vertical) void ZImage::Flip(bool horizontal, bool vertical)
{ {
//all that a flip does is invert the Min/Max coordinates //all that a flip does is invert the Min/Max coordinates