我的项目有一个大问题:
我喜欢NeHe网站上的教程,Windows XP可以完美运行程序。但是,当我重新格式化电脑,将操作系统更改为Windows Vista并重新安装Dev-C++编译器后,尝试打开任何使用纹理的C++程序时,程序崩溃了。
我发现我的glaux.h文件丢失了。我在互联网上找到了这个文件并重新编译了我的项目,但它仍然崩溃了。当我排除纹理函数时,一切都顺利。
问题出在哪里?我该怎么解决?
我想这其中有一个罪魁祸首:
Windows Vista操作系统、我的显卡、glaux.h和库(我知道它有漏洞)、OpenGL本身。
.
更新:我确定了问题的来源。
这段代码导致我的程序崩溃:
if (TextureImage[0]) {
if (TextureImage[0]->data) {
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
由于某些原因,每当我让程序释放内存时,它总是崩溃。当我注释掉这一部分时,我的程序可以正常工作,只是颜色变深了(我想这是由于位图文件的颜色)。有什么建议吗?
回复Matias Valdenegro:
好吧,这是从NeHe lesson6导出的,在我还使用Windows XP时运行良好。当我切换到Windows Vista时,绝对没有任何更改。
只是让你知道,这是整个函数:
#define NoOfTextures 3
GLuint texture[NoOfTextures];
int LoadGLTextures()
{
int Status=FALSE;
AUX_RGBImageRec *TextureImage[NoOfTextures];
memset(TextureImage,0,sizeof(void *)*1);
if (TextureImage[0]=LoadBMP("Data/Bitmaps/texture.bmp"))
{
Status=TRUE;
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
if (TextureImage[0] != NULL) {
if (TextureImage[0]->data != NULL) {
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
}
return Status;
}
附加信息:
我经常重新构建我的项目,LoadBMP()是同一个头文件的一部分。这是LoadBMP()函数:
AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL;
if (!Filename)
{
return NULL;
}
File=fopen(Filename,"r");
if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}
return NULL;
}
这对我来说似乎非常明确。