To render real objects with OpenGL, it's necessary to process a great amount of vertices or normals. So I would like skip processing, like reading from external files and generate arrays with so much elements dynamically, on running.
I found that it is possible. The concept is following using Java static variables.
a class defining vertices data:
public class ComplexObject {
public static FloatBuffer vertexBuffer;
static{
ByteBuffer vbb = ByteBuffer.allocateDirect(74 * 3 * 4);
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(new float[]{
0.53f, 0.3f, 3.55f,
/* definitions of vertices go on */
});
vertexBuffer.position(0);
}
}
To call the defined data:gl.glVertexPointer(3, GL10.GL_FLOAT, 0, ComplexObject.vertexBuffer);
What I did next is scratched a Java program to convert Wavefront .obj files into Java code. This worked fine, and generated codes so easily.
It is when I compile one of generated so long Java code. I encountered a problem that Java compiler alerts following:
The code for the static initializer is exceeding the 65535 bytes limit
In Java, many part of source code elements is limited to 65536 bytes:
http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html
It's been hard. To do next is implementing split method into converter or look for another solution.
No comments:
Post a Comment