added alpha
This commit is contained in:
		
							parent
							
								
									bd3a140858
								
							
						
					
					
						commit
						5a90ab3af0
					
				
					 3 changed files with 53 additions and 8 deletions
				
			
		|  | @ -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.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 |     \file ZE_ZImage.h | ||||||
|     \brief Definition file for ZImage. |     \brief Definition file for ZImage. | ||||||
|  | @ -53,6 +53,8 @@ class ZImage : public ZObject | ||||||
|         unsigned int rWidth; |         unsigned int rWidth; | ||||||
|         //! Current draw height of Texture.
 |         //! Current draw height of Texture.
 | ||||||
|         unsigned int rHeight; |         unsigned int rHeight; | ||||||
|  |         //! Stored alpha value for drawing texture.
 | ||||||
|  |         Uint8 rAlpha; | ||||||
|      |      | ||||||
|     public: |     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. |             Set color which will not be drawn in image. | ||||||
|             \param red Red component of colorkey (0-255). |             \param red Red component of colorkey (0-255). | ||||||
|  | @ -256,6 +267,15 @@ class ZImage : public ZObject | ||||||
|             \return Image Height. |             \return Image Height. | ||||||
|         **/ |         **/ | ||||||
|         int Height() const; |         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> | 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.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 |     \file ZE_ZImage.cpp | ||||||
|     \brief Source file for ZImage. |     \brief Source file for ZImage. | ||||||
|  | @ -29,30 +29,35 @@ namespace ZE | ||||||
| ZImage::ZImage() | ZImage::ZImage() | ||||||
| { | { | ||||||
|     rImage = NULL; |     rImage = NULL; | ||||||
|  |     rAlpha = 255; | ||||||
|     Release(); |     Release(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ZImage::ZImage(const ZImage &rhs) | ZImage::ZImage(const ZImage &rhs) | ||||||
| { | { | ||||||
|     rImage = NULL; |     rImage = NULL; | ||||||
|  |     rAlpha = rhs.Alpha(); | ||||||
|     OpenFromImage(rhs.Surface(),0,0,(Sint16)rhs.Width(),(Sint16)rhs.Height()); |     OpenFromImage(rhs.Surface(),0,0,(Sint16)rhs.Width(),(Sint16)rhs.Height()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ZImage::ZImage(string filename) | ZImage::ZImage(string filename) | ||||||
| { | { | ||||||
|     rImage = NULL; |     rImage = NULL; | ||||||
|  |     rAlpha = 255; | ||||||
|     Open(filename); |     Open(filename); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ZImage::ZImage(SDL_Surface *surface) | ZImage::ZImage(SDL_Surface *surface) | ||||||
| { | { | ||||||
|     rImage = NULL; |     rImage = NULL; | ||||||
|  |     rAlpha = 255; | ||||||
|     Attach(surface); |     Attach(surface); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ZImage::ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h) | ZImage::ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h) | ||||||
| { | { | ||||||
|     rImage = NULL; |     rImage = NULL; | ||||||
|  |     rAlpha = 255; | ||||||
|     OpenFromImage(img,x,y,w,h); |     OpenFromImage(img,x,y,w,h); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -147,6 +152,11 @@ void ZImage::Release() | ||||||
|     FreeImage(rImage); |     FreeImage(rImage); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void ZImage::SetAlpha(Uint8 alpha) | ||||||
|  | { | ||||||
|  |     rAlpha = alpha; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) | void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) | ||||||
| { | { | ||||||
|     SDL_Surface *temp=NULL; |     SDL_Surface *temp=NULL; | ||||||
|  | @ -201,7 +211,10 @@ void ZImage::Bind() const | ||||||
|     if(!rTexID) |     if(!rTexID) | ||||||
|         rEngine->ReportError(ZERR_NOIMAGE,"Bind"); |         rEngine->ReportError(ZERR_NOIMAGE,"Bind"); | ||||||
|     else |     else | ||||||
|  |     { | ||||||
|  |         glColor4ub(255,255,255,rAlpha);  | ||||||
|         glBindTexture(GL_TEXTURE_2D, rTexID); |         glBindTexture(GL_TEXTURE_2D, rTexID); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ZImage::Draw(float x, float y) const | 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(rTexMinX,rTexMaxY);    glVertex2f(x,y+rHeight); | ||||||
|         glTexCoord2f(rTexMaxX,rTexMaxY);    glVertex2f(x+rWidth,y+rHeight); |         glTexCoord2f(rTexMaxX,rTexMaxY);    glVertex2f(x+rWidth,y+rHeight); | ||||||
|     glEnd(); |     glEnd(); | ||||||
|  |     glColor4ub(255,255,255,255);    //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 | ||||||
|  | @ -255,4 +269,9 @@ int ZImage::Height() const | ||||||
|     return rHeight; |     return rHeight; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | Uint8 ZImage::Alpha() const | ||||||
|  | { | ||||||
|  |     return rAlpha; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ | ||||||
|      and the home of this Library is http://www.zengine.sourceforge.net
 |      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 <ZEngine.h> | ||||||
| #include <string>  | #include <string>  | ||||||
|  | @ -39,10 +39,11 @@ void Test() | ||||||
| { | { | ||||||
|     ZEngine *engine = ZEngine::GetInstance(); |     ZEngine *engine = ZEngine::GetInstance(); | ||||||
|     float angle=0.0f; |     float angle=0.0f; | ||||||
|  |     Uint8 alpha=128,alphaDelta=1; | ||||||
| 
 | 
 | ||||||
|     //Open and Setup all the Images//
 |     //Open and Setup all the Images//
 | ||||||
|     SDL_Surface *temp; |     SDL_Surface *temp; | ||||||
|     ZImage image1, image2, image3, textImage; |     ZImage image1, image2, image3, textImage, cp; | ||||||
|     ZFont font("data/almontew.ttf",30); |     ZFont font("data/almontew.ttf",30); | ||||||
| 
 | 
 | ||||||
|     font.SetColor(0,255,0); |     font.SetColor(0,255,0); | ||||||
|  | @ -76,17 +77,20 @@ void Test() | ||||||
|             if(engine->KeyIsPressed(SDLK_s)) |             if(engine->KeyIsPressed(SDLK_s)) | ||||||
|             { |             { | ||||||
|                 //code to toggle screen//
 |                 //code to toggle screen//
 | ||||||
|                 engine->SetupDisplay(engine->Width(),engine->Height(),engine->BPP(),!engine->IsFullscreen()); |                 engine->ToggleFullscreen(); | ||||||
|                 engine->CreateDisplay("ZImage Test"); |  | ||||||
|                 engine->SetReloadNeed(true); |  | ||||||
|             } |             } | ||||||
|             if(engine->KeyIsPressed(SDLK_ESCAPE)) |             if(engine->KeyIsPressed(SDLK_ESCAPE)) | ||||||
|                 engine->RequestQuit(); |                 engine->RequestQuit(); | ||||||
| 
 | 
 | ||||||
|             engine->Clear();    //clear screen
 |             engine->Clear();    //clear screen
 | ||||||
|             //draw the images//
 |             //draw the images//
 | ||||||
|  |             alpha += alphaDelta; | ||||||
|  |             if(alpha ==255 || alpha == 0) | ||||||
|  |                 alphaDelta *= -1; | ||||||
|  |             image1.SetAlpha(alpha); | ||||||
|             image1.Draw(0,0); |             image1.Draw(0,0); | ||||||
| 
 | 
 | ||||||
|  |              | ||||||
|             image2.DrawRotated(100,0,angle); |             image2.DrawRotated(100,0,angle); | ||||||
|             if(++angle > 360) |             if(++angle > 360) | ||||||
|                 angle = 0.0f; |                 angle = 0.0f; | ||||||
|  | @ -95,6 +99,8 @@ void Test() | ||||||
|             textImage.Draw(0,100); |             textImage.Draw(0,100); | ||||||
|             engine->Update();    //update the screen
 |             engine->Update();    //update the screen
 | ||||||
|         } |         } | ||||||
|  |         else | ||||||
|  |             engine->Delay(10); | ||||||
| 
 | 
 | ||||||
|     } while(!engine->QuitRequested());    //quit only when engine has encountered a quit request
 |     } while(!engine->QuitRequested());    //quit only when engine has encountered a quit request
 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 James Turk
						James Turk