Skip to main content
gamedev.net
🔒 Locked

Multiple Texture Binding Issues

Started by Alaric Apr 26, 2006 at 7:45 PM 2 replies 1.2k views
Original Post
Alaric
Alaric
Hi. ...I'm working on a 'forest walkthrough' and am having issues with the incorrect texture being 'binded' to objects that it is not supposed to be assigned to. Here are the display lists that are called:

void InitDisplayLists(void)
{

	//draw bark
	glNewList(1,GL_COMPILE);
		glBindTexture(GL_TEXTURE_2D, textures[1]);
		 
		gluCylinder(q,1.f,1.f,1.f,5.f,5.f);
	glEndList();

	//draw leaves
	glNewList(2,GL_COMPILE);
	glBindTexture(GL_TEXTURE_2D, textures[2]);
		gluDisk(q1,0.f,8.f,4.f, 4.f);
	glEndList();
	
	//draw the ground
	glNewList(3, GL_COMPILE);
		
		glBegin(GL_QUADS);
			glColor3ub(50,50,50);
			glBindTexture(GL_TEXTURE_2D, textures[0]);
			glTexCoord2f(100.0f, 100.0f);glVertex3f(-100,-0.6,-100);
			glTexCoord2f(0.0f, 100.0f);glVertex3f(100,-0.6,-100);
			glTexCoord2f(0.0f, 0.0f);glVertex3f(100,-0.6,100);
			glTexCoord2f(100.0f, 0.0f);glVertex3f(-100,-0.6,100);
		glEnd();
	glEndList();
}
(q and q1 are quadrics. ...I have gluQuadricNormals([quadricobject], GLU_SMOOTH) and gluQuadricTexture([quadricobject], GL_TRUE) set for each of them) my texture loading functions look like this:

void InitTextureObjects()
{
	
        //--------
	//|Ground|
	//*****************************
	ground.data = LoadTGA("grass2.tga", &x, &y, &d);
	ground.bitdepth = d;
	ground.width = x;
	ground.height = y;

        //trunk and branches
	bark.data = LoadTGA("bark1.tga", &x, &y, &d);
	bark.bitdepth = d;
	bark.width = x;
	bark.height = y;
	

        //leaves
	leaf_oak.data = LoadTGA("bark1.tga", &x, &y, &d);
	leaf_oak.bitdepth = d;
	leaf_oak.width = x;
	leaf_oak.height = y;
	

        //skydome texture
	sky.data = LoadTGA("sky.tga", &x, &y, &d);
	sky.bitdepth = d;
	sky.width = x;
	sky.height = y;
	printf("All texture objects loaded\n");
	printf("ground.textureID = %d\n", ground.textureID);
	printf("bark.textureID = %d\n", bark.textureID);
	printf("leaf_oak.textureID = %d\n", leaf_oak.textureID);
	
	
	


}

GLuint Map1_2DTexture(GLuint target, Texture texture)
{
	//1. Generate the Texture ID -:glGenTextures
	//2. Bind texture to Texture array -:glBindTexture
	//3. Set the TexImage2D pointer -:glTexImage2D
	//4. Set Texture Parameters -: glTexParameteri
	//5. Mipmap
	//6. Release Texture memory if texture.lastUse = true, cuz it's done
    
	//1.genID
	//2.bind
	glBindTexture(GL_TEXTURE_2D, target);
	
	
	//3.set image
	if(texture.bitdepth == 32)
	{
		glTexImage2D(GL_TEXTURE_2D, 0, 4, texture.width, texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.data);
	}
	else
	{
		printf("Invalid Texture Format  %d\n", target);
		exit(1);
	}


	//4. texp
	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_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


	//5.  Mipmap

	return target;
}
void InitTextures()
{

	glGenTextures(1, &textures[0]);
	glGenTextures(1, &textures[1]);
	glGenTextures(1, &textures[2]);
	glGenTextures(1, &textures[3]);
	ground.textureID = Map1_2DTexture(textures[0], ground);
	bark.textureID = Map1_2DTexture(textures[1], bark);
	leaf_oak.textureID = Map1_2DTexture(textures[2], leaf_oak);
	sky.textureID = Map1_2DTexture(textures[3], sky);
	printf("ground = %d & %d\n", textures[0], ground.textureID);
	printf("bark = %d & %d\n", textures[1], bark.textureID);
	printf("leaf = %d & %d\n", textures[2], leaf_oak.textureID);
	printf("sky = %d & %d\n", textures[3], sky.textureID);
}
(the printfs are used for debugging. I used both GLuint textures[] and the textureID of my texture struct to store the texture# just to make sure that I was assigning TextureIDs consistently) I have a recursive function defined for procedurally creating a tree for me that I can't divulge, but basically I draw the trunk until I reach the end of the branches, then I draw leaves. So, while I'm not at the end of the 'woody' part of the tree, glCallList(1) is called, and whenever I reach the end, glCallList(2) is called. ...Ok, there's the relevant information; now to my issue. Whenever I load only the grass texture for the ground and run my application, everything in my scene is textured with grass. ...But, whenever I load the other textures for the trees and try to bind the textures to their respective objects, the grass shows up as grass, everything else shows up as bark, and as soon as I move, the bark texture gets applied to everything. Does anybody have any idea what could be causing this? ...if anybody would like to see the rest of my code, ask and I'll post.
Falken42
Falken42
Quote:
Original post by Alaric
//draw the ground
glNewList(3, GL_COMPILE);

glBegin(GL_QUADS);
glColor3ub(50,50,50);
glBindTexture(GL_TEXTURE_2D, textures[0]);
...
glEnd();


glBindTexture is not allowed between a glBegin/glEnd pair.
Alaric
Alaric
Thank you very much. :)

...I'm trying to texture the inside of my skydome and I'm having some complications. Here is my skydome function
void RenderDome(){#define PI 3.1415926535897932384626433832795#define K1 PI/20.f#define K2 PI/20.f#define R 100  GLfloat u,v;  GLfloat x,y,z;  static int t1,t2;  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  for (u=0;u<=PI;u+=K1)  {	  	  glColor3f(0.0f, 0.0f, 1.0f);	  glBindTexture(GL_TEXTURE_2D, sky.textureID);	  glBegin(GL_QUAD_STRIP);		for (v=0;v<=PI+K2;v+=K2)		{			x=R*cos(u)*sin(v);			y=R*sin(u)*sin(v);			z=R*cos(v);			glTexCoord3f(x, y, z);			glVertex3f(x,y,z);						x=R*cos(u+K1)*sin(v);			y=R*sin(u+K1)*sin(v);			glTexCoord3f(x, y, z);			glVertex3f(x,y,z);		}	  glEnd();  }}


...What should my texture coordinates be for these points? I know that the way I have it tiles it across every quad that is built (I was just trying to see if the texture would apply itself since I was having 'general' texturing issues at the time) ...but if I'm wanting my image to be applied across the entire hemisphere, what should my texture coords be?
Falken42
Falken42
Texture coordinates only go from [0.0f -> 1.0f], and you only need the 'r' component if you're doing 3D texturing.

I've never actually done a skybox by hand (always used a pre-built model), but since you want the T component to be 0.0f at the top and 1.0f at the bottom while the S component goes around in a circle, I'd say something like:
glTexCoord2f(u / PI, v / (PI + K2));

and
glTexCoord2f((u + K1) / PI, (v + K2) / (PI + K2));


*might* do what you're looking for.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.