diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h index 47f8354..d5e51f7 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.10 2003/01/24 02:47:06 cozman Exp $
+$Id: ZE_ZImage.h,v 1.11 2003/01/25 19:56:05 cozman Exp $
\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; }; } diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp index afa0066..88a480e 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.20 2003/01/24 10:27:42 cozman Exp $
+$Id: ZE_ZImage.cpp,v 1.21 2003/01/25 19:56:05 cozman Exp $
\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; +} + } diff --git a/test/ZImageTest.cpp b/test/ZImageTest.cpp index 6d43f0c..cf305eb 100644 --- a/test/ZImageTest.cpp +++ b/test/ZImageTest.cpp @@ -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 #include @@ -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 }