Java Code Examples for com.jogamp.opengl.GL3#glEnable()
The following examples show how to use
com.jogamp.opengl.GL3#glEnable() .
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: BlazeBatcher.java From constellation with Apache License 2.0 | 6 votes |
@Override public void drawBatch(final GL3 gl, final Camera camera, final Matrix44f mvMatrix, final Matrix44f pMatrix) { if (batch.isDrawable()) { gl.glUseProgram(shader); gl.glUniformMatrix4fv(shaderMVMatrix, 1, false, mvMatrix.a, 0); gl.glUniformMatrix4fv(shaderPMatrix, 1, false, pMatrix.a, 0); gl.glUniform1f(shaderVisibilityLow, camera.getVisibilityLow()); gl.glUniform1f(shaderVisibilityHigh, camera.getVisibilityHigh()); gl.glUniform1f(shaderMorphMix, camera.getMix()); gl.glUniform1i(shaderXyzTexture, TextureUnits.VERTICES); gl.glUniform1i(shaderImagesTexture, TextureUnits.ICONS); gl.glUniform1f(shaderScale, blazeSize); gl.glUniform1f(shaderOpacity, blazeOpacity); gl.glDisable(GL3.GL_DEPTH_TEST); batch.draw(gl); gl.glEnable(GL3.GL_DEPTH_TEST); } }
Example 2
Source File: JCudaDriverSimpleJOGL.java From jcuda-samples with MIT License | 6 votes |
@Override public void init(GLAutoDrawable drawable) { // Perform the default GL initialization GL3 gl = drawable.getGL().getGL3(); gl.setSwapInterval(0); gl.glEnable(GL_DEPTH_TEST); gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); setupView(drawable); // Initialize the shaders initShaders(gl); // Initialize JCuda initJCuda(); // Create the VBO containing the vertex data initVBO(gl); }
Example 3
Source File: Gl_320_fbo_multisample_integer.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; // Clear the framebuffer gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); // Pass 1 // Render the scene in a multisampled framebuffer gl3.glEnable(GL_MULTISAMPLE); renderFBO(gl3, framebufferName.get(Framebuffer.RENDER)); gl3.glDisable(GL_MULTISAMPLE); // Resolved multisampling gl3.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER)); gl3.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE)); gl3.glBlitFramebuffer( 0, 0, windowSize.x / framebufferSize, windowSize.y / framebufferSize, 0, 0, windowSize.x / framebufferSize, windowSize.y / framebufferSize, GL_COLOR_BUFFER_BIT, GL_NEAREST); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); // Pass 2 // Render the colorbuffer from the multisampled framebuffer renderFB(gl3, textureName.get(Texture.COLORBUFFER)); return checkError(gl3, "render"); }
Example 4
Source File: Gl_330_fbo_multisample_explicit_nv.java From jogl-samples with MIT License | 5 votes |
private void renderFBO(GL3 gl3) { 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).scale(new Vec3(1, -1, 1)); Mat4 mvp = perspective.mul(viewMat4()).mul(model); gl3.glEnable(GL_DEPTH_TEST); gl3.glUseProgram(programName[Program.THROUGH]); gl3.glUniform1i(uniformDiffuse[Program.THROUGH], 0); gl3.glUniformMatrix4fv(uniformMvp[Program.THROUGH], 1, false, mvp.toFa_(), 0); gl3.glViewport(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1)); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1)); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindSampler(0, samplerName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5); gl3.glDisable(GL_DEPTH_TEST); checkError(gl3, "renderFBO"); }
Example 5
Source File: Gl_330_fbo_multisample_explicit_nv.java From jogl-samples with MIT License | 5 votes |
private void resolveMultisampling(GL3 gl3) { Mat4 perspective = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = perspective.mul(viewMat4()).mul(model); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1)); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_RENDERBUFFER_NV, textureName.get(Texture.COLOR)); gl3.glBindSampler(0, samplerName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glEnable(GL_SCISSOR_TEST); // Box { gl3.glScissor(1, 1, windowSize.x / 2 - 2, windowSize.y - 2); gl3.glUseProgram(programName[Program.RESOLVE_BOX]); gl3.glUniform1i(uniformDiffuse[Program.RESOLVE_BOX], 0); gl3.glUniformMatrix4fv(uniformMvp[Program.RESOLVE_BOX], 1, false, mvp.toFa_(), 0); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5); } // Near { gl3.glScissor(windowSize.x / 2 + 1, 1, windowSize.x / 2 - 2, windowSize.y - 2); gl3.glUseProgram(programName[Program.RESOLVE_NEAR]); gl3.glUniform1i(uniformDiffuse[Program.RESOLVE_NEAR], 0); gl3.glUniformMatrix4fv(uniformMvp[Program.RESOLVE_NEAR], 1, false, mvp.toFa_(), 0); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5); } gl3.glDisable(GL_SCISSOR_TEST); }
Example 6
Source File: Gl_300_fbo_multisample.java From jogl-samples with MIT License | 5 votes |
@Override public boolean render(GL gl) { GL3 gl3 = (GL3) gl; // Clear the framebuffer gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); gl3.glUseProgram(programName); gl3.glUniform1i(uniformDiffuse, 0); // Pass 1 // Render the scene in a multisampled framebuffer gl3.glEnable(GL_MULTISAMPLE); renderFBO(gl3, framebufferName.get(Framebuffer.RENDER)); gl3.glDisable(GL_MULTISAMPLE); // Resolved multisampling gl3.glBindFramebuffer(GL_READ_FRAMEBUFFER, framebufferName.get(Framebuffer.RENDER)); gl3.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE)); gl3.glDrawBuffer(GL_COLOR_ATTACHMENT0); gl3.glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_COLOR_BUFFER_BIT, GL_LINEAR); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); // Pass 2 // Render the colorbuffer from the multisampled framebuffer gl3.glViewport(0, 0, windowSize.x, windowSize.y); renderFB(gl3, textureName.get(Texture.RESOLVE)); return true; }
Example 7
Source File: Gl_330_sampler_anisotropy_ext.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean begin(GL gl) { GL3 gl3 = (GL3) gl; viewport[Viewport.V00] = new Vec4i(1, 1, windowSize.x / 2 - 1, windowSize.y / 2 - 1); viewport[Viewport.V10] = new Vec4i(windowSize.x / 2 + 1, 1, windowSize.x / 2 - 1, windowSize.y / 2 - 1); viewport[Viewport.V11] = new Vec4i(windowSize.x / 2 + 1, windowSize.y / 2 + 1, windowSize.x / 2 - 1, windowSize.y / 2 - 1); viewport[Viewport.V01] = new Vec4i(1, windowSize.y / 2 + 1, windowSize.x / 2 - 1, windowSize.y / 2 - 1); boolean validated = true; validated = validated && gl3.isExtensionAvailable("GL_EXT_texture_filter_anisotropic"); if (validated) { validated = initProgram(gl3); } if (validated) { validated = initBuffer(gl3); } if (validated) { validated = initTexture(gl3); } if (validated) { validated = initSampler(gl3); } if (validated) { validated = initVertexArray(gl3); } gl3.glEnable(GL_SCISSOR_TEST); return validated && checkError(gl3, "begin"); }
Example 8
Source File: Gl_320_texture_derivative.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean begin(GL gl) { GL3 gl3 = (GL3) gl; boolean validated = true; if (validated) { validated = initBuffer(gl3); } if (validated) { validated = initTexture(gl3); } if (validated) { validated = initProgram(gl3); } if (validated) { validated = initVertexArray(gl3); } /** * No sense here? Moreovec 4.0f is illegal, [0, 1] allowed. */ gl3.glEnable(GL_SAMPLE_SHADING); gl3.glMinSampleShading(4.0f); return validated; }
Example 9
Source File: Gl_320_primitive_sprite.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean begin(GL gl) { GL3 gl3 = (GL3) gl; boolean validated = true; if (validated) { validated = initTexture(gl3); } if (validated) { validated = initProgram(gl3); } if (validated) { validated = initBuffer(gl3); } if (validated) { validated = initVertexArray(gl3); } gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LESS); gl3.glEnable(GL_PROGRAM_POINT_SIZE); //glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); gl3.glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_UPPER_LEFT); return validated; }
Example 10
Source File: Gl_320_primitive_sprite.java From jogl-samples with MIT License | 5 votes |
@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 view = viewMat4(); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul_(view).mul(model); Mat4 mv = view.mul(model); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glClearBufferfv(GL_COLOR, 0, clearColor0); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth); gl3.glEnable(GL_SCISSOR_TEST); gl3.glScissor(windowSize.x / 4, windowSize.y / 4, windowSize.x / 2, windowSize.y / 2); gl3.glViewport((int) (windowSize.x * 0.25f), (int) (windowSize.y * 0.25f), (int) (windowSize.x * 0.5f), (int) (windowSize.y * 0.5f)); gl3.glClearBufferfv(GL_COLOR, 0, clearColor1); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth); gl3.glDisable(GL_SCISSOR_TEST); gl3.glUseProgram(programName); gl3.glUniformMatrix4fv(uniformMv, 1, false, mv.toFa_(), 0); gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl3.glUniform1i(uniformDiffuse, 0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_POINTS, 0, vertexCount, 1); return true; }
Example 11
Source File: Gl_320_test_scissor.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; Vec3 minScissor = new Vec3(10000.f, 10000.f, 10000.f); Vec3 maxScissor = new Vec3(-10000.f, -10000.f, -10000.f); { gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl3.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); Mat4 view = viewMat4(); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul_(view).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); for (int i = 0; i < vertexCount; ++i) { Vec3 projected = glm.project_( new Vec3(vertexData[i * 4 + 0], vertexData[i * 4 + 1], 0.0f), view.mul_(model), projection, new Vec4(0, 0, windowSize.x, windowSize.y)); minScissor.min(projected); maxScissor.max(projected); } } gl3.glViewport(0, 0, windowSize.x, windowSize.y); clearColor.put(new float[]{1.0f, 0.5f, 0.0f, 1.0f}).rewind(); gl3.glClearBufferfv(GL_COLOR, 0, clearColor); gl3.glScissor((int) minScissor.x, (int) minScissor.y, (int) (maxScissor.x - minScissor.x), (int) (maxScissor.y - minScissor.y)); gl3.glEnable(GL_SCISSOR_TEST); clearColor.put(new float[]{0.0f, 0.0f, 0.0f, 1.0f}).rewind(); gl3.glClearBufferfv(GL_COLOR, 0, clearColor); // Bind the program for use gl3.glUseProgram(programName); gl3.glUniform1i(uniformDiffuse, 0); gl3.glUniformBlockBinding(programName, uniformTransform, Semantic.Uniform.TRANSFORM0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); gl3.glDisable(GL_SCISSOR_TEST); return true; }
Example 12
Source File: Gl_320_fbo_blend_points.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean begin(GL gl) { GL3 gl3 = (GL3) gl; boolean validated = true; gl3.glEnable(GL_PROGRAM_POINT_SIZE); /** * Strange, I remember I had to enable it to get it working, but if I do it now I get * * type Error * severity High: dangerous undefined behavior * source GL API * msg GL_INVALID_ENUM error generated. Cannot enable <cap> in the current profile. */ // gl3.glEnable(GL_POINT_SPRITE); gl3.glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); float[] pointSizeProperties = new float[3]; gl3.glGetFloatv(GL2GL3.GL_POINT_SIZE_RANGE, pointSizeProperties, 0); gl3.glGetFloatv(GL2GL3.GL_POINT_SIZE_GRANULARITY, pointSizeProperties, 2); System.out.println("pointSizeRange: (" + pointSizeProperties[0] + ", " + pointSizeProperties[1] + ") " + "granularity: " + pointSizeProperties[2]); if (validated) { validated = initProgram(gl3); } if (validated) { validated = initBuffer(gl3); } if (validated) { validated = initVertexArray(gl3); } if (validated) { validated = initTexture(gl3); } if (validated) { validated = initFramebuffer(gl3); } return validated; }
Example 13
Source File: Gl_320_fbo_srgb_decode_ext.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; { gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).toFa_()); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } { gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LESS); gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth); gl3.glClearBufferfv(GL_COLOR, 0, clearColorSRGB); // TextureName[texture::DIFFUSE] is a sRGB texture which sRGB conversion on fetch has been disabled // Hence in the shader, the value is stored as sRGB so we should not convert it to sRGB. gl3.glUseProgram(programName[Program.TEXTURE]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0); } { gl3.glDisable(GL_DEPTH_TEST); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glUseProgram(programName[Program.SPLASH]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH)); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); } return true; }
Example 14
Source File: Gl_320_fbo_depth_multisample.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; { gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl3.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); //glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 8.0f); Mat4 model = new Mat4(1.0f).scale(new Vec3(5.0f)); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LESS); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.DEPTH_MULTISAMPLE)); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth); // Bind rendering objects gl3.glUseProgram(programName[Program.TEXTURE]); gl3.glUniformBlockBinding(programName[Program.TEXTURE], uniformTransform, Semantic.Uniform.TRANSFORM0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 2, 0); // Pass 2 gl3.glDisable(GL_DEPTH_TEST); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glUseProgram(programName[Program.SPLASH]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH)); gl3.glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureName.get(Texture.MULTISAMPLE)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); return true; }
Example 15
Source File: Gl_320_fbo_multisample_explicit.java From jogl-samples with MIT License | 4 votes |
private void resolveMultisampling(GL3 gl3) { Mat4 perspective = glm.ortho_(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 100.0f); Mat4 viewFlip = new Mat4(1.0f).scale(new Vec3(1.0f, -1.0f, 1.0f)); Mat4 view = viewFlip.translate(new Vec3(0.0f, 0.0f, -cameraDistance() * 1.0f)); Mat4 model = new Mat4(1.0f); Mat4 mvp = perspective.mul(view).mul(model); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureName.get(Texture.MULTISAMPLE_COLORBUFFER)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glEnable(GL_SCISSOR_TEST); // Box { gl3.glScissor(1, 1, windowSize.x / 2 - 2, windowSize.y - 2); gl3.glUseProgram(programName[Program.RESOLVE_BOX]); gl3.glUniform1i(uniformDiffuse[Program.RESOLVE_BOX], 0); gl3.glUniformMatrix4fv(uniformMvp[Program.RESOLVE_BOX], 1, false, mvp.toFa_(), 0); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5); } // Near { gl3.glScissor(windowSize.x / 2 + 1, 1, windowSize.x / 2 - 2, windowSize.y - 2); gl3.glUseProgram(programName[Program.RESOLVE_NEAR]); gl3.glUniform1i(uniformDiffuse[Program.RESOLVE_NEAR], 0); gl3.glUniformMatrix4fv(uniformMvp[Program.RESOLVE_NEAR], 1, false, mvp.toFa_(), 0); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5); } gl3.glDisable(GL_SCISSOR_TEST); }
Example 16
Source File: Gl_320_transform_feedback_separated.java From jogl-samples with MIT License | 4 votes |
@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; }
Example 17
Source File: NBodyVisualizer.java From gpu-nbody with MIT License | 4 votes |
/** * 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 18
Source File: NewLineRenderable.java From constellation with Apache License 2.0 | 4 votes |
/** * Draws the new line on the display. * <p> * @param drawable The OpenGL rendering target. * @param pMatrix The model view projection matrix. */ @Override public void display(final GLAutoDrawable drawable, final Matrix44f pMatrix) { final Matrix44f mvpMatrix = parent.getDisplayModelViewProjectionMatrix(); // If no endpoints are set, don't draw anything if (model != null && !model.isClear()) { final Vector3f startPosition = model.getStartLocation(); final Vector3f endPosition = model.getEndLocation(); final GL3 gl = drawable.getGL().getGL3(); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, batch.getBufferName(vertexTarget)); ByteBuffer bbuf = gl.glMapBuffer(GL3.GL_ARRAY_BUFFER, GL3.GL_WRITE_ONLY); FloatBuffer fbuf = bbuf.asFloatBuffer(); // Update the line endpoints in the vertex buffer. float[] vertices = new float[]{ startPosition.getX(), startPosition.getY(), startPosition.getZ(), endPosition.getX(), endPosition.getY(), endPosition.getZ()}; fbuf.put(vertices); gl.glUnmapBuffer(GL3.GL_ARRAY_BUFFER); // Disable depth so the line is drawn over everything else. gl.glDisable(GL3.GL_DEPTH_TEST); gl.glDepthMask(false); // Draw the line. gl.glLineWidth(NEW_LINE_WIDTH); gl.glUseProgram(shader); gl.glUniformMatrix4fv(shaderMVP, 1, false, mvpMatrix.a, 0); batch.draw(gl); gl.glLineWidth(1); // Reenable depth. gl.glEnable(GL3.GL_DEPTH_TEST); gl.glDepthMask(true); // Rebind default array buffer gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0); } }
Example 19
Source File: Gl_320_fbo_depth.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; { gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl3.glMapBufferRange( GL_UNIFORM_BUFFER, 0, Mat4.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.5f, 8.0f); Mat4 model = new Mat4(1.0f).scale(new Vec3(5.0f)); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LESS); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); float[] depth = {1.0f}; gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0); // Bind rendering objects gl3.glUseProgram(programName[Program.TEXTURE]); gl3.glUniformBlockBinding(programName[Program.TEXTURE], uniformTransform, Semantic.Uniform.TRANSFORM0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); gl3.glDisable(GL_DEPTH_TEST); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glUseProgram(programName[Program.SPLASH]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH)); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RENDERBUFFER)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); return true; }
Example 20
Source File: Gl_320_fbo_depth_stencil.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; IntBuffer uniformBufferOffsetAlignment = GLBuffers.newDirectIntBuffer(1); { gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffsetAlignment); uniformBufferOffsetAlignment.put(0, glm.ceilMultiple(Mat4.SIZE, uniformBufferOffsetAlignment.get(0))); gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM)); ByteBuffer pointer = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, uniformBufferOffsetAlignment.get(0) * 2, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = glm.perspective_((float) Math.PI * 0.25f, (float) windowSize.x / windowSize.y, 0.1f, 100.0f); pointer.asFloatBuffer().put(projection.mul_(viewMat4()).scale(new Vec3(1.00f)).toFa_()); pointer.position(uniformBufferOffsetAlignment.get(0) * 1); pointer.asFloatBuffer().put(projection.mul(viewMat4()).scale(new Vec3(1.05f)).toFa_()); pointer.rewind(); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } { gl3.glEnable(GL_STENCIL_TEST); gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LEQUAL); gl3.glStencilMask(0xFF); gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glClearBufferfi(GL_DEPTH_STENCIL, 0, 1.0f, 0); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); gl3.glUseProgram(programName[Program.TEXTURE]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE)); gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM), uniformBufferOffsetAlignment.get(0) * 0, uniformBufferOffsetAlignment.get(0)); gl3.glDisable(GL_DEPTH_TEST); gl3.glStencilMask(0xFF); gl3.glStencilFunc(GL_ALWAYS, 1, 0xFF); gl3.glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); gl3.glBindTexture(GL_TEXTURE_2D, 0); // gl3.glBindBufferRange(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM), uniformBufferOffsetAlignment.get(0) * 1, uniformBufferOffsetAlignment.get(0)); gl3.glStencilMask(0x00); gl3.glStencilFunc(GL_NOTEQUAL, 1, 0xFF); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); } { gl3.glDisable(GL_DEPTH_TEST); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glUseProgram(programName[Program.SPLASH]); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH)); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.COLORBUFFER)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1); } BufferUtils.destroyDirectBuffer(uniformBufferOffsetAlignment); return true; }