Java Code Examples for com.jogamp.opengl.GL2ES2#glClear()

The following examples show how to use com.jogamp.opengl.GL2ES2#glClear() . 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: GPURegionGLListener01.java    From jogl-samples with MIT License 6 votes vote down vote up
public void display(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    final RegionRenderer regionRenderer = getRenderer();
    final PMVMatrix pmv = regionRenderer.getMatrix();
    pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmv.glLoadIdentity();
    pmv.glTranslatef(getXTran(), getYTran(), getZTran());
    pmv.glRotatef(getAngle(), 0, 1, 0);
    if( weight != regionRenderer.getRenderState().getWeight() ) {
        regionRenderer.getRenderState().setWeight(weight);
    }
    region.draw(gl, regionRenderer, getSampleCount());
}
 
Example 2
Source File: GPURegionGLListener02.java    From jogl-samples with MIT License 6 votes vote down vote up
public void display(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    final RegionRenderer regionRenderer = getRenderer();

    final PMVMatrix pmv = regionRenderer.getMatrix();
    pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmv.glLoadIdentity();
    pmv.glTranslatef(getXTran(), getYTran(), getZTran());
    pmv.glRotatef(getAngle(), 0, 1, 0);
    if( weight != regionRenderer.getRenderState().getWeight() ) {
        regionRenderer.getRenderState().setWeight(weight);
    }
    region.draw(gl, regionRenderer, getSampleCount());

}
 
Example 3
Source File: UIGLListener01.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
public void display(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    final int[] sampleCount = { 4 };
    final float[] translate = button.getTranslate();

    final RegionRenderer regionRenderer = getRegionRenderer();
    final PMVMatrix pmv = regionRenderer.getMatrix();
    pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmv.glLoadIdentity();
    pmv.glTranslatef(getXTran(), getYTran(), getZoom());
    pmv.glRotatef(getAngle(), 0, 1, 0);
    pmv.glTranslatef(translate[0], translate[1], 0);
    button.drawShape(gl, regionRenderer, sampleCount);
}
 
Example 4
Source File: SceneUIController.java    From jogl-samples with MIT License 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void display(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    final PMVMatrix pmv = renderer.getMatrix();
    pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);

    final Object[] shapesS = shapes.toArray();
    Arrays.sort(shapesS, (Comparator)shapeZAscComparator);

    renderer.enable(gl, true);

    //final int shapeCount = shapes.size();
    final int shapeCount = shapesS.length;
    for(int i=0; i<shapeCount; i++) {
        // final UIShape uiShape = shapes.get(i);
        final UIShape uiShape = (UIShape)shapesS[i];
        // System.err.println("Id "+i+": "+uiShape);
        if( uiShape.isEnabled() ) {
            uiShape.validate(gl, renderer);
            pmv.glPushMatrix();
            transformShape(pmv, uiShape);
            uiShape.drawShape(gl, renderer, sampleCount);
            pmv.glPopMatrix();
        }
    }

    renderer.enable(gl, false);
}
 
Example 5
Source File: Es_200_draw_elements.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL2ES2 gl2es2 = (GL2ES2) gl;

    // Compute the MVP (Model View Projection matrix)
    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    // Set the display viewport
    gl2es2.glViewport(0, 0, windowSize.x, windowSize.y);

    // Clear color buffer with black
    gl2es2.glClearColor(0f, 0f, 0f, 1f);
    gl2es2.glClearDepthf(1f);
    gl2es2.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Bind program
    gl2es2.glUseProgram(programName);

    // Set the value of MVP uniform.
    gl2es2.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl2es2.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
    {
        gl2es2.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, 0, 0);
    }
    gl2es2.glBindBuffer(GL_ARRAY_BUFFER, 0);
    gl2es2.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));

    gl2es2.glEnableVertexAttribArray(Semantic.Attr.POSITION);
    {
        gl2es2.glDrawElements(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0);
    }
    gl2es2.glDisableVertexAttribArray(Semantic.Attr.POSITION);

    // Unbind program
    gl2es2.glUseProgram(0);

    return true;
}
 
Example 6
Source File: TestTextRendererNEWTBugXXXX.java    From jogl-samples with MIT License 4 votes vote down vote up
void testTextRendererImpl(final Font[] fonts, final int renderModes, final int sampleCount, final boolean onlyIssues) throws InterruptedException, GLException, IOException {
    final GLProfile glp;
    if(forceGL3) {
        glp = GLProfile.get(GLProfile.GL3);
    } else if(forceES2) {
        glp = GLProfile.get(GLProfile.GLES2);
    } else {
        glp = GLProfile.getGL2ES2();
    }

    final GLCapabilities caps = new GLCapabilities( glp );
    caps.setAlphaBits(4);
    if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
        caps.setSampleBuffers(true);
        caps.setNumSamples(sampleCount);
    }
    caps.setOnscreen(false);
    System.err.println("Requested: "+caps);
    System.err.println("Requested: "+Region.getRenderModeString(renderModes));

    final int totalHeight = ( (int)fontSize + 1 ) * ( onlyIssues ? 3 : 6 ) * fonts.length;
    final NEWTGLContext.WindowContext winctx =
            NEWTGLContext.createWindow(caps, 800, totalHeight, true);
    final GLDrawable drawable = winctx.context.getGLDrawable();
    final GL2ES2 gl = winctx.context.getGL().getGL2ES2();

    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    System.err.println("Chosen: "+winctx.window.getChosenCapabilities());

    final RenderState rs = RenderState.createRenderState(SVertex.factory());
    final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
    rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
    final TextRegionUtil textRenderUtil = new TextRegionUtil(renderModes);

    // init
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    renderer.init(gl, 0);
    rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
    screenshot = new GLReadBufferUtil(false, false);

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

    // renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
    renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);

    final int[] sampleCountIO = { sampleCount };
    // display
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    for(int i=0; i<fonts.length; i++) {
        final Font font = fonts[i];
        renderString(drawable, gl, renderer, font, textRenderUtil, font.getFullFamilyName(null).toString()+": "+issues, 0,  0==i?0:-1, -1000, sampleCountIO);
        if(!onlyIssues) {
            renderString(drawable, gl, renderer, font, textRenderUtil, "012345678901234567890123456789", 0,  -1, -1000, sampleCountIO);
            renderString(drawable, gl, renderer, font, textRenderUtil, "abcdefghijklmnopqrstuvwxyz", 0, -1, -1000, sampleCountIO);
            renderString(drawable, gl, renderer, font, textRenderUtil, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, -1, -1000, sampleCountIO);
        }
        renderString(drawable, gl, renderer, font, textRenderUtil, "", 0, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, font, textRenderUtil, "", 0, -1, -1000, sampleCountIO);
    }

    drawable.swapBuffers();
    printScreen(renderModes, drawable, gl, false, sampleCount);

    sleep();

    // dispose
    screenshot.dispose(gl);
    renderer.destroy(gl);

    NEWTGLContext.destroyWindow(winctx);
}
 
Example 7
Source File: TestTextRendererNEWT10.java    From jogl-samples with MIT License 4 votes vote down vote up
void testTextRendererImpl(final int renderModes, final int sampleCount) throws InterruptedException, GLException, IOException {
    final GLProfile glp;
    if(forceGL3) {
        glp = GLProfile.get(GLProfile.GL3);
    } else if(forceES2) {
        glp = GLProfile.get(GLProfile.GLES2);
    } else {
        glp = GLProfile.getGL2ES2();
    }

    final GLCapabilities caps = new GLCapabilities( glp );
    caps.setAlphaBits(4);
    if( 0 < sampleCount && !Region.isVBAA(renderModes) ) {
        caps.setSampleBuffers(true);
        caps.setNumSamples(sampleCount);
    }
    System.err.println("Requested: "+caps);
    System.err.println("Requested: "+Region.getRenderModeString(renderModes));

    final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(caps, 800, 400, true);
    final GLDrawable drawable = winctx.context.getGLDrawable();
    final GL2ES2 gl = winctx.context.getGL().getGL2ES2();

    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    System.err.println("Chosen: "+winctx.window.getChosenCapabilities());

    final RenderState rs = RenderState.createRenderState(SVertex.factory());
    final RegionRenderer renderer = RegionRenderer.create(rs, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
    rs.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);
    final TextRegionUtil textRenderUtil = new TextRegionUtil(renderModes);

    // init
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    renderer.init(gl, 0);
    rs.setColorStatic(0.1f, 0.1f, 0.1f, 1.0f);
    screenshot = new GLReadBufferUtil(false, false);

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

    // renderer.reshapePerspective(gl, 45.0f, drawable.getWidth(), drawable.getHeight(), 0.1f, 1000.0f);
    renderer.reshapeOrtho(drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0.1f, 1000.0f);

    final int[] sampleCountIO = { sampleCount };
    // display
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    if( null == customStr ) {
        renderString(drawable, gl, renderer, textRenderUtil, "012345678901234567890123456789", 0,  0, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "Hello World", 0, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "4567890123456", 4, -1, -1000,sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "I like JogAmp", 4, -1, -1000, sampleCountIO);

        int c = 0;
        renderString(drawable, gl, renderer, textRenderUtil, "GlueGen", c++, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "JOAL", c++, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "JOGL", c++, -1, -1000, sampleCountIO);
        renderString(drawable, gl, renderer, textRenderUtil, "JOCL", c++, -1, -1000, sampleCountIO);
    } else {
        renderString(drawable, gl, renderer, textRenderUtil, customStr, 0,  0, -1000, sampleCountIO);
    }
    drawable.swapBuffers();
    printScreen(renderModes, drawable, gl, false, sampleCount);

    sleep();

    // dispose
    screenshot.dispose(gl);
    renderer.destroy(gl);

    NEWTGLContext.destroyWindow(winctx);
}