alex2
1
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.
alex2
3
I have created shorted version to demonstrate idea.
mobeen
4
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?
alex2
5
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();
mobeen
6
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();
alex2
7
WoW - it works - thx You very much - now I understand !