Witam postanowiłem napisać prosty loader modeli 3d konkretnie *.obj najpierw je konwertuje do postaci dwóch tablic( vertexów i indexów) robię to wczytując kolejno vertexy( jeden za drugim) i tak samo indexy(od indexów odejmuje jeden aby były liczone od 0), sześcian wyświetla sie poprawnie natomiast przy "cylindrze" występuje już problem z siatką. prawdopodobnie coś źle interpretuje oto plik *.obj.
Plik *.obj
# Blender v2.58 (sub 1) OBJ File: ''
# www.blender.org
v -0.204667 -0.714511 -0.904894
v 0.746390 -0.714511 -0.213911
v 0.383118 -0.714511 0.904123
v -0.792452 -0.714511 0.904123
v -1.155723 -0.714511 -0.213911
v -0.204667 1.285489 -0.904894
v 0.746390 1.285489 -0.213911
v 0.383119 1.285489 0.904123
v -0.792452 1.285489 0.904123
v -1.155723 1.285489 -0.213912
v -0.204667 -0.714511 0.095106
v -0.204667 1.285489 0.095106
usemtl (null)
s off
f 11 1 2
f 12 7 6
f 11 2 3
f 12 8 7
f 11 3 4
f 12 9 8
f 11 4 5
f 12 10 9
f 5 1 11
f 12 6 10
f 1 6 7
f 1 7 2
f 2 7 8
f 2 8 3
f 3 8 9
f 3 9 4
f 4 9 10
f 4 10 5
f 6 1 5
f 6 5 10
Screeny:
i kod wyświetlania javy
gl.glFrontFace(GL10.GL_CCW);
// Enable face culling.
gl.glEnable(GL10.GL_CULL_FACE);
// What faces to remove with the face culling.
gl.glCullFace(GL10.GL_BACK);
// Enabled the vertices buffer for writing and to be used during
// rendering.
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
// Specifies the location and data format of an array of vertex
// coordinates to use when rendering.
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glColor4f(1, 1, 1, 1);
gl.glDrawElements(GL10.GL_LINE_LOOP, model.indexCount,
GL10.GL_UNSIGNED_SHORT, indexBuffer);
// Disable the vertices buffer.
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
// Disable face culling.
gl.glDisable(GL10.GL_CULL_FACE);