
|
June 2005 |
|||
|
| |||
|
Here we show how to use 3D texture in your JSR-184 MIDlet. This can be useful to generate nice effects or to gain some extra performance. The trick is to render your 3D world to an Image2D object and use that as a texture. The texture can also be animated by changing the 3D scene.
Render pyramid to Image2D texg3d.bindTarget(sceneTexture); // binds the Image2D graphics object
texg3d.render(texWorld); // render the pyramid to the Image2D … g3d.bindTarget(g); // Binds the given Graphics or mutable Image2D as the rendering target of this Graphics3D g3d.render(world); // Render the world The scene texture that is created must be sized to a non-negative power of two (2, 4, 8, 16 … 256).
sceneTexture = new Image2D(Image2D.RGB, 64, 64);
Use Image2D as texture and render mesh
Now create the texture to be used from this Image2D and set this texture to the appearance that is used for the plane.
Texture2D texture1 = new Texture2D(sceneTexture);
texture1.setBlending(Texture2D.FUNC_REPLACE); texture1.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP); texture1.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST); appearance.setTexture(0, texture1);
mesh.setAppearance(0, appearance);
Since the sceneTexture is just referenced in the texture1 object, the appearance of the sceneTexture can be changed at runtime. By doing this we get an animated texture.
| |||
Copyright © 2001 - 2009 Sony Ericsson Mobile Communications AB. All Rights Reserved.