Triangle Fan Mapping

Currently I am doing this tutorial, I’m trying to do this in libgdx OpenGL ES 1.0 because I don’t know how to convert it to Open GL ES 2.0. I’m trying to understand but i can’t understand the other code.

First, I create some vertices base on NUM_SEGMENTS


float vertices[] = new float[(NUM_SEGMENTS + 2) * 3];

and then create FloatBuffer base on vertices


ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
vertexByteBuffer.order(ByteOrder.nativeOrder());
triangleFanPos = vertexByteBuffer.asFloatBuffer();

and under game update


triangleFanPos.clear();

int idx = 0;
vertices[idx++] = innerCircleBody.getPosition().x * PTM_RATIO - orthographicCamera.position.x;
vertices[idx++] = innerCircleBody.getPosition().y * PTM_RATIO - orthographicCamera.position.y;

for (int i = 0; i < NUM_SEGMENTS; i++) {
	Body currentBody = bodies.get(i);

	vertices[idx++] = currentBody.getPosition().x * PTM_RATIO - orthographicCamera.position.x;
	vertices[idx++] = currentBody.getPosition().y * PTM_RATIO - orthographicCamera.position.y;
}

vertices[NUM_SEGMENTS + 1] = vertices[0];
vertices[NUM_SEGMENTS + 2] = vertices[1];

triangleFanPos.put(vertices);

GL10 gl10 = Gdx.gl10;
gl10.glDisable(GL10.GL_TEXTURE_2D);
gl10.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl10.glDisableClientState(GL10.GL_COLOR_ARRAY);

// Set the color to red
gl10.glColor4f(1.f, 0.f, 0.f, 1.f);
gl10.glVertexPointer(2, GL10.GL_FLOAT, 0, triangleFanPos);

gl10.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, NUM_SEGMENTS + 2);

// Re-enable states
gl10.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl10.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl10.glEnable(GL10.GL_TEXTURE_2D);

As you can see, I don’t know if I am doing it in right way. Can i get some help, explanations or any tutorials about this?

thanks!

up

from first glance, i think you are not moving the vertices to the buffer.

either copy all content of float vertices[] to triangleFanPos …

or create just the ByteBuffer vertexByteBuffe and use vertexByteBuffe.putFloat() to fill it.

draw-methods look good.

are you learning how triangle-fans work ? if so, http://profs.sci.univr.it/~colombar/html_openGL_tutorial/en/02rendering_022.html looks easy :slight_smile:

oh wait … is the glDisableClientState glEnableClientState order flipped ?

it should be …

glEnableClientState
glDrawArrays
glDisableClientState

should draw something red.