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

The following examples show how to use com.jogamp.opengl.GL3#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: Gl_320_glsl_discard.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    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);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearColor(1.0f, 0.5f, 0.0f, 1.0f);
    gl3.glClear(GL_COLOR_BUFFER_BIT);

    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));
    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);

    return true;
}
 
Example 2
Source File: Gl_300_fbo_multisample.java    From jogl-samples with MIT License 6 votes vote down vote up
private void renderFBO(GL3 gl3, int framebuffer) {

        gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
        gl3.glClearColor(0.0f, 0.5f, 1.0f, 1.0f);
        gl3.glClear(GL_COLOR_BUFFER_BIT);

        Mat4 perspective = glm.perspective_((float) Math.PI * 0.25f, (float) FRAMEBUFFER_SIZE.x / FRAMEBUFFER_SIZE.y,
                0.1f, 100.0f);
        Mat4 model = new Mat4(1.0f);
        Mat4 mvp = perspective.mul(viewMat4()).mul(model);
        gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

        gl3.glViewport(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y);

        gl3.glActiveTexture(GL_TEXTURE0);
        gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE));

        gl3.glBindVertexArray(vertexArrayName.get(0));
        gl3.glDrawArrays(GL_TRIANGLES, 0, vertexCount);

        checkError(gl3, "renderFBO");
    }
 
Example 3
Source File: Gl_300_test_alpha.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f);
    Mat4 model = new Mat4(1.0f);
    Mat4 mvp = projection.mul(viewMat4()).mul(model);

    gl3.glViewport(0, 0, windowSize.x, windowSize.y);
    gl3.glClearColor(1.0f, 0.5f, 0.0f, 1.0f);
    gl3.glClear(GL_COLOR_BUFFER_BIT);

    gl3.glUseProgram(programName);
    gl3.glUniform1i(uniformDiffuse, 0);
    gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

    gl3.glActiveTexture(GL_TEXTURE0);
    gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0));

    gl3.glBindVertexArray(vertexArrayName.get(0));

    gl3.glDrawArrays(GL_TRIANGLES, 0, vertexCount);

    return true;
}
 
Example 4
Source File: NBodyVisualizer.java    From gpu-nbody with MIT License 4 votes vote down vote up
/**
 * Implementation of GLEventListener: Called when the given GLAutoDrawable is to be displayed.
 */
@Override
public void display(final GLAutoDrawable drawable) {

	if (!initialized) {
		return;
	}
	final GL3 gl = (GL3) drawable.getGL();

	// run computation
	// Map OpenGL buffer object for writing from OpenCL
	gl.glFinish();
	simulation.step();

	gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Activate the shader program
	gl.glUseProgram(shaderProgramID);

	// Set the current projection matrix
	final int projectionMatrixLocation = gl.glGetUniformLocation(shaderProgramID, "projectionMatrix");
	gl.glUniformMatrix4fv(projectionMatrixLocation, 1, false, projectionMatrix, 0);

	// Set the current modelview matrix
	final int modelviewMatrixLocation = gl.glGetUniformLocation(shaderProgramID, "modelviewMatrix");
	gl.glUniformMatrix4fv(modelviewMatrixLocation, 1, false, modelviewMatrix, 0);

	final int screenSizeLocation = gl.glGetUniformLocation(shaderProgramID, "screenSize");
	gl.glUniform2f(screenSizeLocation, glComponent.getWidth(), glComponent.getHeight());

	final int spriteSizeLocation = gl.glGetUniformLocation(shaderProgramID, "spriteSize");
	gl.glUniform1f(spriteSizeLocation, 0.1f);

	bodyTexture.enable(gl);
	bodyTexture.bind(gl);
	final int textureLocation = gl.glGetUniformLocation(shaderProgramID, "tex");
	gl.glUniform1i(textureLocation, bodyTexture.getTarget());

	// Render the VBO
	gl.glEnable(GL_TEXTURE_2D);
	gl.glEnable(GL_BLEND);
	gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE);

	final int velLocation = gl.glGetAttribLocation(shaderProgramID, "inVelocity");
	gl.glBindBuffer(GL_ARRAY_BUFFER, velocityVBO);
	gl.glEnableVertexAttribArray(velLocation);
	gl.glVertexAttribPointer(velLocation, 4, GL3.GL_FLOAT, false, 0, 0);

	final int inVertexLocation = gl.glGetAttribLocation(shaderProgramID, "inVertex");
	gl.glBindBuffer(GL_ARRAY_BUFFER, positionVBO);
	gl.glEnableVertexAttribArray(inVertexLocation);
	gl.glVertexAttribPointer(inVertexLocation, 4, GL3.GL_FLOAT, false, 0, 0);

	gl.glDrawArrays(GL_POINTS, 0, simulation.getNumberOfBodies());
}
 
