【发布时间】:2010-12-15 11:04:06
【问题描述】:
知道我的代码有什么问题吗?当我执行 glCompressedTexImage2D() 时,程序会崩溃(出现 Windows XP 崩溃消息...)
我正在尝试加载没有 mipmaps 的 DDS 图像,图像格式是 DDS DXT1
我是否缺少一些包含文件,或者我做错了什么? 我从以下位置下载了包含的文件: http://sourceforge.net/projects/glew/files/glew/1.5.1/glew-1.5.1-win32.zip/download
我的 .exe 所在的文件夹中有 glew32.dll。
下面的代码只有我为了能够加载 DDS 图像而更改的部分:
#pragma comment(lib, "glew32.lib")
#include <GL\glew.h>
#include <GL\gl.h>
...
typedef struct {
GLuint dwSize;
GLuint dwFlags;
GLuint dwFourCC;
GLuint dwRGBBitCount;
GLuint dwRBitMask;
GLuint dwGBitMask;
GLuint dwBBitMask;
GLuint dwABitMask;
} DDS_PIXELFORMAT;
typedef struct {
GLuint dwMagic;
GLuint dwSize;
GLuint dwFlags;
GLuint dwHeight;
GLuint dwWidth;
GLuint dwLinearSize;
GLuint dwDepth;
GLuint dwMipMapCount;
GLuint dwReserved1[11];
DDS_PIXELFORMAT ddpf;
GLuint dwCaps;
GLuint dwCaps2;
GLuint dwCaps3;
GLuint dwCaps4;
GLuint dwReserved2;
} DDS_HEADER;
DDS_HEADER DDS_headers;
...
FILE *fp = fopen("test.dds", "rb");
fread(&DDS_headers, 1, sizeof(DDS_headers), fp);
img_width = DDS_headers.dwWidth;
img_height = DDS_headers.dwHeight;
maxsize = (img_width*img_height)/2;
unsigned char *imgdata = (unsigned char *)malloc(maxsize);
fread(imgdata, 1, maxsize, fp);
fclose(fp);
GLuint texID;
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_PALETTE4_R5_G6_B5_OES, img_width, img_height, 0, maxsize, imgdata);
// NOTICE:
// Ive also tried with function:
// glCompressedTexImage2DARB();
// and internalformats: GL_COMPRESSED_RGB_S3TC_DXT1_EXT and all of the possible formats... its not a format error.
【问题讨论】:
-
请,如果您想要 DXT1,请将 DXT1 放入 glCompressedTexImage2D 调用中。将PALETTE 保留在那里没有任何意义。现在,在调用 glCompressedTexImage2D 时,img_width/img_height/maxsize/imgdata 的值是多少?
-
我认为问题出在初始化/包含文件上,我现在通过其他一些代码让 DDS 加载工作正常了,无论如何感谢您的帮助。
标签: c++ opengl directdraw dds-format