Jump to content
  • Advertisement
Sign in to follow this  
Dannyli

OpenGL problem with the texture loading in opengl

This topic is 2023 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

void texload(int i,char *filename)
{
    BITMAPINFOHEADER bitmapInfoHeader;                                 
	unsigned char*   bitmapData;                                       

   bitmapData = LoadBitmapFile(filename, &bitmapInfoHeader);
   glBindTexture(GL_TEXTURE_2D, texture);  
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);//filter

	glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE,bitmapData);	
}  

 

  The compiler throw out exception on the line

 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB,bitmapInfoHeader.biWidth,bitmapInfoHeader.biHeight,0,GL_RGB,GL_UNSIGNED_BYTE,bitmapData); 

 

My BMP file is 252x255, is that too big for my function?

Share this post


Link to post
Share on other sites
Advertisement

252x255 is small for a texture.  However, it's dimensions are not a power of two - have you checked for non-power-of-two support first?

 

Also be aware when loading textures that your width * bytes-per-pixel needs to be a multiple of 4, otherwise you will need to set glPixelStorei appropriately.  That's not relevant here because 252x3 is a multiple of 4, but you need to know for the future that you can't just go passing arbitrary data and dimensions to OpenGL and expect it to work.

 

What's most likely the cause is that you're not doing any error checking of the result from your call to LoadBitmapFile.  Are you totally certain that it's loaded the file OK?  What happens when you run it in your debugger?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!