问题描述
- 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_BITMAP00LR_CREATEDIBSECTION); if (hBMP) // Does The Bitmap Exist? { // If So... GetObject(hBMPsizeof(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_ALIGNMENT4);// Pixel Storage Mode (Word Alignment / 4 Bytes) glBindTexture(GL_TEXTURE_2D texture[loop]);// Bind Our Texture glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MAG_FILTERGL_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2DGL_TEXTURE_MIN_FILTERGL_LINEAR_MIPMAP_LINEAR); // Mipmap Linear Filtering // Generate Mipmapped Texture (3 Bytes Width Height And Data From The BMP) gluBuild2DMipmaps(GL_TEXTURE_2D3BMP.bmWidthBMP.bmHeightGL_BGR_EXTGL_UNSIGNED_BYTEBMP.bmBits); DeleteObject(hBMP);// Delete The Bitmap Object }}glClearColor(0.0f0.0f0.0f1.0f);//清除背景颜色glEnable(GL_TEXTURE_2D);//启用纹理模式glEnable(GL_DEPTH_TEST);//启动深度测试glMatrixMode(GL_PROJECTION);//投影glLoadIdentity();
时间: 2024-08-29 02:34:43