Jump to content
  • Advertisement
Sign in to follow this  
BrknPhoenix

Any clue why this texture mapping isn't working?

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

Alright, for some reason my mapping of this terrain just isn't working out. Here is where I'm loading the texture...
void Terrain::loadTextures()
{
	if (!(m_targaLoader->LoadTarga(&m_ground, "grass.tga"))) exit(1);	
	glGenTextures(1, &m_ground.id);
	glBindTexture(GL_TEXTURE_2D, m_ground.id);
	glTexImage2D(GL_TEXTURE_2D, 0, 4, m_ground.width, m_ground.height, 0, m_ground.type, GL_UNSIGNED_BYTE, m_ground.image_data);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);	
}
We can take for granted that the targa loader works because I tested it in a program that was already working, and it was fine. Same for the image itself. Here's where the drawing gets done.
void Terrain::draw()
{
	glColor3f(1.0f, 1.0f, 1.0f);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, m_ground.id);		

	for (int row = 0; row < m_mapWidth; row++)
	{
		for (int column = 0; column < m_mapHeight; column++)
		{	
			glBegin(GL_QUADS);
				glTexCoord2f(0.0f, 1.0f); glVertex3f(m_tileWidth * column, -(m_tileHeight * row), m_zPos + m_heightMap[4 * ((row * m_mapWidth) + column)]);
				glTexCoord2f(0.0f, 0.0f); glVertex3f(m_tileWidth * column, -(m_tileHeight + (m_tileHeight * row)), m_zPos + m_heightMap[4 * ((row * m_mapWidth) + column) + 1]);
				glTexCoord2f(1.0f, 0.0f); glVertex3f(m_tileWidth + (m_tileWidth * column), -(m_tileHeight + (m_tileHeight * row)), m_zPos + m_heightMap[4 * ((row * m_mapWidth) + column) + 2]);				
				glTexCoord2f(1.0f, 1.0f); glVertex3f(m_tileWidth + (m_tileWidth * column), -(m_tileHeight * row), m_zPos + m_heightMap[4 * ((row * m_mapWidth) + column) + 3]);				
			glEnd();
		}		
	}
}
Everything is white, it's not loading the texture. Can't quite figure out why, as I've done this before... I must be missing something small...

Share this post


Link to post
Share on other sites
Advertisement
If you don't know what's wrong, then clamining the loader works correct is a strong statement. Have you verified that the texture is indeed correctly loaded, and is in a valid state, at the time you render your quad?

Just becuase it works in another application doesn't mean it will automatically work here. Is the file missing? Do you load it AFTER you create the rendering context? From your description (white texture, a too common problem), I believe the texture is not loaded correctly more than I believe the rendering code is wrong.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
If you don't know what's wrong, then clamining the loader works correct is a strong statement. Have you verified that the texture is indeed correctly loaded, and is in a valid state, at the time you render your quad?

Just becuase it works in another application doesn't mean it will automatically work here. Is the file missing? Do you load it AFTER you create the rendering context? From your description (white texture, a too common problem), I believe the texture is not loaded correctly more than I believe the rendering code is wrong.


I can check to make sure when I get off work later today but I'd be hard pressed to blame it on the loader. The class for the loader is the same in both programs, the images used were the same, it's called in the same way in a similar place, and the loader function returns true to indicate success.

But yeah later today I'll look at it again. I guess I don't have anywhere else to go with it.

edit:

Quote:
Do you load it AFTER you create the rendering context?


Hm, actually, that could be a difference... I'll get back to you on it.

Share this post


Link to post
Share on other sites
You have to make sure you use glEnable(GL_TEXTURE2D) for every texture stage that you use. In your case you just need to use it once before you draw the scene because you are not using multitexturing.

Share this post


Link to post
Share on other sites
You're not generating your texture's mipmaps. You're getting white because the card is sampling a non-existent mipmap.

Share this post


Link to post
Share on other sites
Both of you above should look at the code he posted. Texturing is enabled, and the minification filter he use does not require mipmaps.

Share this post


Link to post
Share on other sites
Trudat. I've had a couple of instances where I couldn't work out why everything was white which turned out to be forgotten mipmaps, so I assumed this is what happened here.

My bad.

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!