GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


something amiss with glTexEnv ? by godecho
1
 
Texture TexMgr::TextureHandler::LoadTGA(const char *filename, const bool &genMipmaps)            // Load a TGA file
{
    /*    That third value of the TGA header is the image type, described below
    
        Image
        Type    Description

        0        No Image Data Included 
        1        Uncompressed, Color-mapped Image 
        2        Uncompressed, True-color Image 
        3        Uncompressed, Black-and-white Image
        9        Run-length encoded, Color-mapped Image 
        10        Run-length encoded, True-color Image        <-- this is the one we can load
        11        Run-length encoded, Black-and-white Image
    */
    
    if(filename)
    {
        FILE *infile;
        infile = fopen(filename, "rb");

        if(infile)
        {
            Texture texture;
            GLubyte tgaheader[12];
            
            fread(&tgaheader, sizeof(tgaheader), 1, infile);

            if(tgaheader[2] == 10)
            {
                if(LoadCompressedTGA(texture, filename, infile))
                {
                    glGenTextures(1, &texture.texID);
                    
                    glBindTexture(GL_TEXTURE_2D, texture.texID);
                    
                    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter);
                    //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

                    if(genMipmaps)
                    {
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
                        gluBuild2DMipmaps(GL_TEXTURE_2D, texture.type, texture.width, texture.height, texture.type, GL_UNSIGNED_BYTE, texture.pImageData);
                    }    
                    else
                    {
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ((textureQuality > 1) ? GL_LINEAR : minFilter));
                        glTexImage2D(GL_TEXTURE_2D, 0, texture.type, texture.width, texture.height, 0, texture.type, GL_UNSIGNED_BYTE, texture.pImageData);
                    }

                    delete [] texture.pImageData;
                    texture.pImageData = 0;
                    
                    fclose(infile);
                    return texture;
                }
                else
                {
                    ConsoleMgr::Inst()->AddText("Unable to load texture: %s", filename);
                }
            }
            else
            {
                ConsoleMgr::Inst()->AddText("This file is TGA type: %i. TGA file must be type 10", int(tgaheader[2]));
            }
            fclose(infile);
        }
        else
        {
            ConsoleMgr::Inst()->AddText("Unable to open texture: %s", filename);
        }
    }

    return *defaultTexture;
}