Sign in to follow this  
reepsmac

Texturing Mapping Problem

Recommended Posts

I am having trouble mapping a texture to a surface. I know that the class I wrote to load the image is working correctly because I can display the image by using glDrawPixels(). However whenever I try to bind the texture object, set the texture filters, and specify the texture for the texture object nothing is mapped to the surface when it is rendered. here is the code I used to load the texture and create the textre object is there anything i am missing?
[source lang='cpp']
tgaImage.loadTGAImage("test2.tga");

glDrawPixels(tgaImage.getImageWidth(), tgaImage.getImageHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE, aImage.getImageData());

//GLuint grassTexture;
glGenTextures(1, &grassTexture);
glBindTexture(GL_TEXTURE_2D, grassTexture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tgaImage.getImageWidth(),
				tgaImage.getImageHeight(), 0 , GL_RGB, GL_UNSIGNED_BYTE,
				tgaImage.getImageData());

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

//glDrawPixels(tgaImage.getImageWidth(), tgaImage.getImageHeight(), GL_BGR_EXT, GL_UNSIGNED_BYTE, tgaImage.getImageData()); displays the image correctly

Share this post


Link to post
Share on other sites
hello there,

first of all, please check that your texture's dimensions are a power of two (e.g. 32, 64, 128,..) since glTexImage2D has this requirement.

Also, you may want to specify the texture wrapping modes, e.g.

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);

And remember that you will have to specify texture coordinates for your geometry in order for the texture mapping to work properly.

Best regards

Callidus

Share this post


Link to post
Share on other sites
Quote:
Original post by Callidus
first of all, please check that your texture's dimensions are a power of two (e.g. 32, 64, 128,..) since glTexImage2D has this requirement.


The texture is 128*128. Just for testing purposes I am using the one from the nehe tutorial.

Quote:
Original post by Callidus
Also, you may want to specify the texture wrapping modes, e.g.

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);


I tried adding this but it didnt help with displaying the texture

Quote:
Original post by Callidus
And remember that you will have to specify texture coordinates for your geometry in order for the texture mapping to work properly.


here is what my code looks like for showing my geometry.
[source lang = "cpp"]
...
glBindTexture(GL_TEXTURE_2D, grassTexture);
for(int z = 0; (z+1) < terrainLength; z++)
{
glBegin(GL_TRIANGLE_STRIP);

for(int x = 0; (x+1) < terrainWidth; x+=2)
{
glTexCoord2f(1.0, 1.0); glVertex3i(terrainGrid[z][x].xPoint, terrainGrid[z][x].yPoint, terrainGrid[z][x].zPoint);
glTexCoord2f(1.0, 0.0); glVertex3i(terrainGrid[z+1][x].xPoint, terrainGrid[z+1][x].yPoint, terrainGrid[z+1][x].zPoint);
glTexCoord2f(0.0, 1.0); glVertex3i(terrainGrid[z][x+1].xPoint, terrainGrid[z][x+1].yPoint, terrainGrid[z][x+1].zPoint);
glTexCoord2f(1.0, 0.0); glVertex3i(terrainGrid[z+1][x+1].xPoint, terrainGrid[z+1][x+1].yPoint, terrainGrid[z+1][x+1].zPoint);
}
glEnd();
}



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Brother Bob
You have glEnable(GL_TEXTURE_2D) anywhere in your code?


yes it was above the line that reads
[source lang = "cpp"]tgaImage.loadTGAImage("test2.tga");


i just missed copying it over.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
You have glEnable(GL_TEXTURE_2D) anywhere in your code?


yes it was above the line that reads
[source lang = "cpp"]tgaImage.loadTGAImage("test2.tga");



i just missed copying it over.

##sorry about the double post##

Share this post


Link to post
Share on other sites
Try rendering a simple textured quad. I think something is wrong with your drawing code. For example you set the same texture coordinate twice ( glTexCoord2f(1.0,0.0) ).

Share this post


Link to post
Share on other sites

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