Specifications
Developers guidelines | 3D graphics with Java ME
43 June 2010
Q: I have created a triangle, but when I rotate the plane it disappears after rotating 90
degrees and remains invisible until it has rotated 270 degrees. The backside of the
triangle is black ?
A: This is a method called back culling and it is used to gain performance by showing
only the front side of each polygon. You can specify the culling in the PolygonMode
class:
PolygonMode polygonMode = new PolygonMode();
polygonMode.setCulling(PolygonMode.C ULL_BACK);
appearance.setPolygonMode(polygonMode);
Q: How can I set texture coordinates on a figure with multiple vertices when the
VertexArray doesn't allow floating numbers and the texture coordinates must have
values between 0 and 1?
A: Enter your texture coordinates with values from 0 to 255. When you apply your
texture coordinates to the VertexBuffer, you scale them down by 1.0f/255.0f:
vertexBuffer.setTexCoords(0, TEXTURE_ARRAY, (1.0f/255.0f),
null);
Do not forget that the texture maps width and height must be a non-negative power of
two (2, 4, 8, 16, 32, 64, 128, 256).
Q: Should the objects in the .m3g files be compressed or uncompressed?
A: When .m3g files are shipped inside the application .jar file, it is preferrable to leave
the object data uncompressed. This is because .jar files are compressed anyway so
compressing the object data would just give the phone the overhead of loading the
compressed m3g while gaining nothing in terms of file size.
Q: Is it possible to just specify eight vertices for a cube and still specify the right texture
and normal coordinates?
A: It is possible to draw a cube where three faces share the same vertex and set colors
to it. But texture and normal coordinates requires unique values for each vertex, which
means that you must specify four vertices for each face on the cube.
Specify eight points for the cube and then use an IndexBuffer to specify how to
draw the triangles, remember that each face of the cube is built of two triangles.
For example:
short POINTS[] = new short[] {1, 1, 1, // 0
1,-1, 1, // 1
-1, 1, 1, // 2
-1,-1, 1, // 3
-1, 1,-1, // 4
-1,-1,-1, // 5
1, 1,-1, // 6
1,-1,-1}; // 7