コード例 #1
0
ファイル: Texture.cpp プロジェクト: siquel/yam2d
Texture::Texture(const std::string& fileName, bool allowNPOT)
: m_nativeIds(0)
, m_width(0)
, m_height(0)
, m_bpp(0)
, m_data(0)
, m_numNativeIds(1)
{
	m_nativeIds = (unsigned int*)new int[m_numNativeIds];	
	glGenTextures(m_numNativeIds, m_nativeIds);

	if( false == esLoadPNG(fileName.c_str(), 0, &m_width, &m_height, &m_bpp ) )
	{
		return;
	}
	
	if( allowNPOT==false && !isNpotSquare(m_width,m_height) )
	{
		esLogEngineDebug("Image %s, is not NPOT Square texture (w:%d, h:%d, bpp:%d)",
			fileName.c_str(), m_width, m_height, m_bpp );
	}

	m_data = new unsigned char[m_width*m_height*m_bpp];
	if( false == esLoadPNG(fileName.c_str(), m_data, &m_width, &m_height, &m_bpp ) )
	{
		return;
	}

	esLogEngineDebug("[%s] Image loaded w:%d, h:%d, bpp:%d", __FUNCTION__, m_width, m_height, m_bpp);
	
	setData(m_data,m_width,m_height,m_bpp,0);
}
コード例 #2
0
///
// Load texture from disk
//
GLuint LoadTexture ( char *fileName )
{
    int width,
        height;
    char *buffer = esLoadPNG ( fileName, &width, &height );
    GLuint texId;

    if ( buffer == NULL )
    {
        esLogMessage ( "Error loading (%s) image.\n", fileName );
        return 0;
    }

    glGenTextures ( 1, &texId );
    glBindTexture ( GL_TEXTURE_2D, texId );

    glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

    free ( buffer );

    return texId;
}
コード例 #3
0
ファイル: Model3D.c プロジェクト: eslinux/OpenglES
///
// Load texture from disk
//
static GLuint LoadTexture ( char *fileName )
{
    int width,
    height;
    char hasAlpha =0;
    char *buffer=NULL;
    GLuint texId;

    if(strstr(fileName,"tga")!=NULL){
        buffer=esLoadTGA ( fileName, &width, &height );
    }else if(strstr(fileName,"bmp") !=NULL){
        Image *image1;
        // allocate space for texture we will use
        image1 = (Image *) malloc(sizeof(Image));

        if(esLoadBMP ( fileName, image1 ) == 0)
        {
            return 0;
        }
        width = image1->sizeX;
        height = image1->sizeY;
        buffer=image1->data;
    }else if(strstr(fileName,"png") !=NULL){
        buffer= esLoadPNG(fileName,&width, &height, &hasAlpha);
    } else if(strstr(fileName,"jpg") !=NULL){
#if 0
        texId = SOIL_load_OGL_texture(fileName,
                              SOIL_LOAD_AUTO,
                              SOIL_CREATE_NEW_ID,
                              SOIL_FLAG_POWER_OF_TWO |
                              SOIL_FLAG_MIPMAPS |
                              SOIL_FLAG_COMPRESS_TO_DXT);
        return texId;
#endif
    }


    if ( buffer == NULL )
    {
        esLogMessage ( "Error loading (%s) image.\n", fileName );
        return 0;
    }

    glGenTextures ( 1, &texId );
    glBindTexture ( GL_TEXTURE_2D, texId );
    glTexImage2D ( GL_TEXTURE_2D, 0, hasAlpha ? GL_RGBA : GL_RGB, width, height, 0,  hasAlpha ? GL_RGBA : GL_RGB , GL_UNSIGNED_BYTE, buffer);
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

    free ( buffer );
    return texId;
}