while i was trying to implement the Indexed geometry Array,i came across a problem.When i used the IndexedTriangleArray,the geometry has been drawn perfectly. But when i tried to use IndexedQuadArray,absolutely nothing was displayed on the screen.Isearched the forum,if anyone else has faced the sanme problem.I found many people who has also faced the same problem,but no one has comeup with the solution.
Then i checed the library class of Xith, and i found that in PACKAGE–com.xith3d.render.jogl…CLASS----ShapeAtomPeer…METHOD—private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray), some code is missing…actually the functinality of IndexedTriangle is defined ,but nothing for IndexedQuadArray ,IndexedLineArray,IndexedLineStrip Array is defined. Then i just added the function of the missing Arrays, n it start working perfectly. PLzzz try this in ur programs, and let me know if it works correctly in ur programs also.
The modified method is…
private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray) {
ProfileTimer.startProfile("drawGeometry");
int numVertices = geoArray.getValidVertexCount();
//
if (numVertices == 0) {
if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping because there are no valid vertices ");
ProfileTimer.endProfile();
return;
}
// get the format of verticies
int format = geoArray.getVertexFormat();
int stripCount = 0;
int[] stripVertexCounts = null;
// if a strip array then get the above two values
if (geoArray instanceof GeometryStripArray) {
stripCount = ((GeometryStripArray) geoArray).getNumStrips();
stripVertexCounts = ((GeometryStripArray) geoArray).
getStripVertexCounts();
if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a strip array " + stripCount + " strips");
}
// find out if color3f data was supplied and if it was use it
int mode = 0;
if ((geoArray instanceof IndexedGeometryArray)) {
canvas.addTriangles( ((IndexedGeometryArray)geoArray).getValidIndexCount()/geoArray.getFaceSize());
} else if (geoArray instanceof TriangleArray) {
if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a triangle array with " + numVertices + " vertices");
mode = GL.GL_TRIANGLES; // say that we want to draw trianlges
canvas.addTriangles(numVertices/geoArray.getFaceSize());
} else if (geoArray instanceof QuadArray) {
if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a quad array with " + numVertices + " vertices");
mode = GL.GL_QUADS; // say that we want to draw quads
canvas.addTriangles(numVertices/geoArray.getFaceSize());
} else if (geoArray instanceof PointArray) {
mode = GL.GL_POINTS; // say that we want to draw points
canvas.addTriangles(numVertices/geoArray.getFaceSize());
} else if (geoArray instanceof LineArray) {
mode = GL.GL_LINES; // say that we want to draw lines
} else if (!(geoArray instanceof GeometryStripArray)) {
if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping unknown geometry : " + geoArray.getClass().getName());
ProfileTimer.endProfile();
return; // don't know how to draw this
}
// do the actual drawing genericly
setupBuffers(canvas, gl, geoArray);
if (geoArray instanceof GeometryStripArray) {
//setPointers(gl);
if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Starting drawing strips for GeometryStripArray");
// loop through the strips
if (geoArray instanceof LineStripArray) {
mode = GL.GL_LINE_STRIP; // say that we want to draw a line strip
} else if (geoArray instanceof TriangleStripArray) {
mode = GL.GL_TRIANGLE_STRIP; // say that we want to draw a triangle strip
// if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG,“Drawing a triangle strip “+strip+” of “+stripCount+” strips and “+stripVertexCounts[strip]+” vertices”);
} else if (geoArray instanceof TriangleFanArray) {
mode = GL.GL_TRIANGLE_FAN; // say that we want to draw a triangle fan
}
int start = 0;
for (int strip = 0; strip < stripCount; strip++) {
gl.glDrawArrays(mode, start, stripVertexCounts[strip]);
start += stripVertexCounts[strip];
}
} else if (geoArray instanceof IndexedGeometryArray) {
if (geoArray instanceof IndexedLineArray) {
mode = GL.GL_LINES; // say that we want to draw points
IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
}
if (geoArray instanceof IndexedQuadArray) {
mode = GL.GL_QUADS; // say that we want to draw points
IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
}
if (geoArray instanceof IndexedTriangleArray) {
mode = GL.GL_TRIANGLES; // say that we want to draw points
IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
} else if ( geoArray instanceof IndexedGeometryStripArray ) {
if ( geoArray instanceof IndexedTriangleStripArray ) {
mode = GL.GL_TRIANGLE_STRIP;
IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
int[] strips = igsa.getStripVertexCounts();
int start = 0;
for (int s = 0; s < strips.length; s++) {
gl.glDrawElements(mode,strips[s],GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
start += strips[s];
}
}
if ( geoArray instanceof IndexedLineStripArray ) {
mode = GL.GL_LINE_STRIP;
IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
int[] strips = igsa.getStripVertexCounts();
int start = 0;
for (int s = 0; s < strips.length; s++) {
gl.glDrawElements(mode,strips[s],GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
start += strips[s];
}
}
if ( geoArray instanceof IndexedTriangleFanArray ) {
mode = GL.GL_TRIANGLE_FAN;
IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
int[] strips = igsa.getStripVertexCounts();
int start = 0;
for (int s = 0; s < strips.length; s++) {
gl.glDrawElements(mode,strips[s],GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
start += strips[s];
}
}
}
} else {
gl.glDrawArrays(mode, geoArray.getInitialVertexIndex(), geoArray.getValidVertexCount());
}
ProfileTimer.endProfile();
}
i guess replacing the previous code with this one,will solve ur problem…try this…All the best… n plzzz let me know if it works…