28 void Texture::Init(
int width,
int height,
int numChannels,
unsigned char* data)
30 glGenTextures(1, &m_textureID);
31 glBindTexture(GL_TEXTURE_2D, m_textureID);
33 GLint internalFormat = GL_RGB;
38 internalFormat = GL_RGBA;
42 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, GL_UNSIGNED_BYTE, data);
44 glGenerateMipmap(GL_TEXTURE_2D);
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
47 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
49 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
55 int width, height, numChannels;
60 if (!std::filesystem::exists(fullPath))
65 std::shared_ptr<Texture> result;
67 unsigned char* data = stbi_load(fullPath.string().c_str(), &width, &height, &numChannels, 0);
71 result = std::make_shared<Texture>(width, height, numChannels, data);
72 stbi_image_free(data);
std::shared_ptr< Texture > GetOrLoadTexture(const std::string &path)
Texture(int width, int height, int numChannels, unsigned char *data)
static std::shared_ptr< Texture > Load(const std::string &path)
void Init(int width, int height, int numChannels, unsigned char *data)