Java Code Examples for com.jogamp.opengl.GLAutoDrawable#getSurfaceHeight()

The following examples show how to use com.jogamp.opengl.GLAutoDrawable#getSurfaceHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JCudaDriverVolumeRendererJOGL.java    From jcuda-samples with MIT License 6 votes vote down vote up
/**
 * Set up a default view for the given GLAutoDrawable
 * 
 * @param drawable The GLAutoDrawable to set the view for
 */
private void setupView(GLAutoDrawable drawable)
{
    GL2 gl = drawable.getGL().getGL2();

    int w = drawable.getSurfaceWidth();
    int h = drawable.getSurfaceHeight();
    gl.glViewport(0, 0, w, h);

    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
}
 
Example 2
Source File: NBodyVisualizer.java    From gpu-nbody with MIT License 5 votes vote down vote up
/**
 * Set up a default view for the given GLAutoDrawable
 * 
 * @param drawable
 *            The GLAutoDrawable to set the view for
 */
private void setupView(final GLAutoDrawable drawable) {
	final GL3 gl = (GL3) drawable.getGL();

	gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());

	final float aspect = (float) drawable.getSurfaceWidth() / drawable.getSurfaceHeight();
	projectionMatrix = perspective(50, aspect, 0.1f, 400.0f);
}
 
Example 3
Source File: JCudaDriverSimpleJOGL.java    From jcuda-samples with MIT License 5 votes vote down vote up
/**
 * Set up a default view for the given GLAutoDrawable
 * 
 * @param drawable The GLAutoDrawable to set the view for
 */
private void setupView(GLAutoDrawable drawable)
{
    GL3 gl = drawable.getGL().getGL3();
    int w = drawable.getSurfaceWidth();
    int h = drawable.getSurfaceHeight();
    gl.glViewport(0, 0, w, h);
    simpleInteraction.updateProjectionMatrix(w, h);
}
 
Example 4
Source File: HitTester.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f modelViewProjectionMatrix) {
    final GL3 gl = drawable.getGL().getGL3();
    if (needsResize) {
        gl.glBindRenderbuffer(GL3.GL_RENDERBUFFER, hitTestDepthBufferName[0]);
        gl.glRenderbufferStorage(GL3.GL_RENDERBUFFER, GL3.GL_DEPTH_COMPONENT32, width, height);

        gl.glBindRenderbuffer(GL3.GL_RENDERBUFFER, hitTestRboName[0]);
        gl.glRenderbufferStorage(GL3.GL_RENDERBUFFER, GL3.GL_R32F, width, height);

        gl.glBindRenderbuffer(GL3.GL_RENDERBUFFER, 0);
        needsResize = false;
    }
    if (!notificationQueues.isEmpty()) {
        final int x = hitTestRequest.getX();
        final int y = hitTestRequest.getY();

        //  Windows-DPI-Scaling
        //
        // If JOGL is ever fixed or another solution is found, either change
        // needsManualDPIScaling to return false (so there is effectively no
        // DPI scaling here) or to remove dpiScaleY below.            
        float dpiScaleY = 1.0f;
        if (GLTools.needsManualDPIScaling()) {
            dpiScaleY = parent.getDPIScaleY();
        }
        final int surfaceHeight = (int) (drawable.getSurfaceHeight() * dpiScaleY);

        // Allocate 3 floats for RGB values.
        FloatBuffer fbuf = Buffers.newDirectFloatBuffer(3);

        gl.glBindFramebuffer(GL3.GL_READ_FRAMEBUFFER, hitTestFboName[0]);
        gl.glReadBuffer(hitTestBufferName);
        gl.glReadPixels(x, surfaceHeight - y, 1, 1, GL3.GL_RGB, GL3.GL_FLOAT, fbuf);

        // There are enough colors in the buffer that we only need worry about
        // r component for now. That gives us 2**22 distinct values.
        final int r = (int) (fbuf.get(0));

        final int id;
        final HitType currentHitType;
        if (r == 0) {
            currentHitType = HitType.NO_ELEMENT;
            id = -1;
        } else {
            currentHitType = r > 0 ? HitType.VERTEX : HitType.TRANSACTION;
            id = r > 0 ? r - 1 : -r - 1;
        }

        final HitState hitState = hitTestRequest.getHitState();
        hitState.setCurrentHitId(id);
        hitState.setCurrentHitType(currentHitType);
        if (hitTestRequest.getFollowUpOperation() != null) {
            hitTestRequest.getFollowUpOperation().accept(hitState);
        }
        synchronized (this.notificationQueues) {
            while (!notificationQueues.isEmpty()) {
                final Queue<HitState> queue = notificationQueues.remove();
                if (queue != null) {
                    queue.add(hitState);
                }
            }
        }
    }
}
 
