Phoenix/src/texture.cpp
2023-05-27 13:36:40 -04:00

35 lines
844 B
C++

#include "config.hpp"
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_log.h>
#include <state.hpp>
#include <texture.hpp>
PhoenixTexture PLoadTexture(std::string filePath) {
SDL_Log("Loading texture from path: %s", filePath.c_str());
PhoenixTexture texture{};
texture.texture = IMG_LoadTexture(state.renderer, filePath.c_str());
if (texture.texture == NULL) {
SDL_Log("Failed to load image: %s", SDL_GetError());
abort();
}
return texture;
}
void PDestroyTexture(PhoenixTexture *texture) {
SDL_DestroyTexture(texture->texture);
}
void PRenderTexture(PhoenixTexture *texture, int x, int y) {
SDL_Rect dstRect{};
dstRect.x = x - state.camera.x;
dstRect.y = y - state.camera.y;
dstRect.w = TEXTURE_WIDTH;
dstRect.h = TEXTURE_HEIGHT;
SDL_RenderCopy(state.renderer, texture->texture, NULL, &dstRect);
}