Here's a BIG problem with my project:
I love the tutorials on the NeHe website, and Windows XP ran the programs perfectly. However, when I reformatted my computer, changed the OS to Windows Vista and reinstalled my Dev-C++ compiler, and then I tried to open any C++ program that used textures, the program crashed.
I realised my glaux.h went missing. I found the file on the Internet and recompiled my project, but it still crashed. Everything went well when I excluded the texture functions.
Where does the problem lie and what can I do to solve it?
I was thinking one of these is the culprit: Windows Vista OS, my graphics card, glaux.h and libraries (I know it's bugged), OpenGL itself.
.
Update: I determined the source of the problem.
This chunk of code caused my program to crash:
if (TextureImage[0]) {
if (TextureImage[0]->data) {
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
For some reason, my program always crashes whenever I order it to free memory. When I commented this section off, my program works fine, except that all the colours went dark (I'm thinking it's because of the colours of my bitmap file). Any tips?
.
Reply to: Matias Valdenegro
Well, this was derived from NeHe lesson6 which worked fine when I still used Windows XP. Absolutely nothing was changed when I switched to Windows Vista.
Just so you know, here's the entire function:
#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;
}
.
Additional Information:
I rebuild my project often and LoadBMP() is part of the same header file. This is the LoadBMP() function:
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;
}
This seems pretty clear cut to me.