Java Code Examples for com.jogamp.opengl.GL3#glBindVertexArray()
The following examples show how to use
com.jogamp.opengl.GL3#glBindVertexArray() .
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_fbo_depth_multisample.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(Program.MAX, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(Program.TEXTURE)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, Vec2.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl3.glBindVertexArray(0); gl3.glBindVertexArray(vertexArrayName.get(Program.SPLASH)); gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 2
Source File: Gl_320_glsl_builtin_blocks.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, Vec2.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 3
Source File: Gl_320_texture_fetch.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, Vec2.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 4
Source File: Gl_320_texture_integer.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, Vec2.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 5
Source File: Gl_330_texture_integer_rgb10a2ui.java From jogl-samples with MIT License | 6 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); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1).put(1, .5f).put(2, 0).put(3, 1)); gl3.glUseProgram(programName); gl3.glUniform1i(uniformDiffuse, 0); gl3.glUniformMatrix4fv(uniformMvp, 1, false, mvp.toFa_(), 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 6
Source File: Gl_320_texture_derivative.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, Vec2.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl3.glBindVertexArray(0); return true; }
Example 7
Source File: Gl_330_fbo_multisample_explicit_nv.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, Vec2.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 8
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 9
Source File: Gl_320_glsl_input_struct.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, Vec2.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 10
Source File: Gl_320_primitive_point.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 4, GL_FLOAT, false, glf.Vertex_v4fc4f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.COLOR, 4, GL_FLOAT, false, glf.Vertex_v4fc4f.SIZE, Vec4.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.COLOR); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 11
Source File: Gl_320_fbo_shadow.java From jogl-samples with MIT License | 6 votes |
private void renderFramebuffer(GL3 gl3) { gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LESS); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth); gl3.glClearBufferfv(GL_COLOR, 0, clearColor); gl3.glUseProgram(programName[Program.RENDER]); gl3.glUniform1i(uniformShadow, 0); gl3.glUniformBlockBinding(programName[Program.RENDER], uniformTransform[Program.RENDER], Semantic.Uniform.TRANSFORM0); gl3.glActiveTexture(GL_TEXTURE0); gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(0)); gl3.glBindVertexArray(vertexArrayName.get(Program.RENDER)); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); gl3.glDisable(GL_DEPTH_TEST); checkError(gl3, "renderFramebuffer"); }
Example 12
Source File: Gl_320_draw_multiple.java From jogl-samples with MIT License | 6 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 3, GL_FLOAT, false, 0, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT)); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 13
Source File: Gl_320_transform_feedback_interleaved.java From jogl-samples with MIT License | 5 votes |
private boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(Program.MAX, vertexArrayName); // Build a vertex array object gl3.glBindVertexArray(vertexArrayName.get(Program.TRANSFORM)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Program.TRANSFORM)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 4, GL_FLOAT, false, 0, 0); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); } gl3.glBindVertexArray(0); // Build a vertex array object gl3.glBindVertexArray(vertexArrayName.get(Program.FEEDBACK)); { gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Program.FEEDBACK)); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 4, GL_FLOAT, false, Vertex_v4fc4f.SIZE, 0); gl3.glVertexAttribPointer(Semantic.Attr.COLOR, 4, GL_FLOAT, false, Vertex_v4fc4f.SIZE, Vec4.SIZE); gl3.glBindBuffer(GL_ARRAY_BUFFER, 0); gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glEnableVertexAttribArray(Semantic.Attr.COLOR); } gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 14
Source File: Gl_320_draw_range_arrays.java From jogl-samples with MIT License | 5 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 / 6.0f, 0.1f, 100.0f); Mat4 model = new Mat4(1.0f); pointer.asFloatBuffer().put(projection.mul(viewMat4()).mul(model).toFa_()); gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); } float[] depth = new float[]{1.0f}; gl3.glClearBufferfv(GL_DEPTH, 0, depth, 0); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0); gl3.glUseProgram(programName); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Semantic.Uniform.TRANSFORM0, bufferName.get(Buffer.TRANSFORM)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glViewport(0, 0, windowSize.x / 2, windowSize.y); gl3.glDrawArraysInstanced(GL_TRIANGLES, 0, vertexCount / 2, 1); gl3.glViewport(windowSize.x / 2, 0, windowSize.x / 2, windowSize.y); gl3.glDrawArraysInstanced(GL_TRIANGLES, 6, vertexCount / 2, 1); return true; }
Example 15
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 16
Source File: Gl_320_buffer_uniform.java From jogl-samples with MIT License | 5 votes |
@Override protected boolean render(GL gl) { GL3 gl3 = (GL3) gl; { gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.PER_DRAW)); ByteBuffer transform = gl3.glMapBufferRange(GL_UNIFORM_BUFFER, 0, Transform.SIZE, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); Mat4 projection = new Mat4().perspective((float) Math.PI * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); Mat4 view = viewMat4(); Mat4 model = new Mat4(1.0f).rotate((float) -Math.PI * 0.5f, 0.0f, 0.0f, 1.0f); Transform t = new Transform(); t.mv = view.mul(model); t.p = projection; t.normal = new Mat3(t.mv.invTransp3_()); transform.asFloatBuffer().put(t.toFa_()); gl3.glUnmapBuffer(GL_UNIFORM_BUFFER); gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0); } gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glClearBufferfv(GL_COLOR, 0, new float[]{0.2f, 0.2f, 0.2f, 1.0f}, 0); gl3.glClearBufferfv(GL_DEPTH, 0, new float[]{1.0f}, 0); gl3.glUseProgram(programName); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Uniform.PER_SCENE, bufferName.get(Buffer.PER_SCENE)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Uniform.PER_PASS, bufferName.get(Buffer.PER_PASS)); gl3.glBindBufferBase(GL_UNIFORM_BUFFER, Uniform.PER_DRAW, bufferName.get(Buffer.PER_DRAW)); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); return true; }
Example 17
Source File: Gl_320_draw_without_vertex_attrib.java From jogl-samples with MIT License | 5 votes |
private Boolean initVertexArray(GL3 gl3) { gl3.glGenVertexArrays(1, vertexArrayName); gl3.glBindVertexArray(vertexArrayName.get(0)); gl3.glBindVertexArray(0); return checkError(gl3, "initVertexArray"); }
Example 18
Source File: TriangleBatch.java From constellation with Apache License 2.0 | 4 votes |
/** * We've finished providing data; compact the data, map the buffers, and set * up the vertex array. * <p> * You should really save the results of the indexing for future use if the * model data is static (doesn't change). * * @param gl the current OpenGL context. */ public void end(final GL3 gl) { // Create the master vertex array object. gl.glGenVertexArrays(1, vertexArrayBufferObject, 0); gl.glBindVertexArray(vertexArrayBufferObject[0]); // Create the buffer objects. gl.glGenBuffers(4, bufferObjects, 0); // Copy data to video memory. FloatBuffer buf; // Vertex data. buf = FloatBuffer.wrap(GLTools.toFloatArray(allVerts)); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, bufferObjects[VERTEX_DATA]); gl.glEnableVertexAttribArray(ShaderManager.ATTRIBUTE_VERTEX); gl.glBufferData(GL3.GL_ARRAY_BUFFER, GLBuffers.SIZEOF_FLOAT * 3 * nNumVerts, buf, GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(ShaderManager.ATTRIBUTE_VERTEX, 3, GL3.GL_FLOAT, false, 0, 0); // Normal data. buf = FloatBuffer.wrap(GLTools.toFloatArray(allNorms)); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, bufferObjects[NORMAL_DATA]); gl.glEnableVertexAttribArray(ShaderManager.ATTRIBUTE_NORMAL); gl.glBufferData(GL3.GL_ARRAY_BUFFER, GLBuffers.SIZEOF_FLOAT * 3 * nNumVerts, buf, GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(ShaderManager.ATTRIBUTE_NORMAL, 3, GL3.GL_FLOAT, false, 0, 0); // Texture coordinates. buf = FloatBuffer.wrap(GLTools.toFloatArray(allTexCoords)); gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, bufferObjects[TEXTURE_DATA]); gl.glEnableVertexAttribArray(ShaderManager.ATTRIBUTE_TEXTURE0); gl.glBufferData(GL3.GL_ARRAY_BUFFER, GLBuffers.SIZEOF_FLOAT * nNumVerts * 2, buf, GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(ShaderManager.ATTRIBUTE_TEXTURE0, 2, GL3.GL_FLOAT, false, 0, 0); // Indexes. ShortBuffer shortBuf = ShortBuffer.wrap(allIndexes); gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, bufferObjects[INDEX_DATA]); gl.glBufferData(GL3.GL_ELEMENT_ARRAY_BUFFER, GLBuffers.SIZEOF_SHORT * nNumIndexes, shortBuf, GL3.GL_STATIC_DRAW); // Done gl.glBindVertexArray(0); // Free older, larger arrays. // Reassign pointers so they are marked as unused. allIndexes = null; allVerts = null; allNorms = null; allTexCoords = null; }
Example 19
Source File: Gl_320_fbo_srgb.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.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)); // Explicitly convert linear pixel color to sRGB color space, as FramebufferName is an sRGB FBO // Shader execution is done with linear color to get correct linear algebra working. gl3.glEnable(GL_FRAMEBUFFER_SRGB); gl3.glClearBufferfv(GL_DEPTH, 0, clearDepth); 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, 2, 0); } // Blit the sRGB framebuffer to the default framebuffer back buffer. { gl3.glDisable(GL_DEPTH_TEST); gl3.glViewport(0, 0, windowSize.x, windowSize.y); gl3.glBindFramebuffer(GL_FRAMEBUFFER, 0); // Uncomment to avoid the extra linear to sRGB conversion and hence get correct display 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 20
Source File: Gl_320_fbo_shadow.java From jogl-samples with MIT License | 3 votes |
private void renderShadow(GL3 gl3) { gl3.glEnable(GL_DEPTH_TEST); gl3.glDepthFunc(GL_LESS); gl3.glViewport(0, 0, shadowSize.x, shadowSize.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.DEPTH]); gl3.glUniformBlockBinding(programName[Program.DEPTH], uniformTransform[Program.DEPTH], Semantic.Uniform.TRANSFORM0); gl3.glBindVertexArray(vertexArrayName.get(Program.RENDER)); checkError(gl3, "renderShadow 0"); gl3.glDrawElementsInstancedBaseVertex(GL_TRIANGLES, elementCount, GL_UNSIGNED_SHORT, 0, 1, 0); checkError(gl3, "renderShadow 1"); gl3.glDisable(GL_DEPTH_TEST); checkError(gl3, "renderShadow"); }