List of usage examples for org.lwjgl.opengl GL30 glBindVertexArray
public static void glBindVertexArray(@NativeType("GLuint") int array)
From source file:main.EntityRenderer.java
private void unbindTextureModel() { GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); }
From source file:main.java.com.YeAJG.game.entity.Entity.java
License:Open Source License
private void SetupEntity(Vector3f[] vertex, Vector3f[] color, Vector2f[] uv) { // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class vertices = new VertexData[vertex.length]; for (int i = 0; i < vertex.length; i++) { vertices[i] = new VertexData(); vertices[i].setXYZ(vertex[i].x, vertex[i].y, vertex[i].z); vertices[i].setRGBA(color[i].x, color[i].y, color[i].z, 1.0f); vertices[i].setST(uv[i].x, uv[i].y); }//from ww w. j a v a 2 s. c om // Put each 'Vertex' in one FloatBuffer verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride); FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer(); for (int i = 0; i < vertices.length; i++) { // Add position, color and texture floats to the buffer verticesFloatBuffer.put(vertices[i].getElements()); } verticesFloatBuffer.flip(); // OpenGL expects to draw vertices in counter clockwise order by default // TODO: Move this to Setup. byte[] indices = { 0, 1, 2, 2, 3, 0 }; indicesCount = indices.length; ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); indicesBuffer.put(indices); indicesBuffer.flip(); // Create a new Vertex Array Object in memory and select it (bind) vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); // Create a new Vertex Buffer Object in memory and select it (bind) vboId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STREAM_DRAW); // Put the position coordinates in attribute list 0 GL20.glVertexAttribPointer(0, VertexData.positionElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.positionByteOffset); // Put the color components in attribute list 1 GL20.glVertexAttribPointer(1, VertexData.colorElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.colorByteOffset); // Put the texture coordinates in attribute list 2 GL20.glVertexAttribPointer(2, VertexData.textureElementCount, GL11.GL_FLOAT, false, VertexData.stride, VertexData.textureByteOffset); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Deselect (bind to 0) the VAO GL30.glBindVertexArray(0); // Create a new VBO for the indices and select it (bind) - INDICES vboiId = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); Game.cameraPos = new Vector3f(0, 0, -1); Game.exitOnGLError("setupQuad"); }
From source file:main.java.com.YeAJG.game.entity.Entity.java
License:Open Source License
@Override public void Render(float interpolation) { GL20.glUseProgram(pId);//ww w . j a v a 2 s . c o m // 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 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); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); GL20.glUseProgram(0); Game.exitOnGLError("renderCycle"); }
From source file:main.java.com.YeAJG.game.entity.Entity.java
License:Open Source License
public void destroy() { // Delete the Program GL20.glUseProgram(0);//w w w . ja v a2 s . c o m GL20.glDeleteProgram(pId); // Select the VAO GL30.glBindVertexArray(vaoId); // Disable the VBO index from the VAO attributes list GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); // Delete the vertex VBO GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboId); // Delete the index VBO GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(vboiId); // Delete the VAO GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(vaoId); }
From source file:main.Loader.java
private int createVAO() { int vaoID = GL30.glGenVertexArrays(); vaos.add(vaoID); GL30.glBindVertexArray(vaoID); return vaoID; }
From source file:main.TerrainRenderer.java
private void prepareTerrain(Terrain terrain) { RawModel rawModel = terrain.getModel(); GL30.glBindVertexArray(rawModel.getVaoId()); GL20.glEnableVertexAttribArray(0);/*from www.ja va 2 s . c o m*/ GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); ModelTexture texture = terrain.getTexture(); shader.loadShineVariables(texture.getShineDamper(), texture.getReflectivity()); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId()); }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
public void resizeBuffer() { vertByteBuff = BufferUtils.createByteBuffer(vertexCount * Vertex.stride); ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount); FloatBuffer vertFloatBuff = vertByteBuff.asFloatBuffer(); for (Drawable object : objects) { object.store(vertFloatBuff);//w ww. j ava 2 s.co m indicesBuffer.put(object.getIndices()); } for (Drawable object : orthoObjects) { object.store(vertFloatBuff); indicesBuffer.put(object.getIndices()); } indicesBuffer.flip(); vertFloatBuff.flip(); GL30.glBindVertexArray(vaoId); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertFloatBuff, GL15.GL_STREAM_DRAW); GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, Vertex.stride, 0); GL20.glVertexAttribPointer(1, 4, GL11.GL_FLOAT, false, Vertex.stride, 16); GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, Vertex.stride, 32); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL30.glBindVertexArray(0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); }
From source file:me.sunchiro.game.engine.gl.Graphic.java
License:Open Source License
private synchronized void render() { GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL20.glUseProgram(shader.getPID());/* w ww. j a v a2 s .c om*/ // GL13.glActiveTexture(GL13.GL_TEXTURE0); GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid)); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); long offset = 0; int shift = 0; GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); for (Drawable object : objects) { Matrix4f finalMVP = new Matrix4f(mvpMat); Matrix4f modelMat = new Matrix4f(); Matrix4f scaler = new Matrix4f(); scaler.scale(object.scale * allScale); modelMat.translate(object.translation); modelMat.rotateXYZ(object.rotation.x, object.rotation.y, object.rotation.z); finalMVP.mul(modelMat); finalMVP.mul(scaler); finalMVP.get(0, matBuff); if (object.isChar) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap)); } GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff); GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0); if (object.isVisible()) GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE, offset, shift); offset += object.getIndices().length; shift += object.getVertex().length; if (object.isChar) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid)); } } render2d(offset, shift); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); // GL20.glUseProgram(0); glfwSwapBuffers(window); glfwPollEvents(); }
From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30VertexArray.java
License:Open Source License
@Override public void addAttribute(int index, int size, TFloatList data) { ensureCreated("VertexArray must be created to add an attribute."); if (index > GL11.glGetInteger(GL_MAX_VERTEX_ATTRIBS)) { throw new IllegalArgumentException("Vertex attribute index exceeds maximum vertex attribute index."); }// w ww .j av a 2 s .c o m // Put the indices into an FloatBuffer final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size()); data.forEach((float f) -> { buffer.put(f); return true; }); buffer.flip(); // Bind the VAO GL30.glBindVertexArray(vao); // Generate and bind the attribute buffer final int id = GL15.glGenBuffers(); GL15.glBindBuffer(GL_ARRAY_BUFFER, id); // Set the attribute data GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW); // Enable the vertex attribute GL20.glEnableVertexAttribArray(index); // Set the vertex attribute settings GL20.glVertexAttribPointer(index, size, DataType.FLOAT.getGLConstant(), false, 0, 0L); // Disable the vertex attribute GL20.glDisableVertexAttribArray(index); // Unbind the attribute buffer GL15.glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind the VAO GL30.glBindVertexArray(vao); // Add the buffer id to the attributes list this.attributes.insert(index, id); // Check for errors RenderUtil.checkGLError(); }
From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30VertexArray.java
License:Open Source License
@Override public void draw() { ensureCreated("VertexArray must be created to draw."); //Bind the vertex array object GL30.glBindVertexArray(vao); // Enable the vertex attributes for (int i = 0; i < attributes.size(); ++i) { GL20.glEnableVertexAttribArray(i); }//from w ww. j a va 2 s .com // Bind the index buffer GL15.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); // Draw the vertex elements GL11.glDrawElements(GL_TRIANGLES, drawCount, DataType.UNSIGNED_INT.getGLConstant(), 0L); // Unbind the index buffer GL15.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Disable the vertex attributes for (int i = 0; i < attributes.size(); ++i) { GL20.glDisableVertexAttribArray(i); } // Unbind the vertex array object GL30.glBindVertexArray(0); }