addition of SDL GFX_BACKEND
This commit is contained in:
		
							parent
							
								
									299486df5c
								
							
						
					
					
						commit
						5ed1ea52b5
					
				
					 4 changed files with 176 additions and 49 deletions
				
			
		| 
						 | 
					@ -13,7 +13,7 @@
 | 
				
			||||||
    \brief Central source file for ZEngine.
 | 
					    \brief Central source file for ZEngine.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Actual implementation of ZEngine singleton class, the core of ZEngine.
 | 
					    Actual implementation of ZEngine singleton class, the core of ZEngine.
 | 
				
			||||||
    <br>$Id: ZE_ZEngine.cpp,v 1.53 2003/07/13 05:35:11 cozman Exp $<br>
 | 
					    <br>$Id: ZE_ZEngine.cpp,v 1.54 2003/08/01 21:56:58 cozman Exp $<br>
 | 
				
			||||||
    \author James Turk
 | 
					    \author James Turk
 | 
				
			||||||
**/
 | 
					**/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -84,7 +84,9 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
 | 
				
			||||||
    SDL_Surface *iconImg;
 | 
					    SDL_Surface *iconImg;
 | 
				
			||||||
    bool status=true;   //status of setup, only true if everything went flawless
 | 
					    bool status=true;   //status of setup, only true if everything went flawless
 | 
				
			||||||
    int bpp;
 | 
					    int bpp;
 | 
				
			||||||
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
    int rgb_size[3];
 | 
					    int rgb_size[3];
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!mInitialized)
 | 
					    if(!mInitialized)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -134,6 +136,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
    //buffer sizes
 | 
					    //buffer sizes
 | 
				
			||||||
    switch (mBPP)
 | 
					    switch (mBPP)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -168,6 +171,9 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
 | 
				
			||||||
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);
 | 
					    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    flags |= SDL_OPENGL;
 | 
					    flags |= SDL_OPENGL;
 | 
				
			||||||
 | 
					#elif GFX_BACKEND == SDL
 | 
				
			||||||
 | 
					    flags |= SDL_DOUBLEBUF;
 | 
				
			||||||
 | 
					#endif //GFX_BACKEND
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!mInitialized)    //only set these settings the first time
 | 
					    if(!mInitialized)    //only set these settings the first time
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
| 
						 | 
					@ -202,7 +208,9 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
 | 
				
			||||||
    mHeight = mScreen->h;
 | 
					    mHeight = mScreen->h;
 | 
				
			||||||
    mBPP = mScreen->format->BitsPerPixel;
 | 
					    mBPP = mScreen->format->BitsPerPixel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
    SetGL2D();
 | 
					    SetGL2D();
 | 
				
			||||||
 | 
					#endif 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mKeyIsPressed = SDL_GetKeyState(NULL);
 | 
					    mKeyIsPressed = SDL_GetKeyState(NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -296,7 +304,11 @@ SDL_Surface *ZEngine::Display()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ZEngine::Update()
 | 
					void ZEngine::Update()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
    SDL_GL_SwapBuffers();
 | 
					    SDL_GL_SwapBuffers();
 | 
				
			||||||
 | 
					#elif GFX_BACKEND == SDL
 | 
				
			||||||
 | 
					    SDL_Flip(mScreen);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //keeps track of spf//
 | 
					    //keeps track of spf//
 | 
				
			||||||
    mSecPerFrame = (GetTime()-mLastTime)/1000.0;
 | 
					    mSecPerFrame = (GetTime()-mLastTime)/1000.0;
 | 
				
			||||||
| 
						 | 
					@ -311,9 +323,12 @@ void ZEngine::Update()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ZEngine::Clear(float red, float green, float blue, float alpha)
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    glClearColor(red,green,blue,alpha);
 | 
					    GLclampf r = red/255.0f, g = green/255.0f, b = blue/255.0f, a = alpha/255.0f;
 | 
				
			||||||
 | 
					    glClearColor(r,g,b,a);
 | 
				
			||||||
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
 | 
					    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
 | 
				
			||||||
    glLoadIdentity();
 | 
					    glLoadIdentity();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -344,6 +359,15 @@ void ZEngine::SetGL2D()
 | 
				
			||||||
    glLoadIdentity();
 | 
					    glLoadIdentity();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#elif GFX_BACKEND == SDL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    SDL_FillRect(mScreen,NULL,SDL_MapRGBA(mScreen->format,red,green,blue,alpha));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //GFX_BACKEND
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ZEngine::Delay(Uint32 milliseconds)
 | 
					void ZEngine::Delay(Uint32 milliseconds)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    SDL_Delay(milliseconds);
 | 
					    SDL_Delay(milliseconds);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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.37 2003/07/11 20:51:44 cozman Exp $<br>
 | 
					    <br>$Id: ZE_ZImage.cpp,v 1.38 2003/08/01 21:56:58 cozman Exp $<br>
 | 
				
			||||||
    \author James Turk
 | 
					    \author James Turk
 | 
				
			||||||
**/
 | 
					**/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,6 +116,8 @@ void ZImage::OpenFromImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint
 | 
				
			||||||
    OpenFromImage(img.Surface(),x,y,w,h);
 | 
					    OpenFromImage(img.Surface(),x,y,w,h);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//attach is really the core of ZImage, everything calls it, it converts SDL_Surface->OpenGL Texture->ZImage
 | 
					//attach is really the core of ZImage, everything calls it, it converts SDL_Surface->OpenGL Texture->ZImage
 | 
				
			||||||
void ZImage::Attach(SDL_Surface *surface)
 | 
					void ZImage::Attach(SDL_Surface *surface)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -189,48 +191,6 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
 | 
				
			||||||
        rEngine->ReportError(ZERR_NOIMAGE,"SetColorKey");
 | 
					        rEngine->ReportError(ZERR_NOIMAGE,"SetColorKey");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(vertical)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        temp = rTexMinY;
 | 
					 | 
				
			||||||
        rTexMinY = rTexMaxY;
 | 
					 | 
				
			||||||
        rTexMaxY = temp;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//stretching and resizing is very inexpensive, done via variables
 | 
					 | 
				
			||||||
void ZImage::Stretch(float xFactor, float yFactor)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    rWidth = static_cast<unsigned int>(xFactor*rWidth);
 | 
					 | 
				
			||||||
    rHeight = static_cast<unsigned int>(yFactor*rHeight);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void ZImage::Resize(unsigned int width, unsigned int height)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    rWidth = width;
 | 
					 | 
				
			||||||
    rHeight = height;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//this is available for other uses of ZEngine
 | 
					 | 
				
			||||||
void ZImage::Bind() const
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    if(rTexID)
 | 
					 | 
				
			||||||
        glBindTexture(GL_TEXTURE_2D, rTexID);
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
        rEngine->ReportError(ZERR_NOIMAGE,"Bind");
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void ZImage::Draw(int x, int y) const
 | 
					void ZImage::Draw(int x, int y) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    //source is same as float version, but uses glVertex2i
 | 
					    //source is same as float version, but uses glVertex2i
 | 
				
			||||||
| 
						 | 
					@ -285,11 +245,140 @@ void ZImage::DrawRotated(float x, float y, float angle) const
 | 
				
			||||||
    glPopMatrix();
 | 
					    glPopMatrix();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(vertical)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        temp = rTexMinY;
 | 
				
			||||||
 | 
					        rTexMinY = rTexMaxY;
 | 
				
			||||||
 | 
					        rTexMaxY = temp;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//stretching and resizing is very inexpensive, done via variables
 | 
				
			||||||
 | 
					void ZImage::Stretch(float xFactor, float yFactor)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    rWidth = static_cast<unsigned int>(xFactor*rWidth);
 | 
				
			||||||
 | 
					    rHeight = static_cast<unsigned int>(yFactor*rHeight);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZImage::Resize(unsigned int width, unsigned int height)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    rWidth = width;
 | 
				
			||||||
 | 
					    rHeight = height;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//this is available for other uses of ZEngine
 | 
				
			||||||
 | 
					void ZImage::Bind() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if(rTexID)
 | 
				
			||||||
 | 
					        glBindTexture(GL_TEXTURE_2D, rTexID);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        rEngine->ReportError(ZERR_NOIMAGE,"Bind");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool ZImage::IsLoaded() const
 | 
					bool ZImage::IsLoaded() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return glIsTexture(rTexID) == GL_TRUE;
 | 
					    return glIsTexture(rTexID) == GL_TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#elif GFX_BACKEND == SDL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZImage::Attach(SDL_Surface *surface)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Release();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //surface conversion//
 | 
				
			||||||
 | 
					    SDL_Surface *temp = surface;
 | 
				
			||||||
 | 
					    surface = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this
 | 
				
			||||||
 | 
					    if(surface)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        FreeImage(temp);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else    //can't convert
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError()));
 | 
				
			||||||
 | 
					        surface = temp;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(surface)
 | 
				
			||||||
 | 
					        rImage = surface;
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        rEngine->ReportError(ZERR_NOIMAGE,"Attach");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZImage::Reload()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    //currently a no-op
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZImage::Release()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    FreeImage(rImage);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZImage::SetAlpha(Uint8 alpha)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    rAlpha = alpha;
 | 
				
			||||||
 | 
					    if(rImage)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if(SDL_SetAlpha(rImage, SDL_SRCALPHA, alpha) < 0)
 | 
				
			||||||
 | 
					            rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetAlpha failed in ZImage::SetAlpha: %s",SDL_GetError()));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        rEngine->ReportError(ZERR_NOIMAGE,"SetAlpha");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Uint32 color = SDL_MapRGBA(rImage->format,red,green,blue,255);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(rImage)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if(SDL_SetColorKey(rImage, SDL_RLEACCEL|SDL_SRCCOLORKEY, color) < 0)
 | 
				
			||||||
 | 
					            rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()));
 | 
				
			||||||
 | 
					        //surface conversion//
 | 
				
			||||||
 | 
					        SDL_Surface *temp = rImage;
 | 
				
			||||||
 | 
					        rImage = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this
 | 
				
			||||||
 | 
					        if(rImage)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            FreeImage(temp);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else    //can't convert
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::SetColorKey: %s",SDL_GetError()));
 | 
				
			||||||
 | 
					            rImage = temp;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        rEngine->ReportError(ZERR_NOIMAGE,"SetColorKey");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ZImage::Draw(int x, int y) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    SDL_Rect rect;
 | 
				
			||||||
 | 
					    rect.x = static_cast<Sint16>(x);
 | 
				
			||||||
 | 
					    rect.y = static_cast<Sint16>(y);
 | 
				
			||||||
 | 
					    SDL_BlitSurface(rImage, NULL, rEngine->Display(), &rect);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool ZImage::IsLoaded() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return rImage ? true : false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //GFX_BACKEND
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SDL_Surface* ZImage::Surface() const
 | 
					SDL_Surface* ZImage::Surface() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return rImage;
 | 
					    return rImage;
 | 
				
			||||||
