Jump to content
  • Advertisement
Sign in to follow this  
LordAsm

Texturing Problems

This topic is 4843 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:
glBegin(GL_QUADS);
	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);	
	    }
	}
	glEnd();
	glBegin(GL_QUADS);
	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);	
        glVertex3i(-64,-64,64);
	glEnd();



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);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	}

	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
Advertisement
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...
glEnable(GL_TEXTURE_2D);
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...
glDisable(GL_TEXTURE_2D);

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!