Java Code Examples for com.jogamp.opengl.GL2GL3#glDrawElements()
The following examples show how to use
com.jogamp.opengl.GL2GL3#glDrawElements() .
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: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void renderSubMesh(SubMesh subMesh, int materialIndex, Mat4d subInstTrans, Mat4d subInstInvTrans, int contextID, Renderer renderer) { Material mat = _materials.get(materialIndex); int shaderID = mat.shaderID; GL2GL3 gl = renderer.getGL(); if (!subMesh.vaoMaps[shaderID].containsKey(contextID)) { setupVAOForSubMesh(contextID, subMesh, renderer); } int vao = subMesh.vaoMaps[shaderID].get(contextID); gl.glBindVertexArray(vao); ShaderInfo si = sInfos[shaderID]; gl.glUseProgram(si.meshProgHandle); // Setup uniforms for this object Mat4d subInstNorm = new Mat4d(subInstInvTrans); subInstNorm.transpose4(); gl.glUniformMatrix4fv(si.bindSpaceMatVar, 1, false, RenderUtils.MarshalMat4d(subInstTrans), 0); gl.glUniformMatrix4fv(si.bindSpaceNorMatVar, 1, false, RenderUtils.MarshalMat4d(subInstNorm), 0); if (mat._textureIndex != -1) { int texHandle = _textureHandles.get(mat._textureIndex); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, texHandle); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_REPEAT); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_REPEAT); gl.glUniform1i(si.texVar, 0); } else { gl.glUniform4fv(si.diffuseColorVar, 1, mat._diffuseColor.toFloats(), 0); } gl.glUniform3fv(si.ambientColorVar, 1, mat._ambientColor.toFloats(), 0); gl.glUniform3fv(si.specColorVar, 1, mat._specColor.toFloats(), 0); gl.glUniform1f(si.shininessVar, (float)mat._shininess); if (mat._transType != MeshData.NO_TRANS) { gl.glBlendEquationSeparate(GL2GL3.GL_FUNC_ADD, GL2GL3.GL_MAX); if (mat._transType != MeshData.DIFF_ALPHA_TRANS) { gl.glBlendColor((float)mat._transColour.r, (float)mat._transColour.g, (float)mat._transColour.b, (float)mat._transColour.a); } if (mat._transType == MeshData.A_ONE_TRANS) { gl.glBlendFuncSeparate(GL2GL3.GL_CONSTANT_ALPHA, GL2GL3.GL_ONE_MINUS_CONSTANT_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ZERO); } else if (mat._transType == MeshData.RGB_ZERO_TRANS) { gl.glBlendFuncSeparate(GL2GL3.GL_ONE_MINUS_CONSTANT_COLOR, GL2GL3.GL_CONSTANT_COLOR, GL2GL3.GL_ONE, GL2GL3.GL_ZERO); } else if (mat._transType == MeshData.DIFF_ALPHA_TRANS) { gl.glBlendFuncSeparate(GL2GL3.GL_SRC_ALPHA, GL2GL3.GL_ONE_MINUS_SRC_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ZERO); } else { assert(false); // Unknown transparency type } } // Actually draw it //gl.glPolygonMode(GL2GL3.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); gl.glDisable(GL2GL3.GL_CULL_FACE); if (flattenBuffers) { gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, subMesh._numVerts); } else { gl.glDrawElements(GL2GL3.GL_TRIANGLES, subMesh._numVerts, GL2GL3.GL_UNSIGNED_INT, 0); } gl.glEnable(GL2GL3.GL_CULL_FACE); // Reset the blend state if (mat._transType != MeshData.NO_TRANS) { gl.glBlendEquationSeparate(GL2GL3.GL_FUNC_ADD, GL2GL3.GL_MAX); gl.glBlendFuncSeparate(GL2GL3.GL_SRC_ALPHA, GL2GL3.GL_ONE_MINUS_SRC_ALPHA, GL2GL3.GL_ONE, GL2GL3.GL_ONE); } gl.glBindVertexArray(0); }
Example 2
Source File: HullProto.java From jaamsim with Apache License 2.0 | 2 votes |
public void render(int contextID, Renderer renderer, Mat4d modelViewMat, Camera cam) { GL2GL3 gl = renderer.getGL(); Shader s = renderer.getShader(Renderer.ShaderHandle.HULL); int progHandle = s.getProgramHandle(); gl.glUseProgram(progHandle); int modelViewMatVar = gl.glGetUniformLocation(progHandle, "modelViewMat"); int projMatVar = gl.glGetUniformLocation(progHandle, "projMat"); int cVar = gl.glGetUniformLocation(progHandle, "C"); int fcVar = gl.glGetUniformLocation(progHandle, "FC"); int[] is = new int[2]; gl.glGenBuffers(2, is, 0); int vertexBuffer = is[0]; int indexBuffer = is[1]; List<Vec3d> verts = _hull.getVertices(); // Generate the vertex buffer FloatBuffer fb = FloatBuffer.allocate(verts.size() * 3); // for (Vec3d v : verts) { RenderUtils.putPointXYZ(fb, v); } fb.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, vertexBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, verts.size() * 3 * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); // Generate the index buffer List<ConvexHull.HullFace> faces = _hull.getFaces(); int numIndices = faces.size() * 3; IntBuffer ib = IntBuffer.allocate(faces.size() * 3); // for (ConvexHull.HullFace f : faces) { ib.put(f.indices, 0 ,3); } ib.flip(); gl.glBindBuffer(GL2GL3.GL_ELEMENT_ARRAY_BUFFER, indexBuffer); gl.glBufferData(GL2GL3.GL_ELEMENT_ARRAY_BUFFER, faces.size() * 3 * 4, ib, GL2GL3.GL_STATIC_DRAW); gl.glBindBuffer(GL2GL3.GL_ELEMENT_ARRAY_BUFFER, 0); if (!_vaoMap.containsKey(contextID)) { setupVAO(contextID, renderer, progHandle, vertexBuffer, indexBuffer); } int vao = _vaoMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(progHandle); // Setup uniforms for this object Mat4d projMat = cam.getProjMat4d(); gl.glUniformMatrix4fv(modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(projMatVar, 1, false, RenderUtils.MarshalMat4d(projMat), 0); gl.glUniform1f(cVar, Camera.C); gl.glUniform1f(fcVar, Camera.FC); // Actually draw it gl.glEnable(GL2GL3.GL_BLEND); gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glCullFace(GL2GL3.GL_BACK); gl.glBlendFunc(GL2GL3.GL_ONE, GL2GL3.GL_ONE_MINUS_SRC_ALPHA); gl.glBlendEquation(GL2GL3.GL_FUNC_ADD); gl.glDisable(GL2GL3.GL_DEPTH_TEST); //gl.glPolygonMode(GL2GL3.GL_FRONT_AND_BACK, GL2GL3.GL_LINE); gl.glDrawElements(GL2GL3.GL_TRIANGLES, numIndices, GL2GL3.GL_UNSIGNED_INT, 0); //gl.glPolygonMode(GL2GL3.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); gl.glEnable(GL2GL3.GL_DEPTH_TEST); gl.glDisable(GL2GL3.GL_CULL_FACE); gl.glCullFace(GL2GL3.GL_BACK); gl.glDisable(GL2GL3.GL_BLEND); gl.glBindVertexArray(0); gl.glDeleteBuffers(2, is, 0); }