Archived

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

Luya

Unable to load the bmp texture

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites