PDA

View Full Version : square builded with two triangles



alex2
03-01-2011, 11:54 PM
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() ?

Alfonse Reinheart
03-02-2011, 12:04 AM
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
03-02-2011, 12:37 AM
I have created shorted version to demonstrate idea.

mobeen
03-02-2011, 01:25 AM
But how in that case put on this figure some texture using glTexCoord2f() ?

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



I have created shorted version to demonstrate idea?

What idea are u trying to ask?

alex2
03-02-2011, 03:41 AM
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();


http://img192.imageshack.us/img192/1759/beznazwy3ic.jpg (http://img192.imageshack.us/i/beznazwy3ic.jpg/)

mobeen
03-02-2011, 04:04 AM
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
03-02-2011, 04:16 AM
WoW - it works - thx You very much - now I understand ! :D