List of usage examples for org.lwjgl.opengl GL11 glDrawElements
public static void glDrawElements(@NativeType("GLenum") int mode, @NativeType("GLsizei") int count, @NativeType("GLenum") int type, @NativeType("void const *") long indices)
From source file:com.flowpowered.caustic.lwjgl.gl30.GL30VertexArray.java
License:MIT License
@Override public void draw() { checkCreated();/*from w w w . ja v a 2s .c om*/ // Bind the vao GL30.glBindVertexArray(id); // Bind the index buffer GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferID); // Set the polygon mode GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, polygonMode.getGLConstant()); // Draw all indices with the provided mode GL11.glDrawElements(drawingMode.getGLConstant(), indicesDrawCount, GL11.GL_UNSIGNED_INT, indicesOffset * DataType.INT.getByteSize()); // Unbind the index buffer GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); // Unbind the vao GL30.glBindVertexArray(0); // Check for errors LWJGLUtil.checkForGLError(); }
From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java
/** * Render the Object.//from w w w . j a v a2 s .com */ public void render() { FloatBuffer matrix44Buffer = BufferUtils.createFloatBuffer(16); modelMatrix.store(matrix44Buffer); matrix44Buffer.flip(); GL20.glUniformMatrix4(ShaderProgram.getMML(), false, matrix44Buffer); // Bind the texture GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // Bind to the VAO that has all the information about the quad vertices GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); // Bind to the index VBO that has all the information about the order of the vertices GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboIndicesId); // Draw the vertices GL11.glDrawElements(GL11.GL_TRIANGLES, indicesData.length, GL11.GL_UNSIGNED_BYTE, 0); // Put everything back to default (deselect) GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(2); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(0); GL30.glBindVertexArray(0); }
From source file:com.google.gapid.glviewer.gl.Renderer.java
License:Apache License
/** * Draws primitives using the vertex data bound to the given shader, indexed from the * given index buffer./*from www . j a v a 2s .c o m*/ */ public static void draw(Shader shader, int primitive, IndexBuffer indices) { shader.bind(); indices.bind(); GL11.glDrawElements(primitive, indices.count, indices.type, 0); }
From source file:com.grillecube.client.opengl.GLH.java
public static void glhDrawElements(int glTriangles, int indexCount, int indiceType, long indices) { GL11.glDrawElements(glTriangles, indexCount, indiceType, indices); theContext.incrementDrawCalls();// w ww . j a v a2s. c o m theContext.increaseVerticesDrawn(indexCount / 3); }
From source file:com.opengrave.og.base.Renderable3D.java
License:Open Source License
@Override public void render(Matrix4f matrix, RenderStyle style) { dealWithChange();//from w w w . jav a2 s . co m int pID = Resources.loadShader("model.vs", "model.fs").getProgram(); GL20.glUseProgram(pID); int texture = GL20.glGetUniformLocation(pID, "texture"); int shadow = GL20.glGetUniformLocation(pID, "shadowMap"); GL20.glUniform1i(texture, 0); GL20.glUniform1i(shadow, 1); GL30.glBindVertexArray(vao_ID); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); GL20.glBindAttribLocation(pID, 0, "in_Position"); GL20.glBindAttribLocation(pID, 1, "in_Normal"); GL20.glBindAttribLocation(pID, 2, "in_TextureCoord"); Util.checkErr(); if (matList != null && matList.valid()) { matList.bind(pID, GL13.GL_TEXTURE0); Util.loadMaterials(matList, pID); } Util.checkErr(); getContext().setMatrices(pID, matrix); getContext().bindShadowData(GL13.GL_TEXTURE2); getContext().bindLights(pID, GL13.GL_TEXTURE3); Util.setRenderStyle(pID, style); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID); GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); getContext().unbindLights(); getContext().unbindShadowData(); if (matList != null && matList.valid()) { matList.unbind(); } Util.checkErr(); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); Util.checkErr(); GL20.glUseProgram(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }
From source file:com.opengrave.og.base.Renderable3D.java
License:Open Source License
@Override public void renderShadows(Matrix4f matrix, Shadow shadow) { dealWithChange();// w w w. ja va 2 s. c o m int pID = Resources.loadShader("model.vs", "castshadow.fs").getProgram(); GL20.glUseProgram(pID); GL30.glBindVertexArray(vao_ID); GL20.glEnableVertexAttribArray(0); GL20.glBindAttribLocation(pID, 0, "in_Position"); Util.checkErr(); getContext().setShadowMatrices(pID, matrix, shadow); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID); GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); Util.checkErr(); GL20.glDisableVertexAttribArray(0); Util.checkErr(); GL20.glUseProgram(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }
From source file:com.opengrave.og.base.Renderable3D.java
License:Open Source License
@Override public void renderForPicking(Matrix4f matrix, Pickable object) { dealWithChange();// www. j a v a2 s .co m int pID = Resources.loadShader("model.vs", "pickingmodel.fs").getProgram(); GL20.glUseProgram(pID); GL30.glBindVertexArray(vao_ID); GL20.glEnableVertexAttribArray(0); GL20.glBindAttribLocation(pID, 0, "in_Position"); Util.checkErr(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID); getContext().setMatrices(pID, matrix); Picking.registerObject(pID, getContext(), object); GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); Util.checkErr(); GL20.glDisableVertexAttribArray(0); Util.checkErr(); GL20.glUseProgram(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }
From source file:com.opengrave.og.base.RenderableBoneAnimated.java
License:Open Source License
@Override public void render(Matrix4f matrix, RenderStyle style) { // if (!visible) { // return;// www .j ava 2 s . co m // } GL11.glDisable(GL11.GL_CULL_FACE); // TODO Enable Face Culling, and be // absolutely sure that all tris are // facing the correct way dealWithChange(); int pID = Resources.loadShader("animmodel.vs", "animmodel.fs").getProgram(); GL20.glUseProgram(pID); int texture = GL20.glGetUniformLocation(pID, "texture"); int shadow = GL20.glGetUniformLocation(pID, "shadowMap"); GL20.glUniform1i(texture, 0); GL20.glUniform1i(shadow, 1); GL30.glBindVertexArray(vao_ID); GL20.glBindAttribLocation(pID, 0, "in_Position"); GL20.glBindAttribLocation(pID, 1, "in_Normal"); GL20.glBindAttribLocation(pID, 2, "in_TextureCoord"); GL20.glBindAttribLocation(pID, 3, "in_BoneID"); GL20.glBindAttribLocation(pID, 4, "in_BoneWeight"); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); GL20.glEnableVertexAttribArray(3); GL20.glEnableVertexAttribArray(4); if (matList != null && matList.valid()) { matList.bind(pID, GL13.GL_TEXTURE0); Util.loadMaterials(matList, pID); } setBonesUniform(pID); getContext().setMatrices(pID, matrix); getContext().bindShadowData(GL13.GL_TEXTURE2); getContext().bindLights(pID, GL13.GL_TEXTURE3); Util.setRenderStyle(pID, style); // GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertCount); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID); GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); getContext().unbindLights(); getContext().unbindShadowData(); if (matList != null && matList.valid()) { matList.unbind(); } GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL20.glDisableVertexAttribArray(3); GL20.glDisableVertexAttribArray(4); GL20.glUseProgram(0); GL30.glBindVertexArray(0); GL11.glEnable(GL11.GL_CULL_FACE); }
From source file:com.opengrave.og.base.RenderableBoneAnimated.java
License:Open Source License
@Override public void renderShadows(Matrix4f matrix, Shadow shadow) { // if (!visible) { // return;/* w w w .j a v a 2s . c o m*/ // } dealWithChange(); int pID = Resources.loadShader("animmodel.vs", "animmodel.fs").getProgram(); GL20.glUseProgram(pID); GL30.glBindVertexArray(vao_ID); GL20.glBindAttribLocation(pID, 0, "in_Position"); GL20.glBindAttribLocation(pID, 3, "in_BoneID"); GL20.glBindAttribLocation(pID, 4, "in_BoneWeight"); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(3); GL20.glEnableVertexAttribArray(4); setBonesUniform(pID); getContext().setShadowMatrices(pID, matrix, shadow); // GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertCount); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID); GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(3); GL20.glDisableVertexAttribArray(4); GL20.glUseProgram(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }
From source file:com.opengrave.og.base.RenderableBoneAnimated.java
License:Open Source License
@Override public void renderForPicking(Matrix4f matrix, Pickable object) { dealWithChange();//from w w w .java2 s .c o m int pID = Resources.loadShader("animmodel.vs", "pickingmodel.fs").getProgram(); GL20.glUseProgram(pID); GL30.glBindVertexArray(vao_ID); GL20.glBindAttribLocation(pID, 0, "in_Position"); GL20.glBindAttribLocation(pID, 3, "in_BoneID"); GL20.glBindAttribLocation(pID, 4, "in_BoneWeight"); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(3); GL20.glEnableVertexAttribArray(4); setBonesUniform(pID); // Util.setShadowMatrices(pID, shadow, location, scale, rotation, // matrix); Picking.registerObject(pID, getContext(), object); getContext().setMatrices(pID, matrix); // GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertCount); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vbo_index_ID); GL11.glDrawElements(GL11.GL_TRIANGLES, indexCount, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(3); GL20.glDisableVertexAttribArray(4); GL20.glUseProgram(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }