Jump to content
  • Advertisement
Sign in to follow this  
jon723

Distorted texture map

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

Hello, Im trying to texture map an object with a jpeg image. The image loads correctly but when I display the object the image is distorted (i.e. displaying colors that are not part of the image) can someone tell me what is going wrong with this code??
bool CreateTexture(UINT* Array, const char* FileName, int ID)
{
	Fl_JPEG_Image* pJpegImage = NULL;
	
	if(!FileName)
		return false;

	string TextureName(FileName);  // create a string from the filename


	// if the user has selected that they want to create a bolt then a bolt reference geometry has to be created
	if(TextureName.indexof(".JPG"))
	{
		pJpegImage = new Fl_JPEG_Image(FileName);
		if(pJpegImage->data() == NULL)
		{
			return false;	// the data for this image was bad
		}
	}

	if(pJpegImage != NULL)
	{
		glGenTextures(1, &Array[ID]);
//		glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

		glBindTexture(GL_TEXTURE_2D, Array[ID]);

		gluBuild2DMipmaps(GL_TEXTURE_2D, 4, pJpegImage->w(), pJpegImage->h(), GL_RGBA, GL_UNSIGNED_BYTE, pJpegImage->data());
	
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
	}

		pJpegImage->uncache();
	//	delete pJpegImage;
	//	pJpegImage = NULL;


	return true;
}


Share this post


Link to post
Share on other sites
Advertisement
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, pJpegImage->w(), pJpegImage->h(), GL_RGBA, GL_UNSIGNED_BYTE, pJpegImage->data());

I don't think this is right. JPGs only have RGB data = 3 components. Try something like:

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pJpegImage->w(), pJpegImage->h(), GL_RGB, GL_UNSIGNED_BYTE, pJpegImage->data());

Share this post


Link to post
Share on other sites
Are you sure your jpeg has 4 color channels (rgba)? Jpeg doesnt support alpha, really, so I'd be surprised. Try changing your call to gluBuild2DMipmaps to use '3' and 'GL_RGB'... that or make sure your image library is converting it to RGBA on load.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!