X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fapp%2Fapp.cpp;h=f3c9115faedf3b50c96002efe1c231ee0e0547ed;hb=7bb75960dbf9bfdee9ac865384aca81791b3da5c;hp=420dee70aad191c042ac90d719cc01caa70c5fa0;hpb=a34fbcb0581056bd464158acfa30289a3e2c2c2d;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index 420dee7..f3c9115 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -7,12 +7,15 @@ #include "init.hpp" #include "../audio/Sound.hpp" +#include "../graphics/ArrayTexture.hpp" #include "../graphics/Font.hpp" +#include "../graphics/Texture.hpp" #include "../world/BlockType.hpp" #include "../world/Entity.hpp" #include #include +#include using std::string; @@ -195,7 +198,8 @@ void StateControl::Commit(Application &app) { Assets::Assets(const string &base) : fonts(base + "fonts/") -, sounds(base + "sounds/") { +, sounds(base + "sounds/") +, textures(base + "textures/") { } @@ -209,6 +213,35 @@ Sound Assets::LoadSound(const string &name) const { return Sound(full.c_str()); } +Texture Assets::LoadTexture(const string &name) const { + string full = textures + name + ".png"; + Texture tex; + SDL_Surface *srf = IMG_Load(full.c_str()); + if (!srf) { + throw SDLError("IMG_Load"); + } + tex.Bind(); + tex.Data(*srf); + SDL_FreeSurface(srf); + return tex; +} + +void Assets::LoadTexture(const string &name, ArrayTexture &tex, int layer) const { + string full = textures + name + ".png"; + SDL_Surface *srf = IMG_Load(full.c_str()); + if (!srf) { + throw SDLError("IMG_Load"); + } + tex.Bind(); + try { + tex.Data(layer, *srf); + } catch (...) { + SDL_FreeSurface(srf); + throw; + } + SDL_FreeSurface(srf); +} + void FrameCounter::EnterFrame() noexcept { last_enter = SDL_GetTicks();