2 u014623234 u014623234 于 2014.05.21 16:03 提问

opengl在mfc中载入一副BMP文件作为纹理,编译链接都通过了但运行时就提示停止工作
HBITMAP hBMP;//定义BMP头
BITMAP  BMP;//BMP结构体
//byte  Texture[]={IDB_BITMAP3};
byte  Texture[]={IDB_BITMAP4};
glGenTextures(sizeof(Texture), &texture[0]);// Generate 6 Textures (sizeof(Texture)=6 ID's)
for(int loop=0;loop<sizeof(Texture); loop++)// Loop Through All The ID's (Bitmap Images)
{
    hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(Texture[loop]),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
    if (hBMP)                                               // Does The Bitmap Exist?
    {                                                       // If So...
        GetObject(hBMP,sizeof(BMP), &BMP);//                    // Get The Object
        // hBMP: Handle To Graphics Object
        // sizeof(BMP): Size Of Buffer For Object Information
        // Buffer For Object Information
        glPixelStorei(GL_UNPACK_ALIGNMENT,4);// Pixel Storage Mode (Word Alignment / 4 Bytes)
        glBindTexture(GL_TEXTURE_2D, texture[loop]);// Bind Our Texture
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); // Mipmap Linear Filtering
        // Generate Mipmapped Texture (3 Bytes, Width, Height And Data From The BMP)
        gluBuild2DMipmaps(GL_TEXTURE_2D,3,BMP.bmWidth,BMP.bmHeight,GL_BGR_EXT,GL_UNSIGNED_BYTE,BMP.bmBits);
        DeleteObject(hBMP);// Delete The Bitmap Object
    }
}
glClearColor(0.0f,0.0f,0.0f,1.0f);//清除背景颜色
glEnable(GL_TEXTURE_2D);//启用纹理模式
glEnable(GL_DEPTH_TEST);//启动深度测试
glMatrixMode(GL_PROJECTION);//投影
glLoadIdentity();
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!