Actualizadas todas las librerias de sprites

This commit is contained in:
2022-08-08 19:37:55 +02:00
parent c5acab7828
commit a3c846c137
11 changed files with 391 additions and 478 deletions

View File

@@ -1,5 +1,4 @@
#include <stdio.h>
#include <string>
#include "const.h"
#include "ltexture.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
@@ -15,7 +14,7 @@ LTexture::LTexture()
LTexture::~LTexture()
{
// Deallocate
free();
unload();
}
bool LTexture::loadFromFile(std::string path, SDL_Renderer *renderer)
@@ -45,19 +44,23 @@ 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 = SDL_CreateRGBSurfaceWithFormatFrom((void*)data, width, height, depth, pitch, pixel_format);
//SDL_Surface *loadedSurface = IMG_Load(path.c_str());
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());
}
else
{
// 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
newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if (newTexture == NULL)
@@ -97,7 +100,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)
@@ -127,7 +130,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};
@@ -139,6 +142,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);
}