square builded with two triangles

I have a problem with understanding lesson “Loading And Moving Through A 3D World:” nehe tutorial http://nehe.gamedev.net/lesson.asp?index=02

As I understand he builds one square using two triangles - for example:


glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, texture[0]); 
glTranslatef(-10.0f, -10.0f, -50.0f);
glBegin(GL_TRIANGLES); 	
		glVertex3f(-3.0f,0.0f, 6.0f);
		glVertex3f(3.0f,0.0f, 0.0f);
		glVertex3f(3.0f,6.0f, 0.0f);
		
		glVertex3f(-3.0f,0.0f, 6.0f);
		glVertex3f(-3.0f,6.0f, 6.0f);
		glVertex3f(3.0f,6.0f, 0.0f);
glEnd();						
glPopMatrix();

But how in that case put on this figure some texture using glTexCoord2f() ?

I have a problem with understanding lesson “Loading And Moving Through A 3D World:” nehe tutorial http://nehe.gamedev.net/lesson.asp?index=02

Are you sure you’re looking at the right tutorial? Because the code you posted is not part of that tutorial.

I have created shorted version to demonstrate idea.

What are u trying to ask? The english is wrong. The tutorial code is using glTexCoord2f but the snippet u have posted isnt.

What idea are u trying to ask?

How can I put texture on square which has been build from two triangles because below code gives me bad result:


glLoadIdentity();
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glTranslatef(1.0f, -4.0f, -15.0f);
	glBegin(GL_TRIANGLES); 	
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(-3.0f,0.0f, 6.0f);
		glTexCoord2f(0.5f, 0.0f);
		glVertex3f(3.0f,0.0f, 0.0f);
		glTexCoord2f(0.5f, 1.0f);
		glVertex3f(3.0f,6.0f, 0.0f);
		
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(-3.0f,0.0f, 6.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-3.0f,6.0f, 6.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(3.0f,6.0f, 0.0f);
	glEnd(); 						
	glPopMatrix();

Your texture coordinates seem wrong. Try this


glBegin(GL_TRIANGLES); 	
glTexCoord2f(0.0f, 0.0f);	glVertex3f(-3.0f,0.0f, 6.0f);
glTexCoord2f(1.0f, 0.0f);	glVertex3f(3.0f,0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);	glVertex3f(3.0f,6.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);	glVertex3f(-3.0f,0.0f, 6.0f);
glTexCoord2f(0.0f, 1.0f);	glVertex3f(-3.0f,6.0f, 6.0f);
glTexCoord2f(1.0f, 1.0f);	glVertex3f(3.0f,6.0f, 0.0f);
glEnd(); 	

WoW - it works - thx You very much - now I understand ! :smiley: