Jump to content
  • Advertisement
sjhalayka

glDrawArrays(GL_TRIANGLES, ......)

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

I'm creating some vertex data using a vector<GLfloat>:

	    static vector<GLfloat> vertices = {
        
        // 3D position, 2D texture coordinate
        
        // card front
        -0.1, -0.1,  0.0,   1*0.125, 4*0.125, // vertex 0
         0.1, -0.1,  0.0,   2*0.125, 4*0.125, // vertex 1
         0.1,  0.1,  0.0,   2*0.125, 5*0.125, // vertex 2
        -0.1, -0.1,  0.0,   1*0.125, 4*0.125, // vertex 0
         0.1,  0.1,  0.0,   2*0.125, 5*0.125, // vertex 2
        -0.1,  0.1,  0.0,   1*0.125, 5*0.125, // vertex 3
	        // card back
         0.1,  0.1,  0.0,   4*0.125, 2*0.125, // vertex 2
         0.1, -0.1,  0.0,   4*0.125, 1*0.125, // vertex 1
        -0.1, -0.1,  0.0,   5*0.125, 1*0.125, // vertex 0
         0.1,  0.1,  0.0,   4*0.125, 2*0.125, // vertex 2
        -0.1, -0.1,  0.0,   5*0.125, 1*0.125, // vertex 0
        -0.1,  0.1,  0.0,   5*0.125, 2*0.125  // vertex 3
    };
	

Then I draw it:

	    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
	

What is the correct value for the final parameter of glDrawArrays()? vertices.size() or vertices.size()/5? Both appear to work.

 

Edited by sjhalayka

Share this post


Link to post
Share on other sites
Advertisement

You have here 12 vertices, so your number should be 12.
Your vertices vector contains 60 elements (3x float for position, 2x float for uv), so doing

vector.size() / 5         // => 60/5 = 12 

is the correct way.

If you prefer to keep vertex data in one array you might want to consider adding some struct 

struct MyVector
{
  float x, y, z;
  float u, v;
}

and:

static vector<MyVector> vertices

then you can simply do:

vertices.size() // gives 12 now

There are also others methods how you can organize your vertex data, for example keeping vertex and uv data as separate arrays (you can look it up if you want) but I hope this answers your question.

Share this post


Link to post
Share on other sites

  • 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!