Jump to content
  • Advertisement
Sign in to follow this  
Mizipzor

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 triangle
glEnd();



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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!