List of usage examples for org.lwjgl.opengl GL30 glBindVertexArray
public static void glBindVertexArray(@NativeType("GLuint") int array)
From source file:com.xrbpowered.gl.res.StaticMesh.java
License:Open Source License
public void disableDraw() { GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); for (int i = 0; i < countAttribs; i++) GL20.glDisableVertexAttribArray(i); GL30.glBindVertexArray(0); }
From source file:com.xrbpowered.gl.res.StaticMesh.java
License:Open Source License
public void destroy() { GL30.glBindVertexArray(vaoId); for (int i = 0; i < countAttribs; i++) GL20.glDisableVertexAttribArray(i); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboId);/*w ww .j a v a 2s . c o m*/ GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); if (vboiId != GL11.GL_INVALID_VALUE) GL15.glDeleteBuffers(vboiId); GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(vaoId); }
From source file:cuchaz.jfxgl.prism.TexturedQuad.java
License:Open Source License
public TexturedQuad(int x, int y, int w, int h, int texId, Shader shader) { this.shader = shader; this.texId = texId; // make the vertex array vaoId = GL30.glGenVertexArrays();/*from w w w . ja v a 2 s . c o m*/ GL30.glBindVertexArray(vaoId); try (MemoryStack m = MemoryStack.stackPush()) { // make the indices ByteBuffer indexBuf = m.bytes(new byte[] { 0, 1, 2, 0, 2, 3 }); iboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, iboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, indexBuf, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, iboId); // make the vertices FloatBuffer vertexBuf = m.floats( new float[] { x + 0, y + 0, 0, 0, x + w, y + 0, 1, 0, x + w, y + h, 1, 1, x + 0, y + h, 0, 1 }); vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexBuf, GL15.GL_STATIC_DRAW); GL20.glEnableVertexAttribArray(0); GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, Float.BYTES * 4, 0); GL20.glEnableVertexAttribArray(1); GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, Float.BYTES * 4, Float.BYTES * 2); } // unbind things GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); }
From source file:cuchaz.jfxgl.prism.TexturedQuad.java
License:Open Source License
public void render() { // bind stuff shader.bind();// www. j a v a 2 s . c om GL30.glBindVertexArray(vaoId); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); // draw it! GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_BYTE, 0); // unbind things GL30.glBindVertexArray(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
From source file:Data.Building.java
License:Apache License
@Override public void setup() { // OpenGL expects vertices to be defined counter clockwise by default triangulize(geometry);/*w ww .j ava 2 s.c om*/ // Sending data to OpenGL requires the usage of (flipped) byte buffers FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length); verticesBuffer.put(vertices); verticesBuffer.flip(); vertexCount = vertices.length; // Create a new Vertex Array Object in memory and select it (bind) // A VAO can have up to 16 attributes (VBO's) assigned to it by default vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); // Create a new Vertex Buffer Object in memory and select it (bind) // A VBO is a collection of Vectors which in this case resemble the location of each vertex. vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW); // Put the VBO in the attributes list at index 0 GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0); // Deselect (bind to 0) the VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Deselect (bind to 0) the VAO GL30.glBindVertexArray(0); Util.exitOnGLError("Error in setupQuad"); }
From source file:Data.Building.java
License:Apache License
@Override public void render() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); // Bind to the VAO that has all the information about the quad vertices GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0);/*from w w w. j av a 2 s. com*/ // Draw the vertices GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount); // Put everything back to default (deselect) GL20.glDisableVertexAttribArray(0); GL30.glBindVertexArray(0); Util.exitOnGLError("Error in Building render"); }
From source file:Data.Building.java
License:Apache License
@Override public void destroy() { // Disable the VBO index from the VAO attributes list GL20.glDisableVertexAttribArray(0);// w ww . j a v a2 s . com // Delete the VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboId); // Delete the VAO GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(vaoId); }
From source file:dataAccess.lwjgl.VAO_Loader.java
/** * Binds the VAO, so that it can be modified. * * @param vaoID The ID of the VAO that will be bound. *///www . jav a 2 s . c o m private static void bindVAO(int vaoID) { GL30.glBindVertexArray(vaoID); }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLMesh.java
License:Open Source License
public void use() { GL30.glBindVertexArray(vertexArrayObjectId); GL20.glEnableVertexAttribArray(0);//from w w w.j av a2 s . c o m if (hasNormals) GL20.glEnableVertexAttribArray(1); else GL20.glDisableVertexAttribArray(1); if (hasTexCoords) GL20.glEnableVertexAttribArray(2); else GL20.glDisableVertexAttribArray(2); }
From source file:de.ikosa.mars.viewer.glviewer.engine.GLMeshBuilder.java
License:Open Source License
protected GLMesh createMesh(GLResources resourceManager, boolean fetchMaterial) { // create VBO buffers FloatBuffer interleavedBuffer = BufferUtils.createFloatBuffer(vertices.size() * 8); int stride = 12 + (hasNormals ? 12 : 0) + (hasTexCoords ? 8 : 0); int normalPosition = 12; int texCoordPosition = 12 + (hasNormals ? 12 : 0); // fill buffers for (GLVertex vertex : vertices) { interleavedBuffer.put(vertex.px); interleavedBuffer.put(vertex.py); interleavedBuffer.put(vertex.pz); if (hasNormals) { interleavedBuffer.put(vertex.nx); interleavedBuffer.put(vertex.ny); interleavedBuffer.put(vertex.nz); }/*w w w .j a v a 2s . c o m*/ if (hasTexCoords) { interleavedBuffer.put(vertex.tu); interleavedBuffer.put(vertex.tv); } } interleavedBuffer.flip(); // create VAO int vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); // create VBOs int interleavedVboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, interleavedVboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, interleavedBuffer, GL15.GL_STATIC_DRAW); // position should always be there GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0); if (hasNormals) GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, normalPosition); if (hasTexCoords) GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, stride, texCoordPosition); // unbind buffers GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); // create mesh object GLMesh mesh = createInstance(vaoId, interleavedVboId); // create submeshes for material groups for (String material : indices.keySet()) { GLMaterial glMaterial = fetchMaterial ? resourceManager.getMaterial(material) : GLMaterial.nullMaterial; // create index buffer List<GLIndex> indicesForMaterial = indices.get(material); IntBuffer indexBuffer = BufferUtils.createIntBuffer(indicesForMaterial.size()); for (GLIndex index : indicesForMaterial) { indexBuffer.put(index.index); } indexBuffer.flip(); int indexVboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexVboId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL15.GL_STATIC_DRAW); GLSubMesh subMesh = new GLSubMesh(indexVboId, indicesForMaterial.size(), glMaterial, mesh); mesh.addSubMesh(subMesh); } GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); return mesh; }