| 
						 | 
					@ -297,12 +386,12 @@ SDL_Surface* ZImage::Surface() const
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ZImage::Width() const
 | 
					int ZImage::Width() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return rWidth;
 | 
					    return rImage->w;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ZImage::Height() const
 | 
					int ZImage::Height() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return rHeight;
 | 
					    return rImage->h;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Uint8 ZImage::Alpha() const
 | 
					Uint8 ZImage::Alpha() const
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@
 | 
				
			||||||
    \brief Source file for ZRect.
 | 
					    \brief Source file for ZRect.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Implementation of ZRect, the Rectangle class for ZEngine.
 | 
					    Implementation of ZRect, the Rectangle class for ZEngine.
 | 
				
			||||||
    <br>$Id: ZE_ZRect.cpp,v 1.12 2003/06/11 05:51:16 cozman Exp $<br>
 | 
					    <br>$Id: ZE_ZRect.cpp,v 1.13 2003/08/01 21:56:58 cozman Exp $<br>
 | 
				
			||||||
    \author James Turk
 | 
					    \author James Turk
 | 
				
			||||||
**/
 | 
					**/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,16 +23,19 @@ namespace ZE
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ZRect::ZRect() :
 | 
					ZRect::ZRect() :
 | 
				
			||||||
 | 
					    rEngine(ZEngine::GetInstance()),
 | 
				
			||||||
    rX(0),rY(0),rWidth(0),rHeight(0)
 | 
					    rX(0),rY(0),rWidth(0),rHeight(0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ZRect::ZRect(float x, float y, float width, float height) :
 | 
					ZRect::ZRect(float x, float y, float width, float height) :
 | 
				
			||||||
 | 
					    rEngine(ZEngine::GetInstance()),
 | 
				
			||||||
    rX(x),rY(y),rWidth(width),rHeight(height)
 | 
					    rX(x),rY(y),rWidth(width),rHeight(height)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ZRect::ZRect(const SDL_Rect &rect) :
 | 
					ZRect::ZRect(const SDL_Rect &rect) :
 | 
				
			||||||
 | 
					    rEngine(ZEngine::GetInstance()),
 | 
				
			||||||
    rX(static_cast<float>(rect.x)),
 | 
					    rX(static_cast<float>(rect.x)),
 | 
				
			||||||
    rY(static_cast<float>(rect.y)),
 | 
					    rY(static_cast<float>(rect.y)),
 | 
				
			||||||
    rWidth(static_cast<float>(rect.w)),
 | 
					    rWidth(static_cast<float>(rect.w)),
 | 
				
			||||||
| 
						 | 
					@ -41,6 +44,7 @@ ZRect::ZRect(const SDL_Rect &rect) :
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ZRect::ZRect(const ZRect &rhs) :
 | 
					ZRect::ZRect(const ZRect &rhs) :
 | 
				
			||||||
 | 
					    rEngine(ZEngine::GetInstance()),
 | 
				
			||||||
    rX(rhs.X()),rY(rhs.Y()),rWidth(rhs.Width()),rHeight(rhs.Height())
 | 
					    rX(rhs.X()),rY(rhs.Y()),rWidth(rhs.Width()),rHeight(rhs.Height())
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -96,6 +100,7 @@ bool ZRect::operator<(const ZRect &rhs) const
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const
 | 
					void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
    glBindTexture(GL_TEXTURE_2D,0); //reset to blank texture
 | 
					    glBindTexture(GL_TEXTURE_2D,0); //reset to blank texture
 | 
				
			||||||
    glColor4ub(red,green,blue,alpha);
 | 
					    glColor4ub(red,green,blue,alpha);
 | 
				
			||||||
    glBegin(GL_QUADS);
 | 
					    glBegin(GL_QUADS);
 | 
				
			||||||
| 
						 | 
					@ -105,6 +110,11 @@ void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const
 | 
				
			||||||
        glVertex2f(rX, rY+rHeight);
 | 
					        glVertex2f(rX, rY+rHeight);
 | 
				
			||||||
    glEnd();
 | 
					    glEnd();
 | 
				
			||||||
    glColor4ub(255,255,255,255);    //restore color setting
 | 
					    glColor4ub(255,255,255,255);    //restore color setting
 | 
				
			||||||
 | 
					#elif GFX_BACKEND == SDL
 | 
				
			||||||
 | 
					    SDL_Rect rect = SDLrect();
 | 
				
			||||||
 | 
					    SDL_FillRect(rEngine->Display(), &rect, SDL_MapRGBA(rEngine->Display()->format,red,green,blue,alpha));
 | 
				
			||||||
 | 
					#endif //GFX_BACKEND
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ZRect::Move(float x, float y)
 | 
					void ZRect::Move(float x, float y)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										4
									
								
								src/external/SDLGL_Util.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								src/external/SDLGL_Util.cpp
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -4,6 +4,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "external/SDLGL_Util.h"
 | 
					#include "external/SDLGL_Util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if GFX_BACKEND == OGL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//finds nearest power of two (going up), needed for surfaces
 | 
					//finds nearest power of two (going up), needed for surfaces
 | 
				
			||||||
int power_of_two(int input)
 | 
					int power_of_two(int input)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -87,3 +89,5 @@ GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return texture;
 | 
					    return texture;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif //GFX_BACKEND == OGL
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue