Search in sources :

Example 1 with GLU

use of com.jogamp.opengl.glu.GLU in project Universal-G-Code-Sender by winder.

the class VisualizerCanvas method init.

// ------ Implement methods declared in GLEventListener ------
/**
 * Called back immediately after the OpenGL context is initialized. Can be used
 * to perform one-time initialization. Run only once.
 * GLEventListener method.
 */
@Override
public void init(GLAutoDrawable drawable) {
    logger.log(Level.INFO, "Initializing OpenGL context.");
    generateObject();
    this.fpsCounter = new FPSCounter(drawable, new Font("SansSerif", Font.BOLD, 12));
    this.overlay = new Overlay(drawable, new Font("SansSerif", Font.BOLD, 12));
    this.overlay.setColor(127, 127, 127, 100);
    this.overlay.setTextLocation(Overlay.LOWER_LEFT);
    // Parse random gcode file and generate something to draw.
    // get the OpenGL graphics context
    GL2 gl = drawable.getGL().getGL2();
    // get GL Utilities
    glu = new GLU();
    // set background (clear) color
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    // set clear depth value to farthest
    gl.glClearDepth(1.0f);
    // enables depth testing
    gl.glEnable(GL_DEPTH_TEST);
    // the type of depth test to do
    gl.glDepthFunc(GL_LEQUAL);
    // best perspective correction
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    // blends colors nicely, and smoothes out lighting
    gl.glShadeModel(GL_SMOOTH);
}
Also used : GLU(com.jogamp.opengl.glu.GLU) FPSCounter(com.willwinder.universalgcodesender.uielements.helpers.FPSCounter) Overlay(com.willwinder.universalgcodesender.uielements.helpers.Overlay) GL2(com.jogamp.opengl.GL2) Font(java.awt.Font)

Example 2 with GLU

use of com.jogamp.opengl.glu.GLU in project narchy by automenta.

the class JHelpSceneRenderer method reshape.

/**
 * Call by JOGL when 3D view is resize
 *
 * @param drawable
 *           Drawable context
 * @param x
 *           New X
 * @param y
 *           New Y
 * @param width
 *           New width
 * @param height
 *           New height
 * @see javax.media.opengl.GLEventListener#reshape(javax.media.opengl.GLAutoDrawable, int, int, int, int)
 */
@Override
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
    // Get OpenGL and GLU context
    final GLU glu = new GLU();
    final GL2 gl = (GL2) drawable.getGL();
    // Compute new view with new size
    this.width = drawable.getSurfaceWidth();
    this.height = drawable.getSurfaceHeight();
    final float ratio = (float) this.width / ((float) this.height);
    gl.glViewport(0, 0, this.width, this.height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(this.fov, ratio, 0.1f, 5000f);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}
Also used : GLU(com.jogamp.opengl.glu.GLU) GL2(com.jogamp.opengl.GL2)

Example 3 with GLU

use of com.jogamp.opengl.glu.GLU in project narchy by automenta.

the class JHelpSceneRenderer method display.

/**
 * Draw the OpenGL.<br>
 * It is call by JOGL when OpenGL need to be refresh
 *
 * @param drawable
 *           Drawable context
 * @see javax.media.opengl.GLEventListener#display(javax.media.opengl.GLAutoDrawable)
 */
@Override
public void display(final GLAutoDrawable drawable) {
    System.out.println("display: " + drawable);
    this.ready = false;
    // Get OpenGL and GLU context
    final GL2 gl = drawable.getGL().getGL2();
    final GLU glu = new GLUgl2();
    if (this.texturesToRemove.isEmpty() == false) {
        this.texturesToRemove.outQueue().removeFromMemory(gl);
    }
    // If a new scene wait, change the scene
    if (this.newScene != null) {
        this.scene = this.newScene;
        this.newScene = null;
    }
    // Update played animations
    this.playAnimations(gl);
    // Initialize for screen shot
    if ((this.screenShot == null) || (this.screenShot.getWidth() != this.width) || (this.screenShot.getHeight() != this.height)) {
        this.screenShot = null;
        this.screenShot = new JHelpImage(this.width, this.height);
    }
    // Refresh window materials
    for (final WindowMaterial windowMaterial : this.windowMaterials) {
        windowMaterial.refreshIfNeed();
    }
    // Get actual camera
    final Camera camera = this.scene.getCamera();
    // Render picking mode
    if (this.detectionActivate == true) {
        if (this.pickUVnode != null) {
            this.renderPickUV(gl, glu, camera);
        } else {
            this.renderPicking(gl, glu, camera);
        }
    }
    // Render the lights
    this.lights.render(gl);
    // Render the scene
    this.render(gl, glu, camera);
    // Take the snapshot
    this.makeSnapShot(gl, true);
    // Print FPS
    this.showFPS(gl, glu);
    // Update FPS
    this.updateFPS();
    // Make ready for the next loop
    gl.glEnable(GL2.GL_DEPTH_TEST);
    drawable.swapBuffers();
    this.ready = true;
    synchronized (this.LOCK) {
        this.LOCK.notify();
    }
}
Also used : GLU(com.jogamp.opengl.glu.GLU) GLUgl2(com.jogamp.opengl.glu.gl2.GLUgl2) JHelpImage(jhelp.util.gui.JHelpImage) WindowMaterial(jhelp.engine.gui.components.WindowMaterial) GL2(com.jogamp.opengl.GL2)

