#include "Texture.h" #include "EngineCore/Asset_ImagePack.h" #include "EngineCore/Game.h" Texture::Texture() { } Texture::Texture(std::string imgPath, int Index) { Init(imgPath, Index); } Texture::~Texture() { SDL_DestroyTexture(m_texture); } void Texture::Init(std::string imgPath, int Index) { Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(imgPath); if (Info->lpImgName == "sprite/interface/base.img") return; Asset_ImagePack::ImgInfo &Buf = Info->lp_lplist[Index]; m_texture = SDL_CreateTexture( Game::GetInstance().GetRenderer(), SDL_PIXELFORMAT_ARGB8888, // 匹配RGBA数据格式 SDL_TEXTUREACCESS_STREAMING, Buf.Width, Buf.Height); if (!m_texture) { SDL_Log("纹理创建失败: %s", SDL_GetError()); } int pitch = Buf.Width * 4; SDL_UpdateTexture(m_texture, NULL, Buf.PNGdata, pitch); SDL_SetTextureBlendMode(m_texture, SDL_BLENDMODE_BLEND); this->TexturePos.x = Buf.Xpos; this->TexturePos.y = Buf.Ypos; this->TextureSize.x = Buf.Width; this->TextureSize.y = Buf.Height; this->TextureFramepos.x = Buf.FrameXpos; this->TextureFramepos.y = Buf.FrameYpos; } SDL_Texture *Texture::GetTexture() { return m_texture; } void Texture::SetBlendMode(SDL_BlendMode blendMode) { SDL_SetTextureBlendMode(m_texture, blendMode); } SDL_BlendMode Texture::GetBlendMode() { SDL_BlendMode blendMode; SDL_GetTextureBlendMode(m_texture, &blendMode); return blendMode; }