You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
691 B
C++
34 lines
691 B
C++
3 months ago
|
#ifndef COMPONENTS_TEXTURE_HPP
|
||
|
#define COMPONENTS_TEXTURE_HPP
|
||
|
|
||
|
#include "window.hpp"
|
||
|
|
||
|
class Texture
|
||
|
{
|
||
|
public:
|
||
|
Texture(const char *path) {
|
||
|
tex = sdl2LoadTexture(path);
|
||
|
}
|
||
|
|
||
|
~Texture() {
|
||
|
if (tex != nullptr)
|
||
|
SDL_DestroyTexture(tex);
|
||
|
}
|
||
|
|
||
|
void operator()(SDL_Renderer *rend, Point p) const noexcept {
|
||
|
const int x = static_cast<int>(p.x);
|
||
|
const int y = static_cast<int>(p.y);
|
||
|
SDL_Rect rect {x, y, 0, 0};
|
||
|
|
||
|
/* TODO err check */
|
||
|
SDL_QueryTexture(tex, nullptr, nullptr, &rect.w, &rect.h);
|
||
|
SDL_RenderCopy(rend, tex, nullptr, &rect);
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
SDL_Texture *tex;
|
||
|
};
|
||
|
|
||
|
#endif // COMPONENTS_TEXTURE_HPP
|
||
|
|