Sign in to follow this  

Any clue why this texture mapping isn't working?

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

This topic is 3856 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this