在visual studio 2008中加载bmp图像

时间:2011-12-20 00:17:23

标签: .net visual-c++ opengl

我在将bmp图像作为背景纹理加载到项目中时遇到问题 该程序显示出问题。相反,它给我一个白色的背景 这就是我加载它的方式:

void makeTexture(char * path,int i)
{   
    teximage[i]=auxDIBImageLoadA(path);
    glGenTextures(i,&tex[i]);
    glBindTexture(GL_TEXTURE_2D,tex[i]);
    glTexImage2D(GL_TEXTURE_2D,0,3,teximage[i]->sizeX,teximage[i]->sizeY,
        0,GL_RGB, GL_UNSIGNED_BYTE, teximage[i]->data);
    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_DECAL);
}
bool setTexture()
{
      //load the images
      memset(teximage,0,sizeof(void *)*1);  //init the array

      makeTexture("6.bmp",0);
      return true;
}

1 个答案:

答案 0 :(得分:0)

在上传像素数据之前尝试设置滤镜模式:

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_DECAL); 
glTexImage2D(GL_TEXTURE_2D, 0, 3, teximage[i]->sizeX, teximage[i]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, teximage[i]->data);