Advertisement

Texturing multiple objects.

Started by January 02, 2001 08:48 PM
3 comments, last by rask 24 years, 1 month ago
I have a function that draws a square with a texture, but it only displays the texture the first time I call it, so only the first square has a texture. The others just dont appear. The function body.

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture[1]);
	glColor3f(1.0f,1.0f,1.0f);
	glBegin(GL_QUADS);
		glNormal3f( 0.0f, 0.0f, 1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y,  0.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(x+0.02f, y,  0.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(x+0.02f,  y-0.02f,  0.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(x,  y-0.02f,  0.0f);
	glEnd();
	glDisable(GL_TEXTURE_2D);
	glPrint(x1, y1+0.02f,0,"x: %1.2f", x);	
 	glPrint(x1+0.1f, y1+0.02f, 0,"y: %1.2f", y);
 
i think you need to translate the square, so that your not just drawing the same square.

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glColor3f(1.0f,1.0f,1.0f);
glPushMatrix();

glTranslatef(x,y,0) // <--- ***use this***

glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f);glVertex3f(0, 0, 0.0f);
glTexCoord2f(0.0f, 1.0f);glVertex3f(0+0.02f, 0, 0.0f);
glTexCoord2f(0.0f, 0.0f);glVertex3f(0+0.02f, 0-0.02f, 0.0f);
glTexCoord2f(1.0f, 0.0f);glVertex3f(0, 0-0.02f, 0.0f);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glPrint(x1, y1+0.02f,0,"x: %1.2f", x);
glPrint(x1+0.1f, y1+0.02f, 0,"y: %1.2f", y);


Advertisement
x and y change, so they shouldnt be drawing on top of each other. It worked fine untill i added textures(just white blocks before).

but thanks for the tip none the less, i'll give it a shot.


Edited by - rask on January 2, 2001 11:16:29 PM
Nope, although I like your way more, it still didnt fix it
Well, for starters, why not dump the contents of texture[] to a file, so at least you know it is getting data. I assume you have a loop someplace to change x & y right? Perhaps a bigger code snipet would help.




This topic is closed to new replies.

Advertisement