Example 5
Source File: JCudaDriverSimpleJOGL.java    From jcuda-samples with MIT License 4 votes vote down vote up
@Override
public void display(GLAutoDrawable drawable)
{
    GL3 gl = drawable.getGL().getGL3();

    if (useCUDA)
    {
        // Run the CUDA kernel to generate new vertex positions.
        runCuda(gl);
    }
    else
    {
        // Run the Java method to generate new vertex positions.
        runJava(gl);
    }

    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Activate the shader program
    gl.glUseProgram(shaderProgramID);
    
    // Set the current projection matrix
    int projectionMatrixLocation = 
        gl.glGetUniformLocation(shaderProgramID, "projectionMatrix");
    gl.glUniformMatrix4fv(
        projectionMatrixLocation, 1, false, 
        simpleInteraction.getProjectionMatrix(), 0);

    // Set the current modelview matrix
    int modelviewMatrixLocation = 
        gl.glGetUniformLocation(shaderProgramID, "modelviewMatrix");
    gl.glUniformMatrix4fv(
        modelviewMatrixLocation, 1, false, 
        simpleInteraction.getModelviewMatrix(), 0);
    
    // Render the VBO
    gl.glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
    gl.glDrawArrays(GL_POINTS, 0, meshWidth * meshHeight);
    
    // Update FPS information in main frame title
    step++;
    long currentTime = System.nanoTime();
    if (prevTimeNS == -1)
    {
        prevTimeNS = currentTime;
    }
    long diff = currentTime - prevTimeNS;
    if (diff > 1e9)
    {
        double fps = (diff / 1e9) * step;
        String t = "JCuda / JOGL interaction sample - ";
        t += useCUDA ? "JCuda" : "Java";
        t += " mode: " + String.format("%.2f", fps) + " FPS";
        frame.setTitle(t);
        prevTimeNS = currentTime;
        step = 0;
    }

    animationState += 0.01;
}
 
Example 6
Source File: Gl_320_transform_feedback_separated.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
protected boolean render(GL gl) {

    GL3 gl3 = (GL3) gl;

    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
    gl3.glViewport(0, 0, windowSize.x, windowSize.y);

    // Clear color buffer with black
    gl3.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl3.glClear(GL_COLOR_BUFFER_BIT);

    // First draw, capture the attributes
    {
        // Disable rasterisation, vertices processing only!
        gl3.glEnable(GL_RASTERIZER_DISCARD);

        gl3.glUseProgram(programName[Program.TRANSFORM]);
        gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0);

        gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.POSITION, bufferName.get(Buffer.POSITION));
        gl3.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, feedbackOutput.COLOR, bufferName.get(Buffer.COLOR));

        gl3.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM));

        gl3.glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, queryName.get(0));
        gl3.glBeginTransformFeedback(GL_TRIANGLES);
        {
            gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1);
        }
        gl3.glEndTransformFeedback();
        gl3.glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);

        gl3.glDisable(GL_RASTERIZER_DISCARD);
    }

    // Second draw, reuse the captured attributes
    {
        gl3.glUseProgram(programName[Program.FEEDBACK]);

        IntBuffer primitivesWritten = GLBuffers.newDirectIntBuffer(1);
        gl3.glGetQueryObjectuiv(queryName.get(0), GL_QUERY_RESULT, primitivesWritten);

        gl3.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK));
        gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, primitivesWritten.get(0) * 3, 1);

        BufferUtils.destroyDirectBuffer(primitivesWritten);
    }

    return true;
}