Hi!
If I have a texture class:
Texture::Texture(){};
Texture::~Texture()
{
glDeleteTextures(1, &ID);
ExitOnGLError("ERROR: Could not destroy the textures");
};
void Texture::Initialize(void)
{
glActiveTexture(GL_TEXTURE0+n_texture);
n_texture++;
glBindTexture(GL_TEXTURE_2D, ID);
ExitOnGLError("Error: Could not bind the texture");
}
void Texture::Load(std::string filename)
{
name = filename;
FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(filename.c_str(),0);
// Si no soporta el formato, lanzamos error
if(!FreeImage_FIFSupportsReading(formato))
{
ExitOnGLError("ERROR: Formato de textura no soportado");
exit(EXIT_FAILURE);
}
FIBITMAP* imagen = FreeImage_Load(formato, filename.c_str());
imagen = FreeImage_ConvertTo32Bits(imagen);
width = FreeImage_GetWidth(imagen);
height = FreeImage_GetHeight(imagen);
pixels = (char*)FreeImage_GetBits(imagen);
std::cout<<"PIXELES"<<pixels[0 ]<<std::endl;
// Gneramos la textura para OpenGL
glGenTextures(1,&ID);
glBindTexture(GL_TEXTURE_2D, ID);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, width, height, 0, GL_BGRA,GL_UNSIGNED_BYTE,pixels );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glGenerateMipmap(GL_TEXTURE_2D);
FreeImage_Unload(imagen); // Descartamos la imagen
Initialize();
}
If every time that I load a texture, i call this method, Does it load fine the textures? or Should I load the textures at the same time?