Search in sources :

Example 1 with FPSCounter

use of com.willwinder.universalgcodesender.uielements.helpers.FPSCounter 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 FPSCounter

use of com.willwinder.universalgcodesender.uielements.helpers.FPSCounter in project Universal-G-Code-Sender by winder.

the class GcodeRenderer 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.");
    this.drawable = drawable;
    // TODO: Figure out scale factor / dimensions label based on GcodeRenderer
    /*
            this.scaleFactorBase = VisualizerUtils.findScaleFactor(this.xSize, this.ySize, this.objectMin, this.objectMax);
            this.scaleFactor = this.scaleFactorBase * this.zoomMultiplier;

            double objectWidth = this.objectMax.x-this.objectMin.x;
            double objectHeight = this.objectMax.y-this.objectMin.y;
            this.dimensionsLabel = Localization.getString("VisualizerCanvas.dimensions") + ": " 
                    + Localization.getString("VisualizerCanvas.width") + "=" + format.format(objectWidth) + " " 
                    + Localization.getString("VisualizerCanvas.height") + "=" + format.format(objectHeight);

        */
    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();
    // blends colors nicely, and smoothes out lighting
    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glClearColor(clearColor.getRed() / 255f, clearColor.getGreen() / 255f, clearColor.getBlue() / 255f, clearColor.getAlpha() / 255f);
    // set clear depth value to farthest
    gl.glClearDepth(1.0f);
    gl.glEnable(GL2.GL_BLEND);
    gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
    gl.glEnable(GL.GL_DEPTH_TEST);
    // the type of depth test to do
    gl.glDepthFunc(GL2.GL_LEQUAL);
    // best perspective correction
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
    /*
        gl.glLoadIdentity();
        float[] lmodel_ambient = { 0.5f, 0.5f, 0.5f, 1.0f };
        gl.glLightModelfv(GL2.GL_LIGHT_MODEL_AMBIENT, lmodel_ambient, 0);
        */
    // init lighting
    float[] ambient = { .6f, .6f, .6f, 1.f };
    float[] diffuse = { .6f, .6f, .6f, 1.0f };
    float[] position = { 0f, 0f, 20f, 1.0f };
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambient, 0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse, 0);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0);
    // Allow glColor to set colors
    gl.glEnable(GL2.GL_COLOR_MATERIAL);
    gl.glColorMaterial(GL.GL_FRONT, GL2.GL_DIFFUSE);
    gl.glColorMaterial(GL.GL_FRONT, GL2.GL_AMBIENT);
    // gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
    // gl.glColorMaterial(GL.GL_FRONT, GL2.GL_SPECULAR);
    float[] mat_specular = { 1.0f, 1.0f, 1.0f, 1.0f };
    float[] diffuseMaterial = { 0.5f, 0.5f, 0.5f, 1.0f };
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_DIFFUSE, diffuseMaterial, 0);
    // gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, mat_specular, 0);
    // gl.glMaterialf(GL.GL_FRONT, GL2.GL_SHININESS, 25.0f);
    // gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
    gl.glEnable(GL2.GL_LIGHTING);
    for (Renderable r : objects) {
        r.init(drawable);
    }
}
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)

Aggregations

GL2 (com.jogamp.opengl.GL2)2 GLU (com.jogamp.opengl.glu.GLU)2 FPSCounter (com.willwinder.universalgcodesender.uielements.helpers.FPSCounter)2 Overlay (com.willwinder.universalgcodesender.uielements.helpers.Overlay)2 Font (java.awt.Font)1