Example 5
Source File: GPUUISceneGLListener0A.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
public void display(final GLAutoDrawable drawable) {
    // System.err.println("GPUUISceneGLListener0A: display");
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    if(null == labels[currentText]) {
        final float pixelSizeFixed = fontSizeFixedPVP * drawable.getSurfaceHeight();
        final float dyTop = drawable.getSurfaceHeight() - 2f*jogampLabel.getLineHeight();
        final float dxMiddle = drawable.getSurfaceWidth() * relMiddle;
        labels[currentText] = new Label(renderer.getRenderState().getVertexFactory(), renderModes, font, pixelSizeFixed, strings[currentText]);
        labels[currentText].setColor(0.1f, 0.1f, 0.1f, 1.0f);
        labels[currentText].setEnabled(enableOthers);
        labels[currentText].translate(dxMiddle,
                                      dyTop - 1.5f * jogampLabel.getLineHeight()
                                            - 1.5f * truePtSizeLabel.getLineHeight(), 0f);
        labels[currentText].addMouseListener(dragZoomRotateListener);
        sceneUIController.addShape(labels[currentText]);
        System.err.println("Label["+currentText+"] CTOR: "+labels[currentText]);
        System.err.println("Label["+currentText+"] CTOR: "+Arrays.toString(labels[currentText].getTranslate()));
    }
    if( fpsLabel.isEnabled() ) {
        final float lfps, tfps, td;
        final GLAnimatorControl animator = drawable.getAnimator();
        if( null != animator ) {
            lfps = animator.getLastFPS();
            tfps = animator.getTotalFPS();
            td = animator.getTotalFPSDuration()/1000f;
        } else {
            lfps = 0f;
            tfps = 0f;
            td = 0f;
        }
        final String modeS = Region.getRenderModeString(renderModes);
        final String text;
        if( null == actionText ) {
            final String timePrec = gl.isGLES() ? "4.0" : "4.1";
            text = String.format("%03.1f/%03.1f fps, v-sync %d, dpi %.1f, fontSize %.1f, %s-samples %d, q %d, td %"+timePrec+"f, blend %b, alpha %d, msaa %d",
                lfps, tfps, gl.getSwapInterval(), dpiH, fontSizeFixedPVP, modeS, sceneUIController.getSampleCount(), fpsLabel.getQuality(), td,
                renderer.getRenderState().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED),
                drawable.getChosenGLCapabilities().getAlphaBits(),
                drawable.getChosenGLCapabilities().getNumSamples());
        } else {
            text = String.format("%03.1f/%03.1f fps, v-sync %d, fontSize %.1f, %s",
                lfps, tfps, gl.getSwapInterval(), fontSizeFixedPVP, actionText);
        }
        fpsLabel.setText(text);
    }
    sceneUIController.display(drawable);
}
 
