Specifications
Developers guidelines | 3D graphics with Java ME
42 June 2010
vertexBuffer.setTexCoords(1, TEXTURE_ARRAY, (1.0f/255.0f),
null);
appearance.setTexture(0, texture); // add the texture to the
appearance.
apperance.setTexture(1, texture2); // add the second texture to
the appearance
Q: I have specified three different colors for a triangle (one for each vertex) but it only
shows one color. Why?
A: To show all three colors and get a smooth shading you have to specify the
SHADE_SMOOTH parameter for the PolygonMode that you are using.
For example:
public Mesh createTriangle() {
short []POINTS = new short[] {-1,-1, 0,
1,-1, 0,
0, 1, 0};
int []INDICES = new int[] {0, 1, 2};
byte []COLORS = new byte[] {127, 0, 0,
0, 127, 0,
0, 0, 127};
int []LENGTH = new int[] {3};
VertexArray POSITION_ARRAY, COLOR_ARRAY;
IndexBuffer INDEX_BUFFER;
POSITION_ARRAY = new VertexArray(POINTS.length / 3, 3,
2);
POSITION_ARRAY.set(0, POINTS.length / 3, POINTS);
COLOR_ARRAY = new VertexArray(COLORS.length / 3, 3, 1);
COLOR_ARRAY.set(0, COLORS.length / 3, COLORS);
INDEX_BUFFER = new TriangleStripArray(INDICES, LENGTH);
VertexBuffer vertexBuffer = new VertexBuffer();
vertexBuffer.setPositions(POSITION_ARRAY, 1.0f, null);
vertexBuffer.setColors(COLOR_ARRAY);
Mesh mesh = new Mesh(vertexBuffer, INDEX_BUFFER, null);
Appearance appearance = new Appearance();
PolygonMode polygonMode = new PolygonMode();
polygonMode.setPerspectiveCorrectionEnable(true);
polygonMode.setCulling(PolygonMode.CULL_NONE);
polygonMode.setShading(PolygonMode.SHADE_SMOOTH);
appearance.setPolygonMode(polygonMode);
mesh.setAppearance(0, appearance);
return mesh;
}