bool COpenGLES::CreatePNGTexture(GLuint texID, const CString filename) { printf("png图片路径=%s\n",filename); CxImage * image = new CxImage(); image->Destroy(); unsigned char *pImage_RGBA = NULL; if(!(image->Load(filename,CXIMAGE_FORMAT_PNG))) { printf("加载图片失败\n"); return false; } if(!image->IsValid()) { printf("图片不可用\n"); return false; } int sizeX,sizeY; sizeX = image->GetWidth(); sizeY = image->GetHeight(); if(!image->AlphaIsValid()) { printf("alpha层错误\n"); return false; } long imageSize_RGBA = sizeX * sizeY * 4; //pImage_RGBA = new unsigned char[imageSize_RGBA]; image->Encode2RGBA(pImage_RGBA,imageSize_RGBA); glBindTexture(GL_TEXTURE_2D, texID); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sizeX, sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, pImage_RGBA); image->FreeMemory( pImage_RGBA); image->Destroy(); delete image; }