Example 6
Source File: GPUUISceneGLListener0A.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
     System.err.println("GPUUISceneGLListener0A: reshape");

     //
     // Layout all shapes: Relational move regarding window coordinates
     //
     final float dw = width - lastWidth;
     final float dh = height - lastHeight;

     final float dz = 0f;
     final float dyTop = dh * relTop;
     final float dxLeft = dw * relLeft;
     final float dxRight = dw;

     for(int i=0; i<buttons.size() && i<buttonsLeftCount; i++) {
         buttons.get(i).translate(dxLeft, dyTop, dz);
     }
     for(int i=buttonsLeftCount; i<buttons.size(); i++) {
         buttons.get(i).translate(dxRight, dyTop, dz);
     }
     final float dxMiddleAbs = width * relMiddle;
     final float dyTopLabelAbs = drawable.getSurfaceHeight() - 2f*jogampLabel.getLineHeight();
     jogampLabel.setTranslate(dxMiddleAbs, dyTopLabelAbs, dz);
     truePtSizeLabel.setTranslate(dxMiddleAbs, dyTopLabelAbs, dz);
     truePtSizeLabel.setTranslate(dxMiddleAbs, dyTopLabelAbs - 1.5f * jogampLabel.getLineHeight(), 0f);
     fpsLabel.translate(0f, 0f, 0f);
     if( null != labels[currentText] ) {
         labels[currentText].setTranslate(dxMiddleAbs,
                                          dyTopLabelAbs - 1.5f * jogampLabel.getLineHeight()
                                          - 1.5f * truePtSizeLabel.getLineHeight(), 0f);
         System.err.println("Label["+currentText+"] MOVE: "+labels[currentText]);
         System.err.println("Label["+currentText+"] MOVE: "+Arrays.toString(labels[currentText].getTranslate()));
     }
     crossHairCtr.translate(dw/2f, dh/2f, 0f);

     sceneUIController.reshape(drawable, x, y, width, height);

     lastWidth = width;
     lastHeight = height;
}
 
Example 7
Source File: TextRendererGLELBase.java    From jogl-samples with MIT License 4 votes vote down vote up
private void renderStringImpl(final GLAutoDrawable drawable,
                              final Font font, final float pixelSize, final String text,
                              final int column, final int row,
                              final float tx, final float ty, final float tz, final boolean cacheRegion, final GLRegion region) {
    if( null != renderer ) {
        final GL2ES2 gl = drawable.getGL().getGL2ES2();

        float dx = tx;
        float dy;

        if( !exclusivePMVMatrix )  {
            dy = 1f-ty;
        } else {
            final int height = drawable.getSurfaceHeight();
            dy = height-ty;
        }
        final int newLineCount = TextRegionUtil.getCharCount(text, '\n');
        final float lineHeight = font.getLineHeight(pixelSize);
        dx += pixelScale * font.getAdvanceWidth('X', pixelSize) * column;
        dy -= pixelScale * lineHeight * ( row + 1 );

        final PMVMatrix pmvMatrix = rs.getMatrix();
        pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
        if( !exclusivePMVMatrix )  {
            pmvMatrix.glPushMatrix();
        } else {
            pmvMatrix.glLoadIdentity();
        }
        pmvMatrix.glTranslatef(dx, dy, tz);
        if( flipVerticalInGLOrientation && drawable.isGLOriented() ) {
            pmvMatrix.glScalef(pixelScale, -1f*pixelScale, 1f);
        } else if( 1f != pixelScale ) {
            pmvMatrix.glScalef(pixelScale, pixelScale, 1f);
        }
        renderer.enable(gl, true);
        if( cacheRegion ) {
            textRenderUtil.drawString3D(gl, renderer, font, pixelSize, text, null, vbaaSampleCount);
        } else if( null != region ) {
            TextRegionUtil.drawString3D(gl, region, renderer, font, pixelSize, text, null, vbaaSampleCount,
                                        textRenderUtil.tempT1, textRenderUtil.tempT2);
        } else {
            TextRegionUtil.drawString3D(gl, renderModes, renderer, font, pixelSize, text, null, vbaaSampleCount,
                                        textRenderUtil.tempT1, textRenderUtil.tempT2);
        }
        renderer.enable(gl, false);

        if( !exclusivePMVMatrix )  {
            pmvMatrix.glPopMatrix();
        }
        lastRow = row + newLineCount;
    }
}