Java Code Examples for com.jogamp.opengl.GL2GL3#glDisable()
The following examples show how to use
com.jogamp.opengl.GL2GL3#glDisable() .
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: Polygon.java From jaamsim with Apache License 2.0 | 6 votes |
private void renderFill(GL2GL3 gl) { if (_tessPoints == null) { _tessPoints = SimpleTess.tesselate(_points); fb = FloatBuffer.allocate(3 * _tessPoints.size()); for (Vec3d vert : _tessPoints) { RenderUtils.putPointXYZ(fb, vert); } fb.flip(); } gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _vertBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, fb.limit() * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); gl.glDisable(GL2GL3.GL_CULL_FACE); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, _tessPoints.size()); gl.glEnable(GL2GL3.GL_CULL_FACE); }
Example 2
Source File: Renderer.java From jaamsim with Apache License 2.0 | 4 votes |
@Override public void display(GLAutoDrawable drawable) { synchronized (rendererLock) { Camera cam = cameras.get(window.getWindowID()); // The ray of the current mouse position (or null if the mouse is not hovering over the window) Ray pickRay = RenderUtils.getPickRay(getMouseInfo(window.getWindowID())); PerfInfo pi = new PerfInfo(); long startNanos = System.nanoTime(); allowDelayedTextures = true; // Cache the current scene. This way we don't need to lock it for the full render ArrayList<Renderable> scene = new ArrayList<>(currentScene.size()); ArrayList<OverlayRenderable> overlay = new ArrayList<>(currentOverlay.size()); synchronized(sceneLock) { scene.addAll(currentScene); overlay.addAll(currentOverlay); } renderScene(drawable.getContext(), window.getWindowID(), scene, overlay, cam, window.getViewableWidth(), window.getViewableHeight(), pickRay, window.getViewID(), pi); GL2GL3 gl = drawable.getContext().getGL().getGL2GL3(); // Just to clean up the code below boolean showDebug; synchronized(settingsLock) { showDebug = showDebugInfo; } if (showDebug) { // Draw a window specific performance counter gl.glDisable(GL2GL3.GL_DEPTH_TEST); drawContext = drawable.getContext(); StringBuilder perf = new StringBuilder(); perf.append( String.format( "Objects Culled: %s", pi.objectsCulled) ); perf.append( String.format( " VRAM (MB): %.0f", usedVRAM/(1024.0*1024.0)) ); perf.append( String.format( " Frame time (ms): %.3f", lastFrameNanos/1000000.0) ); perf.append( String.format( " SceneTime (ms): %.3f", sceneTimeNS/1000000.0) ); perf.append( String.format( " Loop Time (ms): %.3f", loopTimeNS/1000000.0) ); TessFont defFont = getTessFont(defaultBoldFontKey); OverlayString os = new OverlayString(defFont, perf.toString(), ColourInput.BLACK, 10, 10, 15, false, false, DisplayModel.ALWAYS, DEBUG_PICK_ID); os.render(window.getWindowID(), Renderer.this, window.getViewableWidth(), window.getViewableHeight(), cam, null); // Also draw this window's debug string os = new OverlayString(defFont, window.getDebugString(), ColourInput.BLACK, 10, 10, 30, false, false, DisplayModel.ALWAYS, DEBUG_PICK_ID); os.render(window.getWindowID(), Renderer.this, window.getViewableWidth(), window.getViewableHeight(), cam, null); drawContext = null; gl.glEnable(GL2GL3.GL_DEPTH_TEST); } gl.glFinish(); long endNanos = System.nanoTime(); lastFrameNanos = endNanos - startNanos; } }
Example 3
Source File: TextureView.java From jaamsim with Apache License 2.0 | 4 votes |
private void renderImp(int contextID, Renderer renderer, Camera cam, Ray pickRay) { if (!staticInit) { initStaticBuffers(renderer); } GL2GL3 gl = renderer.getGL(); int textureID = _texLoader.getTexID(renderer); if (textureID == TexCache.LOADING_TEX_ID) { return; // This texture is not ready yet } if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); if ( _texCoords != null && (_texCoordHandle == null || !_texCoordHandle.isValid()) ) { updateTexCoordBuffer(renderer); } Mat4d modelViewMat = new Mat4d(); cam.getViewMat4d(modelViewMat); modelViewMat.mult4(_trans.getMat4dRef()); modelViewMat.scaleCols3(_scale); Mat4d normalMat = RenderUtils.getInverseWithScale(_trans, _scale); normalMat.transpose4(); gl.glUseProgram(progHandle); gl.glUniformMatrix4fv(modelViewMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewMat), 0); gl.glUniformMatrix4fv(projMatVar, 1, false, RenderUtils.MarshalMat4d(cam.getProjMat4d()), 0); gl.glUniformMatrix4fv(normalMatVar, 1, false, RenderUtils.MarshalMat4d(normalMat), 0); gl.glUniformMatrix4fv(bindSpaceMatVar, 1, false, identMat, 0); gl.glUniformMatrix4fv(bindSpaceNorMatVar, 1, false, identMat, 0); gl.glUniform1f(cVar, Camera.C); gl.glUniform1f(fcVar, Camera.FC); gl.glUniform1i(numLightsVar, 1); gl.glUniform3fv(lightDirVar, 1, lightDir, 0); gl.glUniform1fv(lightIntVar, 1, lightInt, 0); gl.glUniform3f(ambientColorVar, 0.0f, 0.0f, 0.0f); gl.glUniform3f(specColorVar, 0.0f, 0.0f, 0.0f); gl.glUniform1f(shininessVar, 1.0f); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, textureID); gl.glUniform1i(texVar, 0); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_CLAMP_TO_EDGE); // Draw gl.glDisable(GL2GL3.GL_CULL_FACE); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, 6); gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }
Example 4
Source File: OverlayTexture.java From jaamsim with Apache License 2.0 | 4 votes |
@Override public void render(int contextID, Renderer renderer, double windowWidth, double windowHeight, Camera cam, Ray pickRay) { if (!staticInit) { initStaticBuffers(renderer); } double x = _x; double y = _y; if (_alignRight) { x = windowWidth - _x - _width; } if (!_alignBottom) { y = windowHeight - _y - _height; } GL2GL3 gl = renderer.getGL(); int textureID = renderer.getTexCache().getTexID(gl, _imageURI, _isTransparent, _isCompressed, false); if (textureID == TexCache.LOADING_TEX_ID) { return; // This texture is not ready yet } if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(progHandle); gl.glUniform1i(hasTexVar, 1); gl.glActiveTexture(GL2GL3.GL_TEXTURE0); gl.glBindTexture(GL2GL3.GL_TEXTURE_2D, textureID); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_S, GL2GL3.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL2GL3.GL_TEXTURE_2D, GL2GL3.GL_TEXTURE_WRAP_T, GL2GL3.GL_CLAMP_TO_EDGE); gl.glUniform1i(texVar, 0); if (_isTransparent) { gl.glEnable(GL2GL3.GL_BLEND); 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); } // Set the size and scale in normalized (-1, 1) coordinates double normX = x / (0.5 * windowWidth) - 1; double normY = y / (0.5 * windowHeight) - 1; double normWidth = _width / (0.5 * windowWidth); double normHeight = _height / (0.5 * windowHeight); gl.glUniform2f(offsetVar, (float)normX, (float)normY); gl.glUniform2f(sizeVar, (float)normWidth, (float)normHeight); // Draw gl.glDisable(GL2GL3.GL_CULL_FACE); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, 0, 6); gl.glEnable(GL2GL3.GL_CULL_FACE); if (_isTransparent) { gl.glDisable(GL2GL3.GL_BLEND); } }
Example 5
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") private void renderBatch(int contextID, Renderer renderer, MeshBatch batch) { // TODO bounds // TODO size culling Material mat = _materials.get(batch.matIndex); SubMesh subMesh = _subMeshes.get(batch.meshIndex); int shaderID = mat.shaderID | Renderer.STATIC_BATCH_FLAG; GL2GL3 gl = renderer.getGL(); GL4 gl4 = renderer.getGL4(); if (!batch.vaoMaps[shaderID].containsKey(contextID)) { setupVAOForBatch(contextID, batch, renderer); } int vao = batch.vaoMaps[shaderID].get(contextID); gl.glBindVertexArray(vao); ShaderInfo si = sInfos[shaderID]; gl.glUseProgram(si.meshProgHandle); // Setup uniforms for this object\ 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); // Actually draw it gl.glDisable(GL2GL3.GL_CULL_FACE); //gl.glDrawElements(GL2GL3.GL_TRIANGLES, subMesh._numVerts, GL2GL3.GL_UNSIGNED_INT, 0); gl4.glDrawElementsInstanced(GL2GL3.GL_TRIANGLES, subMesh._numVerts, GL2GL3.GL_UNSIGNED_INT, 0, batch.numInstances); gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }
Example 6
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 7
Source File: MeshProto.java From jaamsim with Apache License 2.0 | 4 votes |
private void renderStaticMeshes(int contextID, Renderer renderer, Mat4d modelViewMat, Camera cam) { if (data.getStaticMeshInstances().size() == 0) { return; } GL2GL3 gl = renderer.getGL(); GL4 gl4 = renderer.getGL4(); if (!_meshVAOs.containsKey(contextID)) { setupVAOForStaticMeshes(contextID, renderer); } int vao = _meshVAOs.get(contextID); gl.glBindVertexArray(vao); gl.glDisable(GL2GL3.GL_CULL_FACE); // Actually draw it gl4.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, meshIndBuffer); // Server side indirect buffer gl4.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, meshIndirectBuffer); gl4.glMultiDrawElementsIndirect(GL2GL3.GL_TRIANGLES, GL2GL3.GL_UNSIGNED_INT, null, _batches.size(), 0); // Client side indirect buffer // gl4.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, 0); // gl4.glMultiDrawElementsIndirect(GL2GL3.GL_TRIANGLES, GL2GL3.GL_UNSIGNED_INT, indirectBufferData, _indirectData.size(), 0); // Individual indirect calls // gl4.glBindBuffer(GL4.GL_DRAW_INDIRECT_BUFFER, 0); // for (int i = 0; i < _batches.size(); ++i) { // indirectBufferData.position(i*5); // gl4.glDrawElementsIndirect(GL2GL3.GL_TRIANGLES, GL2GL3.GL_UNSIGNED_INT, indirectBufferData); // } // for (IndirectData id: _indirectData) { // gl4.glDrawElementsInstancedBaseVertexBaseInstance( // GL2GL3.GL_TRIANGLES, // id.count, // GL4.GL_UNSIGNED_INT, // id.firstIndex*4, // id.numInstances, // id.baseVertex, // id.baseInstance // ); // } gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }
Example 8
Source File: DebugUtils.java From jaamsim with Apache License 2.0 | 4 votes |
public static void renderArmature(int contextID, Renderer renderer, Mat4d modelViewMat, Armature arm, ArrayList<Mat4d> pose, Color4d color, Camera cam) { GL2GL3 gl = renderer.getGL(); if (!_debugVAOMap.containsKey(contextID)) { setupDebugVAO(contextID, renderer); } int vao = _debugVAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(_debugProgHandle); // 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.glUniform4fv(_colorVar, 1, color.toFloats(), 0); gl.glUniform1f(_cVar, Camera.C); gl.glUniform1f(_fcVar, Camera.FC); ArrayList<Armature.Bone> bones = arm.getAllBones(); //Build up the list of bone vertices Vec4d[] vects = new Vec4d[bones.size() * 2]; for (int i = 0; i < bones.size(); ++i) { Armature.Bone b = bones.get(i); Vec4d boneStart = new Vec4d(0, 0, 0, 1); boneStart.mult4(b.getMatrix(), boneStart); Vec4d boneEnd = new Vec4d(0, b.getLength(), 0, 1); boneEnd.mult4(b.getMatrix(), boneEnd); if (pose != null) { // Adjust the bone by the current pose Mat4d poseMat = pose.get(i); boneStart.mult4(poseMat, boneStart); boneEnd.mult4(poseMat, boneEnd); } vects[2*i + 0] = boneStart; vects[2*i + 1] = boneEnd; } // Now push it to the card FloatBuffer fb = FloatBuffer.allocate(vects.length * 3); for (Vec4d v : vects) { RenderUtils.putPointXYZ(fb, v); } fb.flip(); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _lineVertBuffer); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, fb.limit() * 4, fb, GL2GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(_posVar, 3, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); gl.glDisable(GL2GL3.GL_DEPTH_TEST); gl.glDrawArrays(GL2GL3.GL_LINES, 0, fb.limit() / 3); gl.glEnable(GL2GL3.GL_DEPTH_TEST); gl.glLineWidth(1.0f); gl.glBindVertexArray(0); }
Example 9
Source File: BillboardString.java From jaamsim with Apache License 2.0 | 4 votes |
/** * Note: render() and renderForView() are mutually non-reentrant due to shared temporaries. This should be fine * because neither should ever be called by any thread other than the render thread. */ @Override public void render(int contextID, Renderer renderer, double windowWidth, double windowHeight, Camera cam, Ray pickRay) { GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); // Render the string Shader s = renderer.getShader(Renderer.ShaderHandle.OVERLAY_FONT); s.useShader(gl); int prog = s.getProgramHandle(); // Work out the billboard position cam.getViewMat4d(tempViewMat); // Build up the projection*view matrix tempViewMat.mult4(cam.getProjMat4d(), tempViewMat); tempPos.x = _pos.x; tempPos.y = _pos.y; tempPos.z = _pos.z; tempPos.w = 1.0; tempPos.mult4(tempViewMat, tempPos); tempPos.x /= tempPos.w; tempPos.y /= tempPos.w; // TempPos x and y are now in normalized coordinate space (after the projection) int colorVar = gl.glGetUniformLocation(prog, "color"); gl.glUniform4fv(colorVar, 1, _color, 0); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl)); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); int offsetVar = gl.glGetUniformLocation(prog, "offset"); float scaleY = (float)(2 * _height / (windowHeight * _font.getNominalHeight())); float scaleX = scaleY * (float)(windowHeight/windowWidth); int scaleVar = gl.glGetUniformLocation(prog, "scale"); gl.glUniform2f(scaleVar, scaleX, scaleY); float offsetX = (float)tempPos.x; float offsetY = (float)tempPos.y; offsetX += _xOffset*2.0/windowWidth; offsetY += _yOffset*2.0/windowHeight; gl.glDisable(GL2GL3.GL_CULL_FACE); for (int cp : RenderUtils.stringToCodePoints(_contents)) { TessChar tc = _font.getTessChar(cp); if (tc == null) { assert(false); continue; } gl.glUniform2f(offsetVar, offsetX, offsetY); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, tc.getStartIndex(), tc.getNumVerts()); offsetX += tc.getAdvance()*scaleX; } gl.glEnable(GL2GL3.GL_CULL_FACE); }
Example 10
Source File: TessString.java From jaamsim with Apache License 2.0 | 4 votes |
@Override public void render(int contextID, Renderer renderer, Camera cam, Ray pickRay) { GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); // Render the string Shader s = renderer.getShader(Renderer.ShaderHandle.FONT); s.useShader(gl); int prog = s.getProgramHandle(); // Setup uniforms for this object Mat4d modelViewProjMat = new Mat4d(); cam.getViewMat4d(modelViewProjMat); modelViewProjMat.mult4(_trans); Mat4d projMat = cam.getProjMat4d(); modelViewProjMat.mult4(projMat, modelViewProjMat); int modelViewProjMatVar = gl.glGetUniformLocation(prog, "modelViewProjMat"); gl.glUniformMatrix4fv(modelViewProjMatVar, 1, false, RenderUtils.MarshalMat4d(modelViewProjMat), 0); int colorVar = gl.glGetUniformLocation(prog, "color"); gl.glUniform4fv(colorVar, 1, _color, 0); int cVar = gl.glGetUniformLocation(prog, "C"); gl.glUniform1f(cVar, Camera.C); int fcVar = gl.glGetUniformLocation(prog, "FC"); gl.glUniform1f(fcVar, Camera.FC); int advanceVar = gl.glGetUniformLocation(prog, "advance"); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl)); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); // Send out one draw call per character float advance = 0; gl.glDisable(GL2GL3.GL_CULL_FACE); for (int i = 0; i < _contents.length; ++i) { gl.glUniform1f(advanceVar, advance); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, starts[i], numVerts[i]); advance += advances[i]; } gl.glEnable(GL2GL3.GL_CULL_FACE); // Cleanup gl.glDisableVertexAttribArray(posVar); }
Example 11
Source File: OverlayString.java From jaamsim with Apache License 2.0 | 4 votes |
@Override public void render(int contextID, Renderer renderer, double windowWidth, double windowHeight, Camera cam, Ray pickRay) { Vec3d renderedSize = _font.getStringSize(_height, _contents); double x = _x; double y = _y; if (_alignRight) { x = windowWidth - _x - renderedSize.x; } if (!_alignBottom) { y = windowHeight - _y - renderedSize.y; } GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); // Render the string Shader s = renderer.getShader(Renderer.ShaderHandle.OVERLAY_FONT); s.useShader(gl); int prog = s.getProgramHandle(); int colorVar = gl.glGetUniformLocation(prog, "color"); gl.glUniform4fv(colorVar, 1, _color, 0); int posVar = gl.glGetAttribLocation(prog, "position"); gl.glEnableVertexAttribArray(posVar); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, _font.getGLBuffer(gl)); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); int offsetVar = gl.glGetUniformLocation(prog, "offset"); float scaleY = (float)(2 * _height / (windowHeight * _font.getNominalHeight())); float scaleX = scaleY * (float)(windowHeight/windowWidth); int scaleVar = gl.glGetUniformLocation(prog, "scale"); gl.glUniform2f(scaleVar, scaleX, scaleY); float offsetX = (float)(2*x/windowWidth - 1); float offsetY = (float)(2*y/windowHeight - 1); gl.glDisable(GL2GL3.GL_CULL_FACE); for (int cp : RenderUtils.stringToCodePoints(_contents)) { TessChar tc = _font.getTessChar(cp); if (tc == null) { assert(false); continue; } gl.glUniform2f(offsetVar, offsetX, offsetY); gl.glDrawArrays(GL2GL3.GL_TRIANGLES, tc.getStartIndex(), tc.getNumVerts()); offsetX += tc.getAdvance()*scaleX; } gl.glEnable(GL2GL3.GL_CULL_FACE); }
Example 12
Source File: OverlayPolygon.java From jaamsim with Apache License 2.0 | 2 votes |
@Override public void render(int contextID, Renderer renderer, double windowWidth, double windowHeight, Camera cam, Ray pickRay) { if (!staticInit) { initStaticData(renderer); } GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(progHandle); gl.glUniform4fv(colorVar, 1, color.toFloats(), 0); gl.glUniform1i(hasTexVar, 0); // Set the size and offset in normalized (-1, 1) coordinates double scaleX = 2.0 / windowWidth; double scaleY = 2.0 / windowHeight; double pixelWidth = 2.0/windowWidth; double pixelHeight = 2.0/windowHeight; double xOffset = -1.0 + 0.5*pixelWidth; double yOffset = -1.0 + 0.5*pixelHeight; if (originTop) { scaleY *= -1.0; yOffset = 1.0 - 0.5*pixelHeight; } if (originRight) { scaleX *= -1.0; xOffset = 1.0 - 0.5*pixelWidth; } gl.glUniform2f(offsetVar, (float)xOffset, (float)yOffset); gl.glUniform2f(sizeVar, (float)scaleX, (float)scaleY); gl.glEnableVertexAttribArray(posVar); gl.glDisable(GL2GL3.GL_CULL_FACE); // Build up a float buffer to pass to GL gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, glBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, pointsBuffer.limit() * 4, pointsBuffer, GL2GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); gl.glDrawArrays(GL2GL3.GL_TRIANGLE_FAN, 0, pointsBuffer.limit() / 2); gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }
Example 13
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); }
Example 14
Source File: OverlayLine.java From jaamsim with Apache License 2.0 | 2 votes |
@Override public void render(int contextID, Renderer renderer, double windowWidth, double windowHeight, Camera cam, Ray pickRay) { if (!staticInit) { initStaticData(renderer); } GL2GL3 gl = renderer.getGL(); if (!VAOMap.containsKey(contextID)) { setupVAO(contextID, renderer); } int vao = VAOMap.get(contextID); gl.glBindVertexArray(vao); gl.glUseProgram(progHandle); gl.glUniform4fv(colorVar, 1, color.toFloats(), 0); gl.glUniform1i(hasTexVar, 0); // Set the size and offset in normalized (-1, 1) coordinates double scaleX = 2.0 / windowWidth; double scaleY = 2.0 / windowHeight; double pixelWidth = 2.0/windowWidth; double pixelHeight = 2.0/windowHeight; double xOffset = -1.0 + 0.5*pixelWidth; double yOffset = -1.0 + 0.5*pixelHeight; if (originTop) { scaleY *= -1.0; yOffset = 1.0 - 0.5*pixelHeight; } if (originRight) { scaleX *= -1.0; xOffset = 1.0 - 0.5*pixelWidth; } gl.glUniform2f(offsetVar, (float)xOffset, (float)yOffset); gl.glUniform2f(sizeVar, (float)scaleX, (float)scaleY); gl.glEnableVertexAttribArray(posVar); gl.glDisable(GL2GL3.GL_CULL_FACE); if (!gl.isGLcore()) gl.glLineWidth((float)lineWidth); else gl.glLineWidth(1.0f); // Build up a float buffer to pass to GL gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, lineGLBuff); gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, lineBuffer.limit() * 4, lineBuffer, GL2GL3.GL_STATIC_DRAW); gl.glVertexAttribPointer(posVar, 2, GL2GL3.GL_FLOAT, false, 0, 0); gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0); gl.glDrawArrays(GL2GL3.GL_LINES, 0, lineBuffer.limit() / 2); gl.glLineWidth(1.0f); gl.glEnable(GL2GL3.GL_CULL_FACE); gl.glBindVertexArray(0); }