Jump to content

  • Log In with Google      Sign In   
  • Create Account


Lesson 6 - not compiling question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Omnislash8   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 December 2010 - 06:06 PM

I get the error "initialization failed" when I run the program. Apparently my .bmp file does not exist, but I have created it and it is in the Resources folder in my project.

if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))

I have tried changing that line to just "/NeHe.bmp", "NeHe.bmp" and many other derivatives of that. I tried changing the type to 24-bit bmp, 16-color bmp, monochrome bmp, 256-color bmp, etc.

I don't seem to see what I am doing wrong here. I made the bmp originally and just dragged it into the Resources folder of my project from My Pictures. Can anyone give me an idea of how to go about debugging this? Any help is appreciated, thanks.

Sponsor:

#2 Omnislash8   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 December 2010 - 06:19 PM

I copied the code from the tutorial, but it may still be helpful to post it here. Maybe its a problem with fopen?






AUX_RGBImageRec *LoadBMP(char *Filename) { // Loads A Bitmap Image

FILE *File=NULL; // File Handle
MessageBox(NULL, Filename, "ERROR", MB_OK);
if (!Filename) // Make Sure A Filename Was Given
return NULL; // If Not Return NULL

File=fopen(Filename, "r"); // Check To See If The File Exists
if(File==NULL)
MessageBox(NULL, "File is null", "ERROR", MB_OK);

if (File) {
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}

return NULL; // If Load Failed Return NULL
}

int LoadGLTextures() { // Load Bitmaps And Convert To Textures

int Status=FALSE; // Status Indicator

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture

memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(1, &texture[0]); // Create The Texture

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
// Generate The Texture
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); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
} //end if

if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}

free(TextureImage[0]); // Free The Image Structure
}
return Status; // Return The Status
}



#3 lc_overlord   Members   -  Reputation: 435

Like
0Likes
Like

Posted 20 December 2010 - 09:49 PM

Loading BMP files is a pretty buggy process, this code has been known to not like newly created files, test if it works with the original file, if it does your only option is to abandon using BMP files and directly skip ahead a bit to lesson 24 and 33 and get the TGA code from there, though to be honest there is still a similar bug in the code, so if your having problems with TGAs too then just let me know as there is an even newer much better code available(written by yours truly), though for some reason its unreleased.

#4 HowardStern   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 December 2010 - 10:54 PM

Hi, I was just reading this tutorial yesterday and I had a similar compilation error. The problem seems to be unicode.

auxDIBImageLoad() expects a LPCWSTR rather than char*. Although char* is automatically casted to a unicode string, it ends up on a wrong code page or something. Try casting Filename to an LPWSTR using MultiByteToWideChar. Heres what I did:


AUX_RGBImageRec *LoadBMP(char* file) {
FILE *f = NULL;
int fileLen = strlen(file) + 1;
LPWSTR wfile = SysAllocStringLen(0, fileLen);
MultiByteToWideChar(CP_ACP, NULL, file, -1, wfile, fileLen);

if(!file) {
return NULL;
}

f = fopen(file, "r");

if(!f) {
return NULL;
}

fclose(f);
return auxDIBImageLoad(wfile);
}



Greetings,
HowardStern




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS