Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Billy Lee

Problem loading textures

This topic is 5985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been following the NeHe tutorials up to and including the texture mapping section and they work fine. However, I have made several small alterations along the way. The texture mapping tutorial shows how to apply a texture map onto a cube but I want to change it to apply six texture maps - one for each side of the cube. I''m just working with two texture maps for now to see if it works. I have split the program into several files and the texture mapping one looks like this: #include // Header File For Standard Input/Output #include GLuint texture[2]; // Storage For Two Textures AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image { FILE *File=NULL; // File Handle 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) // Does The File Exist? { fclose(File); // Close The Handle return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer } return NULL; // If Load Failed Return NULL } // End of method AUX_RGBImageRec int LoadGLTextures() // Load Bitmaps And Convert To Textures { const int NumTextures = 2; // The number of textures int Status = FALSE; // Status Indicator For Texture Loaded/Built AUX_RGBImageRec *TextureImage[NumTextures]; // Create Storage Space For The Textures 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/MSG_BJ.bmp")) && (TextureImage[1]=LoadBMP("Data/MSG_BJ_Brit.bmp"))) { Status = TRUE; // Set The Status To TRUE glGenTextures(NumTextures, &texture[0]); // Create The Texture // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture[0]); glBindTexture(GL_TEXTURE_2D, texture[1]); // Generate The Texture glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->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 } // Free up any ram containing bitmap data for (int count = 0; count < NumTextures; count++) { if (TextureImage[count]) // If Texture Exists { if (TextureImage[count]->data) // If Texture Image Exists { free(TextureImage[count]->data); // Free The Texture Image Memory } free(TextureImage[count]); // Free The Image Structure } } // End for return Status; // Return The Status } // End of method LoadGLTextures It compiles but when I run it, it says ''Initialisation failed''. It seems to fail on the bit highlighted in bold. I''ve run the debugger and that if statement is false. Also, is AUX_RGBImageRec *TextureImage[NumTextures]; correct when NumTextures = 2 to create storage space for 2 texture maps? And what about glGenTextures(NumTextures, &texture[0]); ?

Share this post

Link to post
Share on other sites
Good news for you!

This subject has been covered in detail under another thread which can be found in this thread:

[edited by - CyberneticDreams on July 30, 2002 7:48:28 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!