Texturing Mapping Problem

Started by
5 comments, last by Grudzio 17 years, 5 months ago
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

Advertisement
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
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();	}


You have glEnable(GL_TEXTURE_2D) anywhere in your code?
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.
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##
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) ).

This topic is closed to new replies.

Advertisement