Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Use glGenTextures every time I load a Texture?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    7

    Use glGenTextures every time I load a Texture?

    Hi!
    If I have a texture class:

    Code :
    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?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,109
    This class doesn't make sense. Typcally a texture class looks after only 1 texture. You load the texture once and bind it a texture binding point anytime you wish to render with it. So "load" should not call

    "Initialize" and "Initialize" should have a parameter saying what texture bind point to activate not just "+n_texture".

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    Instead of Initialize, call it BindTexture.

    Why have you hard coded values in your Load function? You should pick up that information from the file itself (Is it 24 bpp or 32 bpp, is it RGBA or BGRA?).
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •