Skip to main content
gamedev.net
🔒 Locked

Mutiple Texture Problem

Started by davek20 Jun 16, 2007 at 3:16 PM 1 replies 650+ views
Original Post
davek20
davek20
Hey guys, I'm having some trouble rendering a model with multiple textures. For some reason, it is binding the last texture I load/initialize to the WHOLE model. Here is how I am initializing the textures (test is my model):

for(int i=0;i<test->numTextures;i++){
	glGenTextures(1,(GLuint *)&test->textures.textID);			

	glBindTexture(GL_TEXTURE_2D, (GLuint)test->textures.textID); 	

	
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, test->textures.width, test->textures.height,
        		  GL_RGB, GL_UNSIGNED_BYTE, test->textures.image);
}

And here is how I am rendering the Model:

for(int i=0;i<numTextures;i++){		
	glBegin(GL_TRIANGLES);	
	glEnable(GL_TEXTURE_2D);		
	glBindTexture(GL_TEXTURE_2D, (GLuint)textures.textID);		
	for(int j=0;j<numTriangles;j+=3){
		glNormal3f(triangles[j].nX,triangles[j].nY,triangles[j].nZ);
		glTexCoord2f(triangles[j].u,triangles[j].v);
		glVertex3f(triangles[j].x,triangles[j].y,triangles[j].z);		
			
		glNormal3f(triangles[j+1].nX,triangles[j+1].nY,triangles[j+1].nZ);
		glTexCoord2f(triangles[j+1].u,triangles[j+1].v);
		glVertex3f(triangles[j+1].x,triangles[j+1].y,triangles[j+1].z);	

		glNormal3f(triangles[j+2].nX,triangles[j+2].nY,triangles[j+2].nZ);
		glTexCoord2f(triangles[j+2].u,triangles[j+2].v);
		glVertex3f(triangles[j+2].x,triangles[j+2].y,triangles[j+2].z);	
	}
	glEnd();		
}

It may just be something small that I missed. I looked at some of my other source code that has multiple textures and its basically the same. I've been trying to get this to work for about an hour now *sigh* Any ideas on why its doing this?
Polyteres
Polyteres
Change this:

glBegin(GL_TRIANGLES);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, (GLuint)textures.textID);


for this:

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, (GLuint)textures.textID);
glBegin(GL_TRIANGLES);



davek20
davek20
Polyteres, Thank you very much LOL. I knew it was something so simple that I overlooked it. Thats what happens when I code for too long :/

I just noticed something else in my code. The first section of my code that I posted is OUTSIDE my model class (the code originated from my main.cpp file). When I tried to put it into my model class, it gives me a segmentation fault. Its the exact same code (with out the test-> in there since its in the model class, and with glEnable(GL_TEXTURE_2D) before the loop), any ideas why its giving me a segmentation fault?

Also, should the initializing of textures be in my model class or my main class?

Topic Locked

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

Sign in to reply to this topic.