Java Code Examples for com.jogamp.opengl.GL3#glUniformMatrix4fv()
The following examples show how to use
com.jogamp.opengl.GL3#glUniformMatrix4fv() .
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: Gl_320_fbo_multisample.java From jogl-samples with MIT License | 6 votes |
private void renderFBO(GL3 gl3, int framebuffer) { 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.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.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{0.0f, 0.5f, 1.0f, 1.0f}, 0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); }
Example 3
Source File: Gl_320_fbo_multisample.java From jogl-samples with MIT License | 6 votes |
private void renderFB(GL3 gl3, int textureName) { Mat4 projection = glm.ortho_(-1.1f, 1.1f, 1.1f, -1.1f, 0.0f, 10.0f); Mat4 view = new Mat4(1.0f).translate(new Vec3(0.0f, 0.0f, -cameraDistance() * 0.1f)); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(view).mul(model); gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); checkError(gl3, "renderFB"); }
Example 4
Source File: Gl_320_fbo_multisample_integer.java From jogl-samples with MIT License | 6 votes |
private void renderFBO(GL3 gl3, int framebuffer) { Mat4 projection = glm.ortho_(-1.1f, 1.1f, 1.1f, -1.1f, 1.1f, -1.1f); Mat4 view = new Mat4(1.0f); Mat4 model = new Mat4(1.0f).rotate(-0.3f, new Vec3(0.f, 0.f, 1.f)); Mat4 mvp = projection.mul(view).mul(model); gl3.glUseProgram(programName[Program.RENDER]); gl3.glUniform1i(uniformDiffuse[Program.RENDER], 0); gl3.glUniformMatrix4fv(uniformMvp[Program.RENDER], 1, false, mvp.toFa_(), 0); gl3.glViewport(0, 0, windowSize.x / framebufferSize, windowSize.y / framebufferSize); gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); gl3.glClearBufferuiv(GL_COLOR, 0, new int[]{0, 128, 255, 255}, 0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); checkError(gl3, "renderFBO"); }
Example 5
Source File: LoopBatcher.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); // Uniform variables if (drawForHitTest) { gl.glUniform1i(shaderLocDrawHitTest, GL3.GL_TRUE); drawForHitTest = false; } else { gl.glUniform1i(shaderLocDrawHitTest, GL3.GL_FALSE); } 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); batch.draw(gl); } }
Example 6
Source File: Gl_330_texture_swizzle.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, (float) windowSize.x / windowSize.y, 0.1f, 1000.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).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, texture2dName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); for (int index = 0; index < Viewport.MAX; ++index) { gl3.glViewport(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, swizzleR[index]); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, swizzleG[index]); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, swizzleB[index]); gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, swizzleA[index]); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } return true; }
Example 7
Source File: Gl_320_fbo_multisample_explicit.java From jogl-samples with MIT License | 5 votes |
private void renderFBO(GL3 gl3, int framebuffer) { 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.0f)); 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, framebuffer); float[] depth = new float[]{1.0f}; gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 0.5f, 0.0f, 1.0f}, 0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 5); gl3.glDisable(GL_DEPTH_TEST); }
Example 8
Source File: Gl_330_sampler_wrap.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, (float) windowSize.x / windowSize.y, 0.1f, 1000.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).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, texture2dName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); for (int Index = 0; Index < Viewport.MAX; ++Index) { gl3.glViewport(viewport[Index].x, viewport[Index].y, viewport[Index].z, viewport[Index].w); gl3.glBindSampler(0, samplerName.get(Index)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } return true; }
Example 9
Source File: Gl_320_texture_lod.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, 1000.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); clearColor.put(new float[]{1.0f, 0.5f, 0.0f, 1.0f}).rewind(); gl3.glClearBufferfv(GL_COLOR, 0, clearColor); // Bind the program for use gl3.glUseProgram(programName); gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl3.glUniform1i(uniformDiffuse, 0); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glActiveTexture(GL_TEXTURE0); for (int index = 0; index < Texture.MAX; ++index) { gl3.glViewport(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w); gl3.glBindTexture(GL_TEXTURE_2D_ARRAY, textureName.get(index)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } return true; }
Example 10
Source File: Gl_320_primitive_point_quad.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, clearColor); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth); gl3.glDisable(GL_SCISSOR_TEST); Vec3 cameraPosition = cameraPosition().negate(); //glm::vec3 CameraPosition(glm::vec4(glm::normalize(glm::vec3(1.0)), 1.0) * this->view()); gl3.glUseProgram(programName); gl3.glUniform3fv(uniformCameraPosition, 1, cameraPosition.toFa_(), 0); gl3.glUniformMatrix4fv(uniformMv, 1, false, mv.toFa_(), 0); gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_POINTS, 0, vertexCount, 1); return true; }
Example 11
Source File: Gl_320_fbo_blit.java From jogl-samples with MIT License | 5 votes |
private void renderFBO(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.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.DIFFUSE)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); }
Example 12
Source File: NodeLabelBatcher.java From constellation with Apache License 2.0 | 5 votes |
@Override public void drawBatch(final GL3 gl, final Camera camera, final Matrix44f mvMatrix, final Matrix44f pMatrix) { if (topBatch.isDrawable() || bottomBatch.isDrawable()) { gl.glUseProgram(shader); // Let the glyph controller bind the glyph info and glyph image textures SharedDrawable.updateGlyphTextureController(gl); SharedDrawable.getGlyphTextureController().bind(gl, shaderGlyphInfoTexture, TextureUnits.GLYPH_INFO, shaderGlyphImageTexture, TextureUnits.GLYPHS); // Uniform variables gl.glUniformMatrix4fv(shaderMVMatrix, 1, false, mvMatrix.a, 0); gl.glUniformMatrix4fv(shaderPMatrix, 1, false, pMatrix.a, 0); gl.glUniformMatrix4fv(shaderLabelBottomInfo, 1, false, labelBottomInfo.a, 0); gl.glUniformMatrix4fv(shaderLabelTopInfo, 1, false, labelTopInfo.a, 0); gl.glUniform1f(shaderLocWidth, SharedDrawable.getGlyphManager().getWidthScalingFactor()); gl.glUniform1f(shaderLocHeight, SharedDrawable.getGlyphManager().getHeightScalingFactor()); gl.glUniform1f(shaderVisibilityLow, camera.getVisibilityLow()); gl.glUniform1f(shaderVisibilityHigh, camera.getVisibilityHigh()); gl.glUniform1f(shaderMorphMix, camera.getMix()); gl.glUniform1i(shaderXyzTexture, TextureUnits.VERTICES); gl.glUniform1i(shaderBackgroundGlyphIndex, SharedDrawable.getLabelBackgroundGlyphPosition()); gl.glUniform4fv(shaderBackgroundColor, 1, backgroundColor, 0); gl.glUniform4fv(shaderHighlightColor, 1, highlightColor, 0); if (topBatch.isDrawable()) { topBatch.draw(gl); } if (bottomBatch.isDrawable()) { bottomBatch.draw(gl); } } }
Example 13
Source File: Gl_320_texture_offset.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, 2.0f / 3.0f, 0.1f, 1000.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); 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.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glUseProgram(programName[Program.OFFSET]); gl3.glUniform2iv(uniformOffset, 1, new int[]{48, -80}, 0); for (int i = 0; i < Program.MAX; ++i) { gl3.glUseProgram(programName[i]); gl3.glUniformMatrix4fv(uniformMvp[i], 1, false, mvp.toFa_(), 0); gl3.glUniform1i(uniformDiffuse[i], 0); gl3.glViewport(viewport[i].x, viewport[i].y, viewport[i].z, viewport[i].w); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0, 1, 0); } return true; }
Example 14
Source File: PlanesRenderable.java From constellation with Apache License 2.0 | 5 votes |
@Override public void display(final GLAutoDrawable drawable, final Matrix44f mvpMatrix) { if (planeBatch.isDrawable()) { final GL3 gl = drawable.getGL().getGL3(); gl.glActiveTexture(GL3.GL_TEXTURE0 + TextureUnits.PLANES); gl.glBindTexture(GL3.GL_TEXTURE_2D_ARRAY, textureName); gl.glUseProgram(shader); gl.glUniformMatrix4fv(shaderMVPMatrix, 1, false, mvpMatrix.a, 0); gl.glUniform1i(shaderImages, TextureUnits.PLANES); planeBatch.draw(gl); } }
Example 15
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 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: Gl_330_blend_rtt.java From jogl-samples with MIT License | 4 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; // Pass 1 { gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(0)); gl3.glViewport(0, 0, windowSize.x >> 1, windowSize.y >> 1); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, 1).put(2, 1).put(3, 1)); gl3.glClearBufferfv(GL_COLOR, 1, clearColor); gl3.glClearBufferfv(GL_COLOR, 2, clearColor); gl3.glClearBufferfv(GL_COLOR, 3, clearColor); } // Pass 2 gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 0).put(1, 0).put(2, 0).put(3, 0)); gl3.glUseProgram(programNameSingle); { Mat4 projection = glm.ortho_(-2.0f, 2.0f, -1.5f, 1.5f, -1.0f, 1.0f); Mat4 view = new Mat4(1.0f); Mat4 model = new Mat4(0.2f); Mat4 mvp = projection.mul(view).mul(model); gl3.glUniformMatrix4fv(uniformMvpSingle, 1, false, mvp.toFa_(), 0); gl3.glUniform1i(uniformDiffuseSingle, 0); } for (int i = 0; i < Texture.MAX; ++i) { gl3.glViewport(viewport[i].x, viewport[i].y, viewport[i].z, viewport[i].w); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(i)); gl3.glBindSampler(0, samplerName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } return true; }
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_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 20
Source File: Gl_330_sampler_filter.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, 1000.0f); Mat4 model = new Mat4(1.0f); Mat4 mvp = projection.mul(viewMat4()).mul(model); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glScissor(0, 0, windowSize.x, windowSize.y); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1)); // Bind the program for use gl3.glUseProgram(programName); gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 0); gl3.glBindSampler(Viewport.V00, samplerName.get(Viewport.V00)); gl3.glBindSampler(Viewport.V10, samplerName.get(Viewport.V10)); gl3.glBindSampler(Viewport.V11, samplerName.get(Viewport.V11)); gl3.glBindSampler(Viewport.V01, samplerName.get(Viewport.V01)); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0)); gl3.glActiveTexture(GL_TEXTURE1); gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0)); gl3.glActiveTexture(GL_TEXTURE2); gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0)); gl3.glActiveTexture(GL_TEXTURE3); gl3.glBindTexture(GL_TEXTURE_2D, texture2dName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(0)); for (int index = 0; index < Viewport.MAX; ++index) { gl3.glUniform1i(uniformDiffuse, index); gl3.glScissor(viewport[index].x, viewport[index].y, viewport[index].z, viewport[index].w); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount, 1); } return true; }