Java Code Examples for com.jogamp.opengl.GL3#glBlendFunc()
The following examples show how to use
com.jogamp.opengl.GL3#glBlendFunc() .
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: GLRenderer.java From constellation with Apache License 2.0 | 5 votes |
@Override public void init(final GLAutoDrawable drawable) { initialised = true; renderables.sort(Comparator.naturalOrder()); if (debugGl) { drawable.setGL(new DebugGL3(drawable.getGL().getGL3())); } final GL3 gl = drawable.getGL().getGL3(); //Look for Graphics cards that work with GL3, but not 3.3. //Graphics cards that don't work with GL3 will raise an exception. final String thisversion = gl.glGetString(GL.GL_VERSION); if (!VersionUtilities.doesVersionMeetMinimum(thisversion, GLInfo.MINIMUM_OPEN_GL_VERSION)) { GLInfo.respondToIncompatibleHardwareOrGL(drawable); } if (printGlCapabilities) { GLInfo.printGLCapabilities(gl); } gl.glEnable(GL3.GL_DEPTH_TEST); gl.glDepthFunc(GL3.GL_LEQUAL); gl.glEnable(GL3.GL_BLEND); gl.glBlendFunc(GL3.GL_SRC_ALPHA, GL3.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL3.GL_LINE_SMOOTH); gl.glHint(GL3.GL_LINE_SMOOTH_HINT, GL3.GL_NICEST); renderables.forEach(renderable -> { renderable.init(drawable); }); // Reset to the default framebuffer. gl.glBindFramebuffer(GL3.GL_DRAW_FRAMEBUFFER, 0); }
Example 2
Source File: Gl_330_blend_index.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; // Setup blending gl3.glEnable(GL_BLEND); gl3.glBlendEquation(GL_FUNC_ADD); gl3.glBlendFunc(GL_ONE, GL_SRC1_COLOR); 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.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1)); gl3.glUseProgram(programName); 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_TRIANGLES, 0, vertexCount, 1); return true; }
Example 3
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 4
Source File: Gl_320_fbo_blend_points.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); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } { gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0); gl3.glEnable(GL_FRAMEBUFFER_SRGB); gl3.glEnable(GL_BLEND); gl3.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl3.glUseProgram(programName[Program.RENDER]); gl3.glBindVertexArray(vertexArrayName.get(Program.RENDER)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl3.glDrawArraysInstanced(GL_POINTS, 0, 8, 1); gl3.glDisable(GL_BLEND); } { gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glDisable(GL_FRAMEBUFFER_SRGB); 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 5
Source File: Gl_320_fbo_srgb_blend.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); } // Render a textured quad to a sRGB framebuffer object. { gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale); gl3.glEnable(GL_BLEND); gl3.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glEnable(GL_FRAMEBUFFER_SRGB); gl3.glClearBufferfv(GL_COLOR, 0, clearColor); 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, 100, 0); gl3.glDisable(GL_BLEND); } // Blit the sRGB framebuffer to the default framebuffer back buffer. { gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glDisable(GL_FRAMEBUFFER_SRGB); 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 6
Source File: Gl_320_fbo_blend.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); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); // Make sure the uniform buffer is uploaded gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } { gl3.glViewport(0, 0, windowSize.x * framebufferScale, windowSize.y * framebufferScale); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0); gl3.glEnable(GL_BLEND); gl3.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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, 100, 0); gl3.glDisable(GL_BLEND); } { 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; }