Advertisement Jump to content
Sign in to follow this  

Texturing Problems

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

I'm doing a water in a height map surface, so I loaded one texture (earth tex) and bound it following nehe's tutorial on texture. Then I used glTexCoord2f() to map the texture to the vertex, and then I glEnd(); but when I open another glBegin() and make a new quad, and calls the glColor it keeps with the texture color, but without the texture, and i'm setting it to blue. There's my code:
	glColor3f(1.0f,1.0f,1.0f);							for (int y=0;y<MAP_SIZE-1;y++){
	    for (int x=0;x<MAP_SIZE-1;x++){
		z1 = Height(x+1, y+1 )*10;
		z2 = Height(x, y+1 )*10;
		z3 = Height(x+1, y )*10;
		z4 = Height(x, y )*10;
		glTexCoord2f(0.0f, 0.0f); glVertex3i((x*64)-64,   (y*64),z2);	
		glTexCoord2f(1.0f, 0.0f); glVertex3i(   (x*64),   (y*64),z1);	
		glTexCoord2f(1.0f, 1.0f); glVertex3i(   (x*64),(y*64)-64,z3);	
		glTexCoord2f(0.0f, 1.0f); glVertex3i((x*64)-64,(y*64)-64,z4);	
	glColor3f(0.0f,0.0f,1.0f);							glVertex3i(-64,   MAP_SIZE*64,64);	
	glVertex3i(   MAP_SIZE*64,  MAP_SIZE*64,64);	
	glVertex3i(   MAP_SIZE*64,-64,64);	

And to load the texture I borrowed Nehe's function:
int LoadGLTextures()
	int Status=FALSE;								AUX_RGBImageRec *TextureImage[1];					
	memset(TextureImage,0,sizeof(void *)*1); 
	if (TextureImage[0]=LoadBMP("grass.bmp"))
		Status=TRUE;									glGenTextures(1, &texture[0]);				

		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

	if (TextureImage[0])								{
		if (TextureImage[0]->data)							{
			free(TextureImage[0]->data);						}
		free(TextureImage[0]);							}

	return Status;							

Share this post

Link to post
Share on other sites
Enable texturing and bind the texture when you need it, disable texturing when you don't need it.

So before you render the quads where you are using the texture put this...
glBindTexture(GL_TEXTURE_2D, texId);
//texId is the name of your texture which you got from glGenTextures
and before you render the quads that don't use a texture put this...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!