53 lines
1.2 KiB
C++
53 lines
1.2 KiB
C++
#ifndef TEXTURE_H
|
|
#define TEXTURE_H
|
|
|
|
#include <glad/glad.h>
|
|
#include <glm/glm.hpp>
|
|
#include <stb_image.h>>
|
|
|
|
#include <iostream>
|
|
|
|
class Texture
|
|
{
|
|
public:
|
|
unsigned int ID;
|
|
|
|
Texture()
|
|
{
|
|
ID = -1;
|
|
}
|
|
|
|
Texture(const char* path)
|
|
{
|
|
glGenTextures(1, &ID);
|
|
glBindTexture(GL_TEXTURE_2D, ID);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
int width, height, nrChannels;
|
|
unsigned char *data = stbi_load(path, &width, &height, &nrChannels, 0);
|
|
if (data)
|
|
{
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
|
glGenerateMipmap(GL_TEXTURE_2D);
|
|
}
|
|
else
|
|
{
|
|
std::cout << "Failed to load texture" << std::endl;
|
|
}
|
|
stbi_image_free(data);
|
|
}
|
|
|
|
void activate(int id)
|
|
{
|
|
glActiveTexture(GL_TEXTURE0 + id);
|
|
glBindTexture(GL_TEXTURE_2D, ID);
|
|
}
|
|
};
|
|
|
|
#endif
|
|
|