Package test3d.nehe

Source Code of test3d.nehe.NeHe02

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test3d.nehe;

import javax.media.opengl.GL2;
import test3d.Test3D;
import xenon3d.Canvas3D;
import xenon3d.View3D;
import xenon3d.Xenon3D;
import xenon3d.scene.GraphicsContext3D;

/**
* NeHe Tutorial 02: "Your First Polygon".<p>
* New Features: Issue GL commands through the Canvas3D RenderListener interface.
*/
public class NeHe02 implements Test3D {
   
    // <editor-fold defaultstate="collapsed" desc=" Constant Attributes ">
   
    /** The test title. */
    private static final String TITLE = "Your First Polygon";
   
    /** The test id. */
    private static final String ID = "02";
   
    /** The package screen name. */
    private static final String PACKAGE = "NeHe";
   
    /** The window caption. */
    private static final String CAPTION = PACKAGE + " " + ID + " - " + TITLE;
   
    // </editor-fold>
   
    // <editor-fold defaultstate="collapsed" desc=" Private Fields ">
   
    /** The Xenon3D master window. */
    private Xenon3D xenon;
   
    /** The Canvas3D to render the scene into. */
    private Canvas3D canvas;
   
    /** The View3D which defines the view to the scene. */
    private View3D view;
   
    // </editor-fold>
   
    // <editor-fold defaultstate="collapsed" desc=" Initialization ">
   
    /**
     * Creates a new NeHe01 example object.
     */
    public NeHe02() {
        xenon = new Xenon3D(CAPTION);
        view = new View3D();
        view.setViewModePolicy(View3D.ViewModePolicy.Trace);
        canvas = createCanvas3D();
        canvas.attachView(view);
        xenon.attachCanvas(canvas);
    }
   
    /**
     * Starts the NeHe01 example program.
     * @param args  the param array
     */
    public static void main(String[] args) {
        NeHe02 app = new NeHe02();
    }
   
    // </editor-fold>
   
    // <editor-fold defaultstate="collapsed" desc=" Implemtation Test3D ">
   
    @Override
    public String getTitle() {
        return TITLE;
    }
   
    /**
     * Returns the test package screen name.
     * @return the package screen name
     */
    public String getPackageName() {
        return PACKAGE;
    }
   
    /**
     * Returns the test id.
     * @return the test id
     */
    public String getId() {
        return ID;
    }
   
    // </editor-fold>
   
    // <editor-fold defaultstate="collapsed" desc=" Local Canvas3D Class ">
   
    /**
     * Returns a new customized Canvas3D object.
     * @return the new Canvas3D
     */
    private Canvas3D createCanvas3D() {
        return new Canvas3D() {
           
            @Override
            public void init() {
                System.out.println("Canvas3D.init()");
            }
           
            @Override
            public void reshape(int width, int height) {
                System.out.println("Canvas3D.reshape(" + width + ", " + height + ")");
            }
           
            @Override
            public void preRender() {
                System.out.println("Canvas3D.preRender()");
            }
           
            @Override
            public void render() {
                System.out.println("Canvas3D.render()");
                GraphicsContext3D gc = GraphicsContext3D.getGC();
    GL2 gl = gc.getGL();
    gl.glTranslatef(-1.5f, 0.0f, -6.0f);
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glVertex3f( 0.0f1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 0.0f);
    gl.glVertex3f( 1.0f, -1.0f, 0.0f);
    gl.glEnd();
    gl.glTranslatef(3.0f, 0.0f, 0.0f);
    gl.glBegin(GL2.GL_QUADS);
    gl.glVertex3f(-1.0f1.0f, 0.0f);
    gl.glVertex3f( 1.0f1.0f, 0.0f);
    gl.glVertex3f( 1.0f, -1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 0.0f);
    gl.glEnd();
            }
           
            @Override
            public void postRender() {
                System.out.println("Canvas3D.postRender()");
            }
           
            @Override
            public void dispose() {
                System.out.println("Canvas3D.dispose()");
            }
           
        };
    }
   
    // </editor-fold>

} // end class NeHe02
TOP

Related Classes of test3d.nehe.NeHe02

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.