1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
matabstrix/src/texture.cpp

29 lines
680 B
C++
Raw Normal View History

2015-11-07 14:11:23 +00:00
#include "texture.hpp"
#include <string>
2015-11-16 16:34:46 +00:00
#include <stb_image.h>
2015-11-07 14:11:23 +00:00
2015-11-11 17:28:11 +00:00
const std::string Texture::filename(const std::string &name)
{
2015-11-16 13:05:04 +00:00
return "/textures/" + name;
2015-11-11 17:28:11 +00:00
}
2015-11-16 13:05:04 +00:00
Texture::Texture(const Adapter &adapter, const std::string &name)
2015-11-07 14:11:23 +00:00
{
2015-11-16 16:34:46 +00:00
GLsizei width, height, comp;
GLvoid *data = stbi_load(adapter.filename<Texture>(name).c_str(), &width, &height, &comp, 0);
2015-11-07 14:11:23 +00:00
glGenTextures(1, &_id);
glBindTexture(GL_TEXTURE_2D, _id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2015-11-16 16:34:46 +00:00
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
2015-11-07 14:11:23 +00:00
2015-11-16 16:34:46 +00:00
stbi_image_free(data);
2015-11-07 14:11:23 +00:00
}
void Texture::use() const
{
glBindTexture(GL_TEXTURE_2D, _id);
}