[ogl] texturen mapping



  • hi

    soll ich für die inistalisierung einer textur glaux.lib includieren und

    ...
    AUX_RGBImageRec *LoadBMP(char *Filename)
    ...
    

    verwenden oder doch leiber so:

    ...
    void slgl::Texture::SetParams(const bool BuildMipMaps) const
    {
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        if (BuildMipMaps) glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP,TRUE);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    }
    
    HRESULT slgl::Texture::LoadFromBMP(char *pFilename,const bool BuildMipMaps)
    {
        std::ifstream       file;
    	BITMAPFILEHEADER	FileHeader; 
    	BITMAPINFOHEADER	InfoHeader;
    
        file.open(pFilename,std::ios_base::in | std::ios_base::binary);
        if (!file.is_open())  return E_FAIL;
    
    	file.read((char*)&FileHeader, sizeof(FileHeader));
    	file.read((char*)&InfoHeader, sizeof(InfoHeader));
    
        if (FileHeader.bfType!='MB' || InfoHeader.biBitCount==32)
        {
            file.close();
            return E_FAIL;
        }
    
        m_Width   =InfoHeader.biWidth;
        m_Height  =InfoHeader.biHeight;
        m_DataType=GL_UNSIGNED_BYTE;
    
        m_BytesPerPixel=InfoHeader.biBitCount/8;
        BYTE *pData;
    
        switch(InfoHeader.biBitCount)
        {
            case 8:
            {
                m_Format=GL_RGB;
                m_BytesPerPixel=3;
    
                const DWORD NumColors=1 << InfoHeader.biBitCount;
                RGBQUAD *ColorTable=new RGBQUAD[NumColors];
                file.read((char*)ColorTable,sizeof(RGBQUAD)*NumColors);
                pData=new BYTE[m_Width*m_Height*3];
                BYTE *pIndices=new BYTE[m_Width*m_Height];
                file.read((char*)pIndices,sizeof(BYTE)*m_Width*m_Height);
                for (DWORD i=0; i<m_Width*m_Height; i++)
                {
                    pData[i*3  ]=ColorTable[pIndices[i]].rgbBlue;
                    pData[i*3+1]=ColorTable[pIndices[i]].rgbGreen;
                    pData[i*3+2]=ColorTable[pIndices[i]].rgbRed;
                }
    
                delete[] pIndices;
                delete[] ColorTable;
            } break;
    
            case 24:
            case 32:
            {
                if (m_BytesPerPixel==3) m_Format=GL_RGB; else m_Format=GL_RGBA;
    
                pData=new BYTE[GetImageSize()];
                if (!pData)
                {
                    file.close();
                    return E_FAIL;
                }
                file.read((char*)pData,GetImageSize());
            } break;
        }
    
        for (DWORD i=0; i<m_Width*m_Height; i++)
    	{
    		pData[i*m_BytesPerPixel] ^= pData[i*m_BytesPerPixel+2] ^= 
            pData[i*m_BytesPerPixel] ^= pData[i*m_BytesPerPixel+2];
    	}
    
        glGenTextures(1,&m_ID);
    
        glBindTexture(GL_TEXTURE_2D,m_ID);
    
        SetParams(BuildMipMaps);
    
        glTexImage2D(GL_TEXTURE_2D,0,m_BytesPerPixel,m_Width,m_Height,0,m_Format,m_DataType,pData);
        delete[] pData;
    
        file.close();
    
        return S_OK;
    ...
    }
    


  • a) Schlau: GLAUX und GLUT nicht mehr verwenden.
    b) Schlauer: Eine Lib verwenden von Leuten, die wissen was sie tun, und nicht eigene zusammengehackte Funktionen, die nur unter bestimmten Planetenkonstellationen funktionieren. In diesem Fall: DevIL
    c) Am Schlauesten: Direct3D verwenden! :p

    Nein, das letzte war natürlich nur Flame. 🤡

    Und der Rest ist natürlich auch nur meine Meinung. Die Loader-Funktionen für TGA und BMP von NeHe funktionieren jedenfalls nur bei bestimmten Dateien. ...und wenn der Wind aus Nordosten kommt.



  • glut ist scheiße aber glaux verwende ich denk ich


Anmelden zum Antworten