Example 4 with GLU

use of com.jogamp.opengl.glu.GLU in project narchy by automenta.

the class JHelpSceneRenderer method init.

/**
 * Call by JOGL on OpenGL initialization
 *
 * @param drawable
 *           Drawable context
 * @see javax.media.opengl.GLEventListener#init(javax.media.opengl.GLAutoDrawable)
 */
@Override
public void init(final GLAutoDrawable drawable) {
    // Delegate key and mouse events to this manager
    drawable.addGLEventListener(this);
    // drawable.addKeyListener(this);
    // drawable.addMouseListener(this);
    // drawable.addMouseMotionListener(this);
    // drawable.addMouseWheelListener(this);
    // Get OpenGL and GLU context
    final GLU glu = new GLU();
    final GL2 gl = drawable.getGL().getGL2();
    // Get dimensions and ration
    this.width = drawable.getSurfaceWidth();
    this.height = drawable.getSurfaceHeight();
    final float ratio = (float) this.width / (float) this.height;
    // Get number maximum of lights
    BufferUtils.TEMPORARY_INT_BUFFER.rewind();
    gl.glGetIntegerv(GL2.GL_MAX_LIGHTS, BufferUtils.TEMPORARY_INT_BUFFER);
    BufferUtils.TEMPORARY_INT_BUFFER.rewind();
    this.lights = new Lights(BufferUtils.TEMPORARY_INT_BUFFER.get());
    // *************************
    // *** Initialize OpenGL ***
    // *************************
    // Alpha enable
    gl.glEnable(GL2.GL_ALPHA_TEST);
    // Set alpha precision
    gl.glAlphaFunc(GL2.GL_GREATER, 0.01f);
    // Material can be colored
    gl.glEnable(GL2.GL_COLOR_MATERIAL);
    // For performance disable texture, we enable them only on need
    gl.glDisable(GL2.GL_TEXTURE_2D);
    // Way to compute alpha
    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
    // We accept blinding
    gl.glEnable(GL2.GL_BLEND);
    // Fix the view port
    gl.glViewport(0, 0, this.width, this.height);
    // Normalization is enable
    gl.glEnable(GL2.GL_NORMALIZE);
    // Fix the view port. Yes again, I don't know why, but it work better on
    // doing that
    gl.glViewport(0, 0, this.width, this.height);
    // Set the "3D feeling".
    // That is to say how the 3D looks like
    // Here we want just see the depth, but not have fish eye effect
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(45.0f, ratio, 0.1f, 5000f);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    // Initialize background
    gl.glClearColor(1f, 1f, 1f, 1f);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    // Enable see and hide face
    gl.glEnable(GL2.GL_CULL_FACE);
    gl.glCullFace(GL2.GL_FRONT);
    // Light base adjustment for smooth effect
    gl.glLightModeli(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, GL2.GL_TRUE);
    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);
    gl.glLightModeli(GL2.GL_LIGHT_MODEL_TWO_SIDE, 1);
    // Enable lights and default light
    gl.glEnable(GL2.GL_LIGHTING);
    ThreadManager.THREAD_MANAGER.doThread(this.fireEventScheduleAction, JHelpSceneRenderer.ACTION_FIRE_SCENE_RENDERER_IS_INITIALIZED);
}
Also used : GLU(com.jogamp.opengl.glu.GLU) GL2(com.jogamp.opengl.GL2)

Example 5 with GLU

use of com.jogamp.opengl.glu.GLU in project narchy by automenta.

the class JoglAbstractPanel method reshape.

@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
    float width = (float) getWidth();
    float height = (float) getHeight();
    GL2 gl2 = arg0.getGL().getGL2();
    gl2.glMatrixMode(GL2.GL_PROJECTION);
    gl2.glLoadIdentity();
    // coordinate system origin at lower left with width and height same as the window
    GLU glu = new GLU();
    glu.gluOrtho2D(0.0f, width, 0.0f, height);
    gl2.glMatrixMode(GL2.GL_MODELVIEW);
    gl2.glLoadIdentity();
    gl2.glViewport(0, 0, getWidth(), getHeight());
    if (controller != null) {
        controller.updateExtents(arg3 / 2, arg4 / 2);
    }
}
Also used : GLU(com.jogamp.opengl.glu.GLU)

Aggregations

GLU (com.jogamp.opengl.glu.GLU)9 GL2 (com.jogamp.opengl.GL2)6 FPSCounter (com.willwinder.universalgcodesender.uielements.helpers.FPSCounter)2 Overlay (com.willwinder.universalgcodesender.uielements.helpers.Overlay)2 GLUquadric (com.jogamp.opengl.glu.GLUquadric)1 GLUgl2 (com.jogamp.opengl.glu.gl2.GLUgl2)1 Font (java.awt.Font)1 WindowMaterial (jhelp.engine.gui.components.WindowMaterial)1 JHelpImage (jhelp.util.gui.JHelpImage)1