# OpenGL Having trouble understanding glVertex3f()

This topic is 4952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, Ive just started out with opengl. Ive got some serious trouble understanding this function.
    glBegin(GL_TRIANGLES);		// Drawing
glVertex3f( 0.0f, 1.0f, 0.0f);	// Top
glVertex3f(-1.0f,-1.0f, 0.0f);	// Bottom Left
glVertex3f( 1.0f,-1.0f, 0.0f);	// Bottom Right
glEnd();		                // Finished Drawing The Triangle

When I use that function should I imagine I move the distance inputed as parameters and laying out a line after me? But that way it should be: 1 unit up, 1 unit left and down, and then 1 unit right, back to initial position However, in the last line theres a second unit downwards. Quite confused. Ive checked the faq but I couldnt find anything there. Someone sitting on a good explanation? :)

##### Share on other sites
Well, GL_TRIANGLES means that it draws a solid triangle. You need three vertices to make a triangle, correct? Remember that you're not drawing lines. If you wanted to draw it the way you think you are, do it like this:

glBegin(GL_LINE_STRIP)    glVertex3f (0.0f, 1.0f, 0.0f);    glVertex3f (-1.0f, -1.0f, 0.0f);    glVertex3f (1.0f, -1.0f, 0.0f);    glVertex3f (0.0f, 1.0f); // need this to complete triangleglEnd();

Or, if you wanted to use just 3 points to draw a wireframe triangle after all, you could use GL_LINE_LOOP instead.

##### Share on other sites
Quote:
 When I use that function should I imagine I move the distance inputed as parameters and laying out a line after me?

No, this would mean that the inputs to glVertex3f are relative to each other.
The parameters to glVertex3f() are absolute coordinates in world-space.

The code you have would draw a triangle ABC, with A(0,1,0) B(-1,-1,0), C(1,-1,0)

##### Share on other sites
Ok so I should think of the position as relative to my current position? Ie where I ended up after glTranslatef()?

##### Share on other sites
Yep

....although technically it's your transformation according to the model-view matrix. This can include your position (glTranslate), your orientation (glRotate), the scale of things in the world (glScale), and other transformation you can stuff into a matrix (whether it be through the gl functions or by manually manipulating the matrix).

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633311
• Total Posts
3011312
• ### Who's Online (See full list)

There are no registered users currently online

×