Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Texture class
- class Texture {
- public:
- GLuint handle;
- Texture();
- virtual ~Texture();
- void loadData (int w, int h, int chan, GLenum format, void* data);
- void enable();
- };
- Texture::Texture() {
- handle = 0;
- }
- void Texture::loadData(int w, int h, int chan, GLenum format, void* data)
- {
- glGenTextures(1, &handle);
- enable();
- // Bilinear filtering
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // Clamp: texture ends at edges
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- // Create the texture
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexImage2D(GL_TEXTURE_2D, 0, chan, w, h, 0, format, GL_UNSIGNED_BYTE, data);
- //gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, format, GL_UNSIGNED_BYTE, data);
- }
- void Texture::enable()
- {
- glBindTexture(GL_TEXTURE_2D, handle);
- }
- Texture::~Texture() {
- if (handle != 0)
- glDeleteTextures(1, &handle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement