tema
tema

Reputation: 1125

How to enumerate vertices in OpenGL

I'm new to OpenGL and my question seems to be very simple, but I haven't found propper inforamtion yet.
I'm trying to build my own cone by rotating a triangle around the y-axis.
I've got some (x,y) coordinates which describes the triangle. As I understood, I have to convert them to (x,y,z) like (x*cos(alpha), x*sin(alpha),y), where alpha is between [0, 2Pi] with some step (let it be Pi/36)
Next, I have to enumerate obtained vertices to tell OpenGL how to connect them.
So, my question is about how to enumerate them correctly.

Upvotes: 0

Views: 165

Answers (1)

Adrian Krupa
Adrian Krupa

Reputation: 1937

The question has nothing to do with OpenGL; This cone will be without basis.

First create vertices

int density = 10;
float3 vertices[];
vertices.add(float3(0,0,1));
for(int i=0; i<=density; i++) {
    float alpha = i*2*PI/density
    vertices.add(float3(cos(alpha), sin(alpha), 0));
}

Then create indices and triangles

int indices[];
for(int i=0; i<density; i++) {
    //add triangle
    indices.add(0);
    indices.add(i);
    indices.add(i+1);
}

Then you have to use data from vertices[] and indices[] during drawing.

Upvotes: 1

Related Questions