forked from jaildesigner-jailgames/coffee_crisis
code reorganized
This commit is contained in:
@@ -16,7 +16,7 @@ LTexture::LTexture()
|
||||
LTexture::~LTexture()
|
||||
{
|
||||
// Deallocate
|
||||
free();
|
||||
unload();
|
||||
}
|
||||
|
||||
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
@@ -46,14 +46,14 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
}
|
||||
|
||||
// Get rid of preexisting texture
|
||||
free();
|
||||
unload();
|
||||
|
||||
// The final texture
|
||||
SDL_Texture *newTexture = NULL;
|
||||
|
||||
// Load image at specified path
|
||||
//SDL_Surface *loadedSurface = IMG_Load(path.c_str());
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void*)data, width, height, depth, pitch, pixel_format);
|
||||
SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format);
|
||||
if (loadedSurface == NULL)
|
||||
{
|
||||
printf("Unable to load image %s!\n", path.c_str());
|
||||
@@ -61,7 +61,7 @@ bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
|
||||
else
|
||||
{
|
||||
// Color key image
|
||||
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
|
||||
//SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, COLOR_KEY_R, COLOR_KEY_G, COLOR_KEY_B));
|
||||
|
||||
// Create texture from surface pixels
|
||||
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
|
||||
@@ -102,7 +102,7 @@ bool LTexture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Te
|
||||
return mTexture != NULL;
|
||||
}
|
||||
|
||||
void LTexture::free()
|
||||
void LTexture::unload()
|
||||
{
|
||||
// Free texture if it exists
|
||||
if (mTexture != NULL)
|
||||
@@ -132,7 +132,7 @@ void LTexture::setAlpha(Uint8 alpha)
|
||||
SDL_SetTextureAlphaMod(mTexture, alpha);
|
||||
}
|
||||
|
||||
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
// Set rendering space and render to screen
|
||||
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
|
||||
@@ -144,6 +144,9 @@ void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, doub
|
||||
renderQuad.h = clip->h;
|
||||
}
|
||||
|
||||
renderQuad.w = renderQuad.w * zoomW;
|
||||
renderQuad.h = renderQuad.h * zoomH;
|
||||
|
||||
// Render to screen
|
||||
SDL_RenderCopyEx(renderer, mTexture, clip, &renderQuad, angle, center, flip);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user