added alpha
This commit is contained in:
parent
bd3a140858
commit
5a90ab3af0
@ -13,7 +13,7 @@
|
||||
File: ZE_ZImage.h <br>
|
||||
Description: Header file for core ZEngine Image and Texture Object. <br>
|
||||
Author(s): James Turk, Gamer Tazar <br>
|
||||
$Id: ZE_ZImage.h,v 1.10 2003/01/24 02:47:06 cozman Exp $<br>
|
||||
$Id: ZE_ZImage.h,v 1.11 2003/01/25 19:56:05 cozman Exp $<br>
|
||||
|
||||
\file ZE_ZImage.h
|
||||
\brief Definition file for ZImage.
|
||||
@ -53,6 +53,8 @@ class ZImage : public ZObject
|
||||
unsigned int rWidth;
|
||||
//! Current draw height of Texture.
|
||||
unsigned int rHeight;
|
||||
//! Stored alpha value for drawing texture.
|
||||
Uint8 rAlpha;
|
||||
|
||||
public:
|
||||
|
||||
@ -159,7 +161,16 @@ class ZImage : public ZObject
|
||||
////////////
|
||||
|
||||
/*!
|
||||
\brief Set Color Key (transparent color) of Image.
|
||||
\brief Set alpha value (translucency) of image.
|
||||
|
||||
Set translucency value 0-255 (0 is transparent, 255 = opaque).
|
||||
\since 0.8.2
|
||||
\param alpha Number 0-255 setting translucency for image.
|
||||
**/
|
||||
void SetAlpha(Uint8 alpha);
|
||||
|
||||
/*!
|
||||
\brief Set Color Key (transparent color) of image.
|
||||
|
||||
Set color which will not be drawn in image.
|
||||
\param red Red component of colorkey (0-255).
|
||||
@ -256,6 +267,15 @@ class ZImage : public ZObject
|
||||
\return Image Height.
|
||||
**/
|
||||
int Height() const;
|
||||
|
||||
/*!
|
||||
\brief Get Alpha component.
|
||||
|
||||
Get current alpha value of image.
|
||||
\since 0.8.2
|
||||
\return Image Alpha.
|
||||
**/
|
||||
Uint8 Alpha() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
File: ZE_ZImage.cpp <br>
|
||||
Description: Implementation source file for core ZEngine Image or Texture Object. <br>
|
||||
Author(s): James Turk, Gamer Tazar <br>
|
||||
$Id: ZE_ZImage.cpp,v 1.20 2003/01/24 10:27:42 cozman Exp $<br>
|
||||
$Id: ZE_ZImage.cpp,v 1.21 2003/01/25 19:56:05 cozman Exp $<br>
|
||||
|
||||
\file ZE_ZImage.cpp
|
||||
\brief Source file for ZImage.
|
||||
@ -29,30 +29,35 @@ namespace ZE
|
||||
ZImage::ZImage()
|
||||
{
|
||||
rImage = NULL;
|
||||
rAlpha = 255;
|
||||
Release();
|
||||
}
|
||||
|
||||
ZImage::ZImage(const ZImage &rhs)
|
||||
{
|
||||
rImage = NULL;
|
||||
rAlpha = rhs.Alpha();
|
||||
OpenFromImage(rhs.Surface(),0,0,(Sint16)rhs.Width(),(Sint16)rhs.Height());
|
||||
}
|
||||
|
||||
ZImage::ZImage(string filename)
|
||||
{
|
||||
rImage = NULL;
|
||||
rAlpha = 255;
|
||||
Open(filename);
|
||||
}
|
||||
|
||||
ZImage::ZImage(SDL_Surface *surface)
|
||||
{
|
||||
rImage = NULL;
|
||||
rAlpha = 255;
|
||||
Attach(surface);
|
||||
}
|
||||
|
||||
ZImage::ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h)
|
||||
{
|
||||
rImage = NULL;
|
||||
rAlpha = 255;
|
||||
OpenFromImage(img,x,y,w,h);
|
||||
}
|
||||
|
||||
@ -147,6 +152,11 @@ void ZImage::Release()
|
||||
FreeImage(rImage);
|
||||
}
|
||||
|
||||
void ZImage::SetAlpha(Uint8 alpha)
|
||||
{
|
||||
rAlpha = alpha;
|
||||
}
|
||||
|
||||
void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
SDL_Surface *temp=NULL;
|
||||
@ -201,7 +211,10 @@ void ZImage::Bind() const
|
||||
if(!rTexID)
|
||||
rEngine->ReportError(ZERR_NOIMAGE,"Bind");
|
||||
else
|
||||
{
|
||||
glColor4ub(255,255,255,rAlpha);
|
||||
glBindTexture(GL_TEXTURE_2D, rTexID);
|
||||
}
|
||||
}
|
||||
|
||||
void ZImage::Draw(float x, float y) const
|
||||
@ -213,6 +226,7 @@ void ZImage::Draw(float x, float y) const
|
||||
glTexCoord2f(rTexMinX,rTexMaxY); glVertex2f(x,y+rHeight);
|
||||
glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth,y+rHeight);
|
||||
glEnd();
|
||||
glColor4ub(255,255,255,255); //return to standard color state
|
||||
}
|
||||
|
||||
void ZImage::DrawRotated(int x, int y, float angle) const
|
||||
@ -255,4 +269,9 @@ int ZImage::Height() const
|
||||
return rHeight;
|
||||
}
|
||||
|
||||
Uint8 ZImage::Alpha() const
|
||||
{
|
||||
return rAlpha;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
and the home of this Library is http://www.zengine.sourceforge.net
|
||||
*******************************************************************************/
|
||||
|
||||
/*$Id: ZImageTest.cpp,v 1.14 2003/01/12 19:00:15 cozman Exp $*/
|
||||
/*$Id: ZImageTest.cpp,v 1.15 2003/01/25 19:59:38 cozman Exp $*/
|
||||
|
||||
#include <ZEngine.h>
|
||||
#include <string>
|
||||
@ -39,10 +39,11 @@ void Test()
|
||||
{
|
||||
ZEngine *engine = ZEngine::GetInstance();
|
||||
float angle=0.0f;
|
||||
Uint8 alpha=128,alphaDelta=1;
|
||||
|
||||
//Open and Setup all the Images//
|
||||
SDL_Surface *temp;
|
||||
ZImage image1, image2, image3, textImage;
|
||||
ZImage image1, image2, image3, textImage, cp;
|
||||
ZFont font("data/almontew.ttf",30);
|
||||
|
||||
font.SetColor(0,255,0);
|
||||
@ -76,16 +77,19 @@ void Test()
|
||||
if(engine->KeyIsPressed(SDLK_s))
|
||||
{
|
||||
//code to toggle screen//
|
||||
engine->SetupDisplay(engine->Width(),engine->Height(),engine->BPP(),!engine->IsFullscreen());
|
||||
engine->CreateDisplay("ZImage Test");
|
||||
engine->SetReloadNeed(true);
|
||||
engine->ToggleFullscreen();
|
||||
}
|
||||
if(engine->KeyIsPressed(SDLK_ESCAPE))
|
||||
engine->RequestQuit();
|
||||
|
||||
engine->Clear(); //clear screen
|
||||
//draw the images//
|
||||
alpha += alphaDelta;
|
||||
if(alpha ==255 || alpha == 0)
|
||||
alphaDelta *= -1;
|
||||
image1.SetAlpha(alpha);
|
||||
image1.Draw(0,0);
|
||||
|
||||
|
||||
image2.DrawRotated(100,0,angle);
|
||||
if(++angle > 360)
|
||||
@ -95,6 +99,8 @@ void Test()
|
||||
textImage.Draw(0,100);
|
||||
engine->Update(); //update the screen
|
||||
}
|
||||
else
|
||||
engine->Delay(10);
|
||||
|
||||
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user