Java Code Examples for org.lwjgl.opengl.GL11#glDrawElements()
The following examples show how to use
org.lwjgl.opengl.GL11#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: vboWithIndices.java From ldparteditor with MIT License | 6 votes |
@Override public void drawScene(float mouseX, float mouseY) { final GLCanvas canvas = cp.getCanvas(); if (!canvas.isCurrent()) { canvas.setCurrent(); GL.setCapabilities(cp.getCapabilities()); } GL11.glColorMask(true, true, true, true); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT); Rectangle bounds = cp.getBounds(); GL11.glViewport(0, 0, bounds.width, bounds.height); shaderProgram.use(); GL30.glBindVertexArray(VAO); // GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0); // GL20.glDisableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary! GL30.glBindVertexArray(0); canvas.swapBuffers(); }
Example 2
Source File: GL33HelperPrimitives.java From ldparteditor with MIT License | 6 votes |
public static void drawTrianglesIndexedRGB_Triangle(float[] vertices, int[] indices) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_triangle); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertices); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_triangle); GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, indices); GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0); GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION); GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4 GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0); }
Example 3
Source File: GL33HelperPrimitives.java From ldparteditor with MIT License | 6 votes |
public static void drawTrianglesIndexedRGB_Quad(float[] vertices, int[] indices) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_quad); GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0 , vertices); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_quad); GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, indices); GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0); GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION); GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4 GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, 12, GL11.GL_UNSIGNED_INT, 0); }
Example 4
Source File: GL33Helper.java From ldparteditor with MIT License | 6 votes |
public void drawTrianglesIndexedRGB_General(float[] vertices, int[] indices) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STREAM_DRAW); GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0); GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION); GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4 GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0); }
Example 5
Source File: GL33Helper.java From ldparteditor with MIT License | 6 votes |
public static void drawTrianglesIndexedRGB_GeneralSlow(float[] vertices, int[] indices) { int VBO_general = GL15.glGenBuffers(); int EBO_general = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STREAM_DRAW); GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0); GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION); GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4 GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0); GL15.glDeleteBuffers(VBO_general); GL15.glDeleteBuffers(EBO_general); }
Example 6
Source File: SkyboxRenderer.java From OpenGL-Animation with The Unlicense | 5 votes |
/** * Renders the skybox. * * @param camera * - the scene's camera. */ public void render(ICamera camera) { prepare(camera); box.bind(0); GL11.glDrawElements(GL11.GL_TRIANGLES, box.getIndexCount(), GL11.GL_UNSIGNED_INT, 0); box.unbind(0); shader.stop(); }
Example 7
Source File: Renderer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void renderMesh(Mesh mesh) { GL30.glBindVertexArray(mesh.getVAO()); GL30.glEnableVertexAttribArray(0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIBO()); GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL30.glDisableVertexAttribArray(0); GL30.glBindVertexArray(0); }
Example 8
Source File: GL33Helper.java From ldparteditor with MIT License | 5 votes |
public static void drawTrianglesIndexedTextured_GeneralSlow(float[] vertices, int[] indices) { int VAO_general = GL30.glGenVertexArrays(); int VBO_general = GL15.glGenBuffers(); int EBO_general = GL15.glGenBuffers(); GL30.glBindVertexArray(VAO_general); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW); GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 0); GL20.glEnableVertexAttribArray(TEX_NORMAL_SHADER_LOCATION); GL20.glVertexAttribPointer(TEX_NORMAL_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 12); // 3 * 4 GL20.glEnableVertexAttribArray(TEX_COLOUR_SHADER_LOCATION); GL20.glVertexAttribPointer(TEX_COLOUR_SHADER_LOCATION, 4, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 24); GL20.glEnableVertexAttribArray(UV_SHADER_LOCATION); GL20.glVertexAttribPointer(UV_SHADER_LOCATION, 2, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 40); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0); GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(VAO_general); GL15.glDeleteBuffers(VBO_general); GL15.glDeleteBuffers(EBO_general); }
Example 9
Source File: LandscapeRenderer.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
final void renderShadow(int patch_x, int patch_y, int start_x, int start_y, int end_x, int end_y) { landscape_vertices.bind(patch_x, patch_y); PatchLevel patch_level = getPatchLevel(patch_x, patch_y); shadow_indices_buffer.clear(); world.getLandscapeIndices().fillCoverIndices(shadow_indices_buffer, patch_level.getLevel(), patch_level.getBorderSet(), start_x, start_y, end_x, end_y); shadow_indices_buffer.flip(); GL11.glDrawElements(GL11.GL_TRIANGLES, shadow_indices_buffer); }
Example 10
Source File: OpenGL3_TheQuadTextured.java From ldparteditor with MIT License | 4 votes |
private void loopCycle() { // Logic while(Keyboard.next()) { // Only listen to events where the key was pressed (down event) if (!Keyboard.getEventKeyState()) continue; // Switch textures depending on the key released switch (Keyboard.getEventKey()) { case Keyboard.KEY_1: textureSelector = 0; break; case Keyboard.KEY_2: textureSelector = 1; break; } } // Render GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL20.glUseProgram(pId); // Bind the texture GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texIds[textureSelector]); // Bind to the VAO that has all the information about the 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, vboiId); // Draw the vertices GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0); // Put everything back to default (deselect) GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); GL20.glUseProgram(0); this.exitOnGLError("loopCycle"); }
Example 11
Source File: TerrainRenderer.java From LowPolyWater with The Unlicense | 3 votes |
/** * Renders a terrain to the screen. If the terrain has an index buffer the * glDrawElements is used. Otherwise glDrawArrays is used. * * @param terrain * - The terrain to be rendered. * @param camera * - The camera being used for rendering the terrain. * @param light * - The light being used to iluminate the terrain. * * @param clipPlane * - The equation of the clipping plane to be used when rendering * the terrain. The clipping planes cut off anything in the scene * that is rendered outside of the plane. */ public void render(Terrain terrain, ICamera camera, Light light, Vector4f clipPlane) { prepare(terrain, camera, light, clipPlane); if (hasIndices) { GL11.glDrawElements(GL11.GL_TRIANGLES, terrain.getVertexCount(), GL11.GL_UNSIGNED_INT, 0); } else { GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, terrain.getVertexCount()); } finish(terrain); }
Example 12
Source File: AnimatedModelRenderer.java From OpenGL-Animation with The Unlicense | 3 votes |
/** * Renders an animated entity. The main thing to note here is that all the * joint transforms are loaded up to the shader to a uniform array. Also 5 * attributes of the VAO are enabled before rendering, to include joint * indices and weights. * * @param entity * - the animated entity to be rendered. * @param camera * - the camera used to render the entity. * @param lightDir * - the direction of the light in the scene. */ public void render(AnimatedModel entity, ICamera camera, Vector3f lightDir) { prepare(camera, lightDir); entity.getTexture().bindToUnit(0); entity.getModel().bind(0, 1, 2, 3, 4); shader.jointTransforms.loadMatrixArray(entity.getJointTransforms()); GL11.glDrawElements(GL11.GL_TRIANGLES, entity.getModel().getIndexCount(), GL11.GL_UNSIGNED_INT, 0); entity.getModel().unbind(0, 1, 2, 3, 4); finish(); }
Example 13
Source File: GearGL20.java From ldparteditor with MIT License | 3 votes |
public void draw(float x, float y, float z) { GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, bvertices); GL11.glDrawElements(GL11.GL_QUADS, bindices); GL11.glPopMatrix(); }
Example 14
Source File: SphereGL20.java From ldparteditor with MIT License | 3 votes |
public void draw(float x, float y, float z) { GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, bvertices); GL11.glDrawElements(GL11.GL_QUADS, bindices); GL11.glPopMatrix(); }
Example 15
Source File: GearGL33.java From ldparteditor with MIT License | 3 votes |
public void draw(GLMatrixStack stack, GLShader shader, float x, float y, float z, float r, float g, float b) { final GLShader backup = stack.getShader(); stack.setShader(shader); shader.use(); stack.glPushMatrix(); stack.glLoadIdentity(); stack.glTranslatef(x, y, z); final int colour = shader.getUniformLocation("color"); //$NON-NLS-1$ GL20.glUniform3f(colour, r, g, b); final int VBO = GL15.glGenBuffers(); final int EBO = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, bvertices, GL15.GL_STREAM_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, bindices, GL15.GL_STREAM_DRAW); GL20.glEnableVertexAttribArray(0); GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 12, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL11.glDrawElements(GL11.GL_TRIANGLES, bindices.capacity(), GL11.GL_UNSIGNED_INT, 0); GL15.glDeleteBuffers(VBO); GL15.glDeleteBuffers(EBO); stack.setShader(backup); backup.use(); stack.glPopMatrix(); }