List of usage examples for org.lwjgl.opengl GL30 glGenVertexArrays
@NativeType("void") public static int glGenVertexArrays()
From source file:org.spout.engine.renderer.GL40BatchVertexRenderer.java
License:Open Source License
/** * Batch Renderer using OpenGL 4.0 mode. * * @param renderMode Mode to render in//from w w w.ja v a2s .c o m */ public GL40BatchVertexRenderer(int renderMode) { super(renderMode); vao = GL30.glGenVertexArrays(); SpoutRenderer.checkGLError(); }
From source file:org.spout.engine.renderer.GLBatchInstanceRenderer.java
License:Open Source License
/** * Batch Renderer using OpenGL 3.0 mode. * @param renderMode Mode to render in/* www.ja v a 2s . c om*/ */ public GLBatchInstanceRenderer(int renderMode) { super(renderMode); vao = GL30.glGenVertexArrays(); SpoutRenderer.checkGLError(); //Util.checkGLError(); //GL30.glBindVertexArray(vao); // useless //vertexBuffers.put(0, new VertexBufferImpl("vPosition", 4, 0)); //Auto create the first time }
From source file:ru.axialshift.vram.gl.VAOIncapsulator.java
License:Apache License
@Override protected void upload_gl() { glpointer = GL30.glGenVertexArrays(); GL30.glBindVertexArray(glpointer); vertexVBO.upload(); GL30.glBindVertexArray(0); indicesVBO.upload(); }
From source file:thebounzer.org.lwgldemo.Chapter3.java
License:Open Source License
@Override public void loopCycle() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL20.glUseProgram(program.getId());//from w w w. j a v a2s . c om vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); attributesBind(time += 0.01f); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3); GL20.glUseProgram(0); }
From source file:thebounzer.org.lwgldemo.Chapter5.java
License:Open Source License
@Override public void configure() { shaders.add(new GenericShader("src/main/resources/shadersCap5/shader.vert", GL20.GL_VERTEX_SHADER)); shaders.add(new GenericShader("src/main/resources/shadersCap5/shader.frag", GL20.GL_FRAGMENT_SHADER)); vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId);/*from w w w . ja va2s .c o m*/ GL11.glPointSize(5.0f); try { createAndBindVertexObject(vertex); } catch (IOException ex) { Logger.getLogger(Chapter5.class.getName()).log(Level.SEVERE, null, ex); } shaderSetup(); FloatBuffer matrixProjBuff = BufferUtils.createFloatBuffer(16); projMat.store(matrixProjBuff); matrixProjBuff.flip(); }
From source file:thebounzer.org.lwgldemo.Chapter5.java
License:Open Source License
@Override public void loopCycle() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); float f = (float) (time * Math.PI * 0.1f); Matrix4f modelViewM = new Matrix4f(); Matrix4f mat = new Matrix4f(); Matrix4f transOne = new Matrix4f(); Matrix4f transTwo = new Matrix4f(); Matrix4f rotaOne = new Matrix4f(); Matrix4f rotaTwo = new Matrix4f(); Matrix4f.translate(new Vector3f(0.0f, 0.0f, -0.4f), mat, transOne); Matrix4f.translate(new Vector3f((float) Math.sin(2.1f * f) * 0.5f, (float) Math.cos(1.7f * f) * 0.5f, (float) Math.sin(1.3f * f) * (float) Math.cos(1.5 * f) * 2.0f), mat, transTwo); Matrix4f.rotate(time * 45.0f, new Vector3f(0.0f, 1.0f, 0.0f), mat, rotaOne); Matrix4f.rotate(time * 81.0f, new Vector3f(1.0f, 0.0f, 0.0f), mat, rotaTwo); Matrix4f.mul(modelViewM, transOne, modelViewM); Matrix4f.mul(modelViewM, transTwo, modelViewM); Matrix4f.mul(modelViewM, rotaOne, modelViewM); Matrix4f.mul(modelViewM, rotaTwo, modelViewM); GL20.glUseProgram(program.getId());//from ww w .j av a2 s . c om FloatBuffer matrixBuf = BufferUtils.createFloatBuffer(16); modelViewM.store(matrixBuf); matrixBuf.flip(); int uniLoc = GL20.glGetUniformLocation(program.getId(), "mv_matrix"); GL20.glUniformMatrix4(uniLoc, false, matrixBuf); int uniProjMatLoc = GL20.glGetUniformLocation(program.getId(), "proj_matrix"); GL20.glUniformMatrix4(uniProjMatLoc, false, matrixBuf); vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); GL11.glDrawArrays(GL11.GL_POINTS, 0, 36); GL20.glUseProgram(0); time += 0.001f; }
From source file:tk.ivybits.engine.gl.GL.java
License:Open Source License
public static int glGenVertexArrays() { return GL30.glGenVertexArrays(); }
From source file:uk.co.ifs_studios.engine.geometry.BasicDrawElement.java
License:Open Source License
/** * Create new DrawElement./*from w w w . jav a 2s . c o m*/ */ public BasicDrawElement() { this.shader = new BasicShader(); this.matrixBuffer = BufferUtils.createFloatBuffer(16); this.vao = GL30.glGenVertexArrays(); this.vbo = GL15.glGenBuffers(); this.ibo = GL15.glGenBuffers(); this.cbo = GL15.glGenBuffers(); }
From source file:voxels.Mesh.java
License:Open Source License
private void createMesh() { // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class VertexData v0 = new VertexData(); v0.setXYZ(-0.5f, 0.5f, 0.5f);//from w w w.j a v a 2 s . co m v0.setRGB(1, 0, 0); v0.setST(0, 0); VertexData v1 = new VertexData(); v1.setXYZ(-0.5f, -0.5f, 0.5f); v1.setRGB(0, 1, 0); v1.setST(0, 1); VertexData v2 = new VertexData(); v2.setXYZ(0.5f, -0.5f, 0.5f); v2.setRGB(0, 0, 1); v2.setST(1, 1); VertexData v3 = new VertexData(); v3.setXYZ(0.5f, 0.5f, 0.5f); v3.setRGB(1, 1, 1); v3.setST(1, 0); VertexData v4 = new VertexData(); v4.setXYZ(-0.5f, 0.5f, -0.5f); v4.setRGB(1, 0, 0); v4.setST(0, 0); VertexData v5 = new VertexData(); v5.setXYZ(-0.5f, -0.5f, -0.5f); v5.setRGB(0, 1, 0); v5.setST(0, 1); VertexData v6 = new VertexData(); v6.setXYZ(-0.5f, -0.5f, 0.5f); v6.setRGB(0, 0, 1); v6.setST(1, 1); VertexData v7 = new VertexData(); v7.setXYZ(-0.5f, 0.5f, 0.5f); v7.setRGB(1, 1, 1); v7.setST(1, 0); VertexData v8 = new VertexData(); v8.setXYZ(-0.5f, 0.5f, -0.5f); v8.setRGB(1, 0, 0); v8.setST(0, 0); VertexData v9 = new VertexData(); v9.setXYZ(-0.5f, 0.5f, 0.5f); v9.setRGB(0, 1, 0); v9.setST(0, 1); VertexData v10 = new VertexData(); v10.setXYZ(0.5f, 0.5f, 0.5f); v10.setRGB(0, 0, 1); v10.setST(1, 1); VertexData v11 = new VertexData(); v11.setXYZ(0.5f, 0.5f, -0.5f); v11.setRGB(1, 1, 1); v11.setST(1, 0); VertexData v12 = new VertexData(); v12.setXYZ(0.5f, -0.5f, 0.5f); v12.setRGB(1, 0, 0); v12.setST(0, 0); VertexData v13 = new VertexData(); v13.setXYZ(-0.5f, -0.5f, 0.5f); v13.setRGB(0, 1, 0); v13.setST(0, 1); VertexData v14 = new VertexData(); v14.setXYZ(-0.5f, -0.5f, -0.5f); v14.setRGB(0, 0, 1); v14.setST(1, 1); VertexData v15 = new VertexData(); v15.setXYZ(0.5f, -0.5f, -0.5f); v15.setRGB(1, 1, 1); v15.setST(1, 0); VertexData v16 = new VertexData(); v16.setXYZ(0.5f, -0.5f, -0.5f); v16.setRGB(1, 0, 0); v16.setST(0, 0); VertexData v17 = new VertexData(); v17.setXYZ(-0.5f, -0.5f, -0.5f); v17.setRGB(0, 1, 0); v17.setST(0, 1); VertexData v18 = new VertexData(); v18.setXYZ(-0.5f, 0.5f, -0.5f); v18.setRGB(0, 0, 1); v18.setST(1, 1); VertexData v19 = new VertexData(); v19.setXYZ(0.5f, 0.5f, -0.5f); v19.setRGB(1, 1, 1); v19.setST(1, 0); VertexData v20 = new VertexData(); v20.setXYZ(0.5f, -0.5f, 0.5f); v20.setRGB(1, 0, 0); v20.setST(0, 0); VertexData v21 = new VertexData(); v21.setXYZ(0.5f, -0.5f, -0.5f); v21.setRGB(0, 1, 0); v21.setST(0, 1); VertexData v22 = new VertexData(); v22.setXYZ(0.5f, 0.5f, -0.5f); v22.setRGB(0, 0, 1); v22.setST(1, 1); VertexData v23 = new VertexData(); v23.setXYZ(0.5f, 0.5f, 0.5f); v23.setRGB(1, 1, 1); v23.setST(1, 0); vertices = new VertexData[] { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23 }; // Put each 'Vertex' in one FloatBuffer verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride); FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer(); for (VertexData vertice : vertices) { // Add position, color and texture floats to the buffer verticesFloatBuffer.put(vertice.getElements()); } verticesFloatBuffer.flip(); // OpenGL expects to draw vertices in counter clockwise order by default short[] indices = new short[6 * vertices.length / 4]; for (short i = 0; i < indices.length / 6; i++) { // 0, 1, 2, 2, 3, 0,4, 5 , 0, 5, 1, 0, 1, 5, 2, 5, 6, 2, 3, 0, 7, 0, 2, 7, 8, 6, 4, 6, 5, 4, 2, 3, 8, 3, 6, 8 indices[i * 6 + 0] = (short) (0 + 4 * i); indices[i * 6 + 1] = (short) (1 + 4 * i); indices[i * 6 + 2] = (short) (2 + 4 * i); indices[i * 6 + 3] = (short) (2 + 4 * i); indices[i * 6 + 4] = (short) (3 + 4 * i); indices[i * 6 + 5] = (short) (0 + 4 * i); } //indices = new byte[]{0, 1, 2, 2, 3, 0,4, 5 , 0, 5, 1, 0, 1, 5, 2, 5, 6, 2, 3, 0, 7, 0, 2, 7, 8, 6, 4, 6, 5, 4, 2, 3, 8, 3, 6, 8}; vertices = null; indicesCount = indices.length; ShortBuffer indicesBuffer = BufferUtils.createShortBuffer(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); }
From source file:wrath.client.graphics.Model.java
License:Open Source License
/** * Creates a 2D or 3D model from a list of verticies. * Models are always assumed to be made with triangles, and will be rendered as such. * @param name The {@link java.lang.String} name of the Model. * @param verticies The list of verticies in the model. One point is represented by (x, y, z), and there must be at least 3 points. * @param indicies The list of points to connect for OpenGL. Look up indicies in OpenGL for reference. * @param normals The list of 3 float vectors describing the normal vector of the model's surface. * @param useDefaultShaders If true, shaders will be set up automatically. * @return Returns the {@link wrath.client.graphics.Model} object of your model. *//*from w w w. j a v a 2 s . com*/ public static Model createModel(String name, float[] verticies, int[] indicies, float[] normals, boolean useDefaultShaders) { // Generating VAO int vaoid = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoid); // Generating Verticies VBO int vtvboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtvboid); FloatBuffer vbuffer = BufferUtils.createFloatBuffer(verticies.length); vbuffer.put(verticies); vbuffer.flip(); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(VERTICIES_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0); // Generating Normals VBO int nmvboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, nmvboid); FloatBuffer nbuffer = BufferUtils.createFloatBuffer(normals.length); nbuffer.put(normals); nbuffer.flip(); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, nbuffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(NORMALS_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0); // Generating Indicies VBO int invboid = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, invboid); IntBuffer ibuffer = BufferUtils.createIntBuffer(indicies.length); ibuffer.put(indicies); ibuffer.flip(); GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, ibuffer, GL15.GL_STATIC_DRAW); // Creating Model Object Model model; File mfile = new File("assets/models/" + name); if (!mfile.exists()) model = new Model(name, vaoid, new Integer[] { vtvboid, invboid, nmvboid }, verticies, indicies, normals, useDefaultShaders); else model = new Model(name, vaoid, new Integer[] { vtvboid, invboid, nmvboid }, null, null, null, useDefaultShaders); Game.getCurrentInstance().getLogger().println("Loaded model '" + name + "' with " + verticies.length + " verticies, " + indicies.length + " indicies, and " + normals.length + " normals."); if (useDefaultShaders) model.attachShader(ShaderProgram.DEFAULT_SHADER); // Unbinding OpenGL Objects GL30.glBindVertexArray(0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); Game.getCurrentInstance().addToTrashCleanup(model); Game.getCurrentInstance().addToRefreshList(model); return model; }