Unable to load the bmp texture

Started by
4 comments, last by Luya 21 years, 1 month ago
The code runs fine. However the texture does not display. Here is the source. The variable used for texture datas are: unsigned char* bmpData[1]; // The texture data GLuint iTexture[1]; // The texture object
  
int LoadTextures()
{
	int iStatus = false;
	
	memset(bmpData,0,sizeof(void *)*1);				// Set The Pointer To NULL

	
	if(bmpData[0] = LoadBMP("Data/muandi3.bmp", &bmpInfoHeader))
	{
		iStatus = true;
        
        glGenTextures(1, &iTexture[0]);           // Generate texture object

        glBindTexture(GL_TEXTURE_2D, iTexture[0]); // Bind the texture

	
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   	
   		// Load the texture image

	    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmpInfoHeader.biWidth,
	             bmpInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
	             bmpData);
     }
     
     if (bmpData[0])							// If Texture Exists

	{
		free(bmpData[0]);						// Free The Image Structure

	}
	
	return iStatus;
}
  
What is wrong with the code?
Advertisement
1.Try:

    glTexImage2D(GL_TEXTURE_2D, 0, 3, bmpInfoHeader.biWidth, bmpInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,	             bmpData);    

2.Are width and height powers of two?
EDIT: Check for errors!
3.If it doesn't work, post some texture-displaying code...



PM

Times change...

Excuse my poor english!

[edited by - PM on March 16, 2003 4:18:57 AM]
PM Times change...Excuse my poor english!
Try changing bmpData to bmpData[0] in the glTexImage2D command.

Enigma

[edited by - Enigma on March 16, 2003 7:26:12 AM]
The .exe crashed with that modification. As I use a custom function to load BMP file without GLaux.

Here is the source:


  int LoadTextures(){	int iStatus = false;		memset(bmpData[0],0,sizeof(void *)*1);				// Set The Pointer To NULL		if(bmpData[0] = LoadBMP("Data/muandi4.bmp", &bmpInfoHeader))	{		iStatus = true;                glGenTextures(1, &iTexture[0]);           // Generate texture object        glBindTexture(GL_TEXTURE_2D, iTexture[0]); // Bind the texture	        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);   	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);   	   		// Load the texture image	    glTexImage2D(GL_TEXTURE_2D, 0, 3, bmpInfoHeader.biWidth,	             bmpInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,	             bmpData[0]);     }          if (bmpData[0])							// If Texture Exists	{		free(bmpData[0]);						// Free The Image Structure	}		return iStatus;}int InitGL(GLvoid)										// All Setup For OpenGL Goes Here{	if(!LoadTextures())	// Return false if texture doesn''t load 	   return false;	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);				// Black Background	glClearDepth(1.0f);									// Depth Buffer Setup	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing//	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do//	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations    glEnable(GL_CULL_FACE);    glFrontFace(GL_CCW);	glEnable(GL_TEXTURE_2D);	// Load our bitmap file				return true;										// Initialization Went OK}  
What is the type of bmpData and where does it get initialised? From the look of your code it should be a GLubyte**. If it''s just a GLubyte* then change all the bmpData[0]''s to just bmpData. Also make sure your LoadBMP function is allocating a new GLubyte* and returning it.

Enigma
Thank you very much, your suggestion worked.

This topic is closed to new replies.

Advertisement