31 lines
1.0 KiB
C++
31 lines
1.0 KiB
C++
#include <iostream>
|
|
|
|
#include "texture.h"
|
|
|
|
|
|
Texture::Texture()
|
|
: Width(0), Height(0), Internal_Format(GL_RGBA), Image_Format(GL_RGBA), Wrap_S(GL_REPEAT), Wrap_T(GL_REPEAT), Filter_Min(GL_LINEAR), Filter_Mag(GL_NEAREST)
|
|
{
|
|
glGenTextures(1, &this->ID);
|
|
}
|
|
|
|
void Texture::generate(GLuint width, GLuint height, unsigned char* data)
|
|
{
|
|
this->Width = width;
|
|
this->Height = height;
|
|
// Create Texture
|
|
glBindTexture(GL_TEXTURE_2D, this->ID);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, this->Internal_Format, width, height, 0, this->Image_Format, GL_UNSIGNED_BYTE, data);
|
|
// Set Texture wrap and filter modes
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, this->Wrap_S);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, this->Wrap_T);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, this->Filter_Min);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, this->Filter_Mag);
|
|
// Unbind texture
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
}
|
|
|
|
void Texture::bind() const
|
|
{
|
|
glBindTexture(GL_TEXTURE_2D, this->ID);
|
|
} |