Sign in to follow this  

Why does the order of vertices and indices matter?

This topic is 666 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

  Why does the order, in which vertices are arranged matter. The following compiles fine

    const GLfloat vertices[] =

    {

        0.5f,  0.5f, 0.0f,   // Top Right    

        0.5f, -0.5f, 0.0f,   // Bottom Right

       -0.5f, -0.5f, 0.0f,   // Bottom Left

       -0.5f,  0.5f, 0.0f    // Top Left

    

    };
 
...
 
    const GLint indices[] =

    {

        0, 1, 3,  // 1st Triangle

        1, 2, 3   // 2nd Triangle

    

    };

while something like this does not,


    const GLfloat vertices[] =
    {        
        0.5f, -0.5f, 0.0f,   // Bottom Right
        -0.5f,  0.5f, 0.0f,   // Top Left
        0.5f,  0.5f, 0.0f,   // Top Right    
       -0.5f, -0.5f, 0.0f   // Bottom Left

    
    };
 
...
 
    const GLint indices[] =
    {
        0, 1, 2,  // 1st Triangle
        3, 1, 2   // 2nd Triangle
    
    };
 
 

  What am I missing in terms of a pattern, that I can get out of this.

Share this post


Link to post
Share on other sites

Not really an error message, its more of a deformed shape. The normal output should be a square that is composed of two triangles.  Used Element Buffer Objects to reduce the number of vertices that are stored in the array. Its a more efficient way of drawing something like a square, that uses the same vertices multiple times.

Edited by TheStudent111

Share this post


Link to post
Share on other sites


Not really an error message, its more of a deformed shape.

Then it is not a compilation error. Terminology matters :)

 

That said, it looks like your indices are incorrect.

You seem to have:

Bottom Right - Top Left - Top Right

Bottom Left - Top Left - Top Right

 

You probably want to swap Top Right with Bottom Right (so 3, 1, 0 for the second triangle).

Share this post


Link to post
Share on other sites

Each set of three indices correspond to a triangle.

 

Look more closely at your second case. Your two triangles are overlapping, instead of being adjacent.

Share this post


Link to post
Share on other sites

This topic is 666 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this