
gnu.app.redbook.SurfaceTexture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of escher Show documentation
Show all versions of escher Show documentation
Escher is a collection of libraries for X Window System written purely in Java.
The newest version!
package gnu.app.redbook;
import gnu.x11.extension.glx.GL;
import gnu.util.Misc;
import gnu.x11.Data;
/**
* Draw a surface with texture. To demonstrate how to evaluators to
* generate a curved surface and automatically generated texture
* coordinates. Modified from texturesuf.c
.
*
* @see
* screenshot
*
* @see
* help output
*/
public class SurfaceTexture extends gnu.x11.extension.glx.Application {
private static final int IMAGE_SIZE = 64;
private static final byte [] IMAGE = new byte [IMAGE_SIZE * IMAGE_SIZE * 3];
private static final float [] [] [] CONTROL_POINTS = {
{{-1.5f, -1.5f, 4.0f},
{-0.5f, -1.5f, 2.0f},
{0.5f, -1.5f, -1.0f},
{1.5f, -1.5f, 2.0f}},
{{-1.5f, -0.5f, 1.0f},
{-0.5f, -0.5f, 3.0f},
{0.5f, -0.5f, 0.0f},
{1.5f, -0.5f, -1.0f}},
{{-1.5f, 0.5f, 4.0f},
{-0.5f, 0.5f, 0.0f},
{0.5f, 0.5f, 3.0f},
{1.5f, 0.5f, 4.0f}},
{{-1.5f, 1.5f, -2.0f},
{-0.5f, 1.5f, -2.0f},
{0.5f, 1.5f, 0.0f},
{1.5f, 1.5f, -1.0f}}
};
private static final float [] [] TEXTURE_POINTS = {
{0.0f, 0.0f},
{0.0f, 1.0f},
{1.0f, 0.0f},
{1.0f, 1.0f}
};
public SurfaceTexture (String [] args) {
super (args, RESIZE_BIT);
about ("0.1", "surface texture",
"Stephen Tse ",
"http://escher.sourceforge.net/");
if (help_option) return;
visual_config.set_depth_size (1);
init_window (500, 500);
gl.enable (GL.DEPTH_TEST);
gl.enable (GL.MAP2_VERTEX_3);
gl.enable (GL.MAP2_TEXTURE_COORD_2);
gl.enable (GL.TEXTURE_2D);
gl.shade_model (GL.FLAT);
gl.map2f (GL.MAP2_VERTEX_3, 0.0f, 1.0f, 3, 4,
0.0f, 1.0f, 12, 4, Misc.linearize (CONTROL_POINTS));
gl.map2f (GL.MAP2_TEXTURE_COORD_2, 0.0f, 1.0f, 2, 2,
0.0f, 1.0f, 4, 2, Misc.linearize (TEXTURE_POINTS));
gl.map_grid2f (20, 0.0f, 1.0f, 20, 0.0f, 1.0f);
init_images ();
init_texture ();
}
protected void handle_expose () {
gl.clear (GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
gl.eval_mesh2 (GL.FILL, 0, 20, 0, 20);
gl.swap_buffers (window);
}
protected void handle_resize (int width, int height) {
gl.viewport (0, 0, width, height);
gl.matrix_mode (GL.PROJECTION);
gl.load_identity ();
double wh = (float) width / (float) height;
double hw = (float) height / (float) width;
if (width <= height)
gl.ortho (-4.0, 4.0, -4.0*hw, 4.0*hw, -4.0, 4.0);
else
gl.ortho (-4.0*wh, 4.0*wh, -4.0, 4.0, -4.0, 4.0);
gl.matrix_mode (GL.MODELVIEW);
gl.load_identity ();
gl.rotatef (85.0f, 1.0f, 1.0f, 1.0f);
}
private void init_images () {
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy