Quitadas todas las variables globales y transformadas en punteros
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "ltexture.h"
|
||||
|
||||
LTexture::LTexture()
|
||||
LTexture::LTexture(SDL_Renderer *gRenderer)
|
||||
{
|
||||
//Initialize
|
||||
this->gRenderer = gRenderer;
|
||||
|
||||
// Initialize
|
||||
mTexture = NULL;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
@@ -10,19 +12,19 @@ LTexture::LTexture()
|
||||
|
||||
LTexture::~LTexture()
|
||||
{
|
||||
//Deallocate
|
||||
// Deallocate
|
||||
free();
|
||||
}
|
||||
|
||||
bool LTexture::loadFromFile(std::string path)
|
||||
{
|
||||
//Get rid of preexisting texture
|
||||
// Get rid of preexisting texture
|
||||
free();
|
||||
|
||||
//The final texture
|
||||
// The final texture
|
||||
SDL_Texture *newTexture = NULL;
|
||||
|
||||
//Load image at specified path
|
||||
// Load image at specified path
|
||||
SDL_Surface *loadedSurface = IMG_Load(path.c_str());
|
||||
if (loadedSurface == NULL)
|
||||
{
|
||||
@@ -30,10 +32,10 @@ bool LTexture::loadFromFile(std::string path)
|
||||
}
|
||||
else
|
||||
{
|
||||
//Color key image
|
||||
// Color key image
|
||||
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
|
||||
|
||||
//Create texture from surface pixels
|
||||
// Create texture from surface pixels
|
||||
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
|
||||
if (newTexture == NULL)
|
||||
{
|
||||
@@ -41,40 +43,40 @@ bool LTexture::loadFromFile(std::string path)
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get image dimensions
|
||||
// Get image dimensions
|
||||
mWidth = loadedSurface->w;
|
||||
mHeight = loadedSurface->h;
|
||||
}
|
||||
|
||||
//Get rid of old loaded surface
|
||||
// Get rid of old loaded surface
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
}
|
||||
|
||||
//Return success
|
||||
// Return success
|
||||
mTexture = newTexture;
|
||||
return mTexture != NULL;
|
||||
}
|
||||
|
||||
bool LTexture::createBlank( int width, int height, SDL_TextureAccess access )
|
||||
bool LTexture::createBlank(int width, int height, SDL_TextureAccess access)
|
||||
{
|
||||
//Create uninitialized texture
|
||||
mTexture = SDL_CreateTexture( gRenderer, SDL_PIXELFORMAT_RGBA8888, access, width, height );
|
||||
if( mTexture == NULL )
|
||||
{
|
||||
printf( "Unable to create blank texture! SDL Error: %s\n", SDL_GetError() );
|
||||
}
|
||||
else
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
// Create uninitialized texture
|
||||
mTexture = SDL_CreateTexture(gRenderer, SDL_PIXELFORMAT_RGBA8888, access, width, height);
|
||||
if (mTexture == NULL)
|
||||
{
|
||||
printf("Unable to create blank texture! SDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
return mTexture != NULL;
|
||||
return mTexture != NULL;
|
||||
}
|
||||
|
||||
void LTexture::free()
|
||||
{
|
||||
//Free texture if it exists
|
||||
// Free texture if it exists
|
||||
if (mTexture != NULL)
|
||||
{
|
||||
SDL_DestroyTexture(mTexture);
|
||||
@@ -86,42 +88,42 @@ void LTexture::free()
|
||||
|
||||
void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
//Modulate texture rgb
|
||||
// Modulate texture rgb
|
||||
SDL_SetTextureColorMod(mTexture, red, green, blue);
|
||||
}
|
||||
|
||||
void LTexture::setBlendMode(SDL_BlendMode blending)
|
||||
{
|
||||
//Set blending function
|
||||
// Set blending function
|
||||
SDL_SetTextureBlendMode(mTexture, blending);
|
||||
}
|
||||
|
||||
void LTexture::setAlpha(Uint8 alpha)
|
||||
{
|
||||
//Modulate texture alpha
|
||||
// Modulate texture alpha
|
||||
SDL_SetTextureAlphaMod(mTexture, alpha);
|
||||
}
|
||||
|
||||
void LTexture::render(int x, int y, SDL_Rect *clip, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
//Set rendering space and render to screen
|
||||
// Set rendering space and render to screen
|
||||
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
|
||||
|
||||
//Set clip rendering dimensions
|
||||
// Set clip rendering dimensions
|
||||
if (clip != NULL)
|
||||
{
|
||||
renderQuad.w = clip->w;
|
||||
renderQuad.h = clip->h;
|
||||
}
|
||||
|
||||
//Render to screen
|
||||
// Render to screen
|
||||
SDL_RenderCopyEx(gRenderer, mTexture, clip, &renderQuad, angle, center, flip);
|
||||
}
|
||||
|
||||
void LTexture::setAsRenderTarget()
|
||||
{
|
||||
//Make self render target
|
||||
SDL_SetRenderTarget( gRenderer, mTexture );
|
||||
// Make self render target
|
||||
SDL_SetRenderTarget(gRenderer, mTexture);
|
||||
}
|
||||
|
||||
int LTexture::getWidth()
|
||||
|
||||
Reference in New Issue
Block a user