Java Reference
In-Depth Information
The first constant is used for the RGB pixel format, such as the data from an MIDP Image
object. The alpha channel is typically used to indicate transparency on systems that support it.
Luminance is an alternative way of encoding pixel data, typically used for monochrome images.
The second parameter can be an Image object from MIDP, allowing texture images to be
easily loaded from resource with code similar to the following:
mImage = Image.createImage( "/texture.png" );
Image2D image2D = new Image2D( Image2D.RGB, mImage );
Applying Texture Image to Triangle Strips
Once you have an image, you need to tell M3G how to map it to the triangle strips. This is done
through another vertex attribute called a texture coordinate . Figure 15-9 shows how the texture
is mapped to a surface (square) using texture coordinates.
Figure 15-9. Texture mapping a 3D surface
In Figure 15-9, you can see that the texture coordinates essentially tell M3G how to place
the texture on the surface by anchoring specific texture points to the vertices.
The code that performs the assignment of the texture coordinates to a VertexArray from
Listing 15-3 is reproduced here:
short[] texturecords = {
0,1, 1,1, 0, 0, 1, 0,
0,1, 0,0, 1, 1, 1, 0,
0,0, 1,0, 0, 1, 1, 1 };
VertexArray textureArray =
new VertexArray(texturecords.length / 2, 2, 2);
textureArray.set(0, texturecords.length/2, texturecords);
Search WWH ::




Custom Search