Posted by
millerni456 on
Sep 28, 2011; 3:31am
URL: https://forum.jogamp.org/glDrawElements-with-TRIANGLE-STRIP-tp3374872.html
Problem Solved: Skip to last post for answer.
Hello, I was working with
glDrawElements and seem to have run into a problem and I was looking for assistance.
It would also help to clear things up on
glDrawElements, because I haven't found a solid definition out there yet.
glDrawElements takes these parameters as far as I know.....
the mode (GL_TRAIGLE_STRIP),
the number of indices
the size in bytes of the indices
and the index buffer.
So, when I fill in the paramters I don't quite get want I expect.
Im looking to create a sort of truncated cone that looks like this. (looking down z axis).

Here's how I set up my vertices:
Note that the height and radius are specified by the program.
RadialX and Z is talking about coordinate locations. (Distance along those axes).
Also the loop iterates 20 times incrementing the angle by 18 degrees per iteration. (Thus a whole circle).
Since I'm making a triangle strip, the vertices alternate from the bottom of the cone to the top.
float[] data = new float[120]; //20 vertices on top and bottom, * 3 per xyz component.
double h1 = .333 * height;
int k = 0;
for(int i = 0; i<data.length; i+=6)//iterates 20 times.
{
double cos = Math.cos(Math.toRadians(k*18));
double sin = Math.sin(Math.toRadians(k*18));
System.out.println(k*18);
double radialX = radius * cos;//-1 to 1
double radialZ = radius * sin;//-1 to 1
System.out.println(k*36);
/**BOTTOM or cylinder**/
//gl.glTexCoord2d(1, 1);
data[i] = (float) (radialX * .5);
data[i+1] = (float) (h1);
data[i+2] = (float) (radialZ * .5);
/**TOP of ylinder**/
//gl.glTexCoord2d(1, 0);
data[i+3] = (float) (radialX);
data[i+4] = (float) (height);
data[i+5] = (float) (radialZ);
k++;
}
So this should set up the vertices correctly (which it does, I've tested with GL_POINTS).