List of usage examples for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER
int GL_ARRAY_BUFFER
To view the source code for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER.
Click Source Link
From source file:model.ModelMD2.java
@Override public void destroy() { //Delete VAO/* w w w .j a v a 2s . c o m*/ GL30.glBindVertexArray(vao_id); { for (int i = 0; i < 6; i++) { GL20.glDisableVertexAttribArray(i); } //Delete VBOs GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); for (int i = 0; i < frame_ids.length; i++) { GL15.glDeleteBuffers(frame_ids[i]); } } GL30.glBindVertexArray(0); GL30.glDeleteVertexArrays(vao_id); GL11.glDeleteTextures(tex_id); }
From source file:model.ModelMD2.java
@Override public void draw(float frame, float[] vpMatrix, float[] matrix, RenderEngine engine) { if (frame < 0 || frame > header.num_frames - 1) return;/* w ww . j a v a2s. co m*/ //Select current frame and next int frame_0 = frame_ids[(int) Math.floor(frame)]; int frame_1 = frame_ids[(int) Math.min(Math.ceil(frame), header.num_frames - 1)]; //Upload frame interpolation GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_id); ShaderUtils.useProgram(shader_id); { //Upload uniform values ShaderUtils.setUniformMatrix4(shader_id, "viewprojMatrix", vpMatrix); ShaderUtils.setUniformMatrix4(shader_id, "modelMatrix", matrix); ShaderUtils.setUniformVar(shader_id, "frame_interpolated", (float) (frame - Math.floor(frame))); //ShaderUtils.setUniformVar(shader_id, "cameraDir", engine.camera.yaw, engine.camera.pitch, engine.camera.roll); //Bind frames to VAO GL30.glBindVertexArray(vao_id); { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_0);//Bind frame 0 { GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 32, 0); GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 32, 12); GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 32, 20); } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_1);//Bind frame 1 { GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, 32, 0); GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, 32, 12); GL20.glVertexAttribPointer(5, 3, GL11.GL_FLOAT, false, 32, 20); } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); //Enable attribs and render for (int i = 0; i < 6; i++) { GL20.glEnableVertexAttribArray(i); } { GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, header.num_tris * 3); } for (int i = 0; i < 6; i++) { GL20.glDisableVertexAttribArray(i); } } GL30.glBindVertexArray(0); } ShaderUtils.useProgram(0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
From source file:model.ModelMD2.java
public void compileVBO() { frame_ids = new int[header.num_frames]; ArrayList<float[]> data = new ArrayList<float[]>(); for (int currentFrame = 0; currentFrame < header.num_frames; currentFrame++) { MD2_Frame frame = frames[currentFrame];// Current frame for (int currentTriangle = 0; currentTriangle < header.num_tris; currentTriangle++) { for (int j = 0; j < 3; j++) { float[] temp = new float[8]; //Extract position from vertex array using triangles vertex index MD2_Vertex vertex = frame.vertices[triangles[currentTriangle].vertexIndex[j]]; //For MD2 format/exporter Z is up, swap Z and Y for OGL temp[0] = vertex.v[1];//w w w. ja v a 2 s . c o m temp[1] = vertex.v[2]; temp[2] = vertex.v[0]; //Extract texture coords from st array using triangle texture index float s = (float) (textureCoords[triangles[currentTriangle].textureIndex[j]].s / 256f); float t = (float) (textureCoords[triangles[currentTriangle].textureIndex[j]].t / 256f); temp[3] = s; temp[4] = t; //Normals, why hardcoded? int index = frame.vertices[triangles[currentTriangle].vertexIndex[j]].lightNormalIndex; //Some models seems to use a different normal array and doesn't work with Quake II normals if (index < normals.length) { float[] n = normals[index]; temp[5] = n[0]; temp[6] = n[2]; temp[7] = n[1]; } data.add(temp);//Add vertex data } } //Put data into floatbuffer ByteBuffer verticesByteBuffer = BufferUtils.createByteBuffer(data.size() * 32); FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer(); for (int i = 0; i < data.size(); i++) { // Add position, normal and texture floats to the buffer verticesFloatBuffer.put(data.get(i)); } verticesFloatBuffer.flip(); //Put data into its vbo int id = GL15.glGenBuffers(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id); { GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesFloatBuffer, GL15.GL_STATIC_DRAW); } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); //Clear data for next frame data.clear(); //Save frame id frame_ids[currentFrame] = id; } GLUtil.cerror(getClass().getName() + " compileVBO"); }
From source file:net.kubin.rendering.ChunkMeshBuilder.java
License:Apache License
public static void generateChunkMesh(Chunk chunk, MeshType meshType) { if (DEBUG) {// w w w.j a va 2 s . c om System.out.println("Building " + meshType.name() + " Mesh for " + chunk.toString() + "..."); } /* Make sure there are no list edits anymore */ chunk.performListChanges(); ChunkMesh mesh = chunk.getMesh(); mesh.destroy(meshType); /* Compute vertex count */ int vertexCount = chunk.getVertexCount(meshType); if (DEBUG) { System.out.println("\tVertex Count = " + vertexCount); } /* * If there are no faces visible yet (because of generating busy), don't * create a buffer */ if (vertexCount == 0) { return; } mesh.setVertexCount(meshType, vertexCount); /* Create a buffer */ int vbo = BufferManager.getInstance().createBuffer(); mesh.setVBO(meshType, vbo); /* Bind the buffer */ GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo); /* Allocate size for the buffer */ int size = vertexCount * STRIDE * FLOAT_SIZE; GL15.glBufferData(GL15.GL_ARRAY_BUFFER, size, GL15.GL_STATIC_DRAW); if (DEBUG) { System.out.println( "\tCreate VBO: " + vbo + " with size = " + size + " (ERROR: " + GL11.glGetError() + ")"); } /* Get the native buffer to write to */ ByteBuffer byteBuffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY, size, null); if (byteBuffer == null) { System.out.println("\tCouldn't create a native VBO!: GL Error Code = " + GL11.glGetError()); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); mesh.destroy(meshType); Thread.dumpStack(); mesh.setVBO(meshType, -1); mesh.setVertexCount(meshType, 0); return; } FloatBuffer vertexBuffer = byteBuffer.asFloatBuffer(); /* Store all vertices in the buffer */ USED_SIZE = 0; /* Local temporary variables, used to speed up */ IntList blockList = chunk.getVisibleBlocks(); int blockIndex = -1; byte BlockDef = 0; boolean special = false; Vec3i vec = new Vec3i(); BlockDef type; Block block = null; LightBuffer lightBuffer = chunk.getLightBuffer(); byte faceMask = 0; /* Iterate over the blocks */ for (int i = 0; i < blockList.size(); ++i) { blockIndex = blockList.get(i); BlockDef = chunk.getChunkData().getBlockDef(blockIndex); if (BlockDef == 0) { continue; } special = chunk.getChunkData().isSpecial(blockIndex); type = _blockManager.getBlockDef(BlockDef); if ((meshType == MeshType.OPAQUE && !type.isTranslucent() && type.hasNormalAABB()) || (meshType == MeshType.TRANSLUCENT && (type.isTranslucent() || !type.hasNormalAABB()))) { ChunkData.indexToPosition(blockIndex, vec); /* Build the light buffer */ vec.setX(vec.x() + chunk.getAbsoluteX()); vec.setZ(vec.z() + chunk.getAbsoluteZ()); lightBuffer.setReferencePoint(vec.x(), vec.y(), vec.z()); if (special) { block = chunk.getChunkData().getSpecialBlock(blockIndex); if (block.isVisible()) { block.storeInVBO(vertexBuffer, lightBuffer); } } else { faceMask = chunk.getChunkData().getFaceMask(blockIndex); type.getDefaultBlockBrush().setFaceMask(faceMask); type.getBrush().storeInVBO(vertexBuffer, vec.x() + 0.5f, vec.y() + 0.5f, vec.z() + 0.5f, lightBuffer); } } } /* Perform a check */ if (USED_SIZE != STRIDE * FLOAT_SIZE * mesh.getVertexCount(meshType)) { System.out.println("\t[WARNING!]: Used size = " + USED_SIZE); System.out.println("\t[WARNING!]: Vertex count = " + USED_SIZE / STRIDE / FLOAT_SIZE); mesh.setVertexCount(meshType, USED_SIZE / STRIDE / FLOAT_SIZE); } byteBuffer.flip(); GL15.glUnmapBuffer(GL15.GL_ARRAY_BUFFER); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); }
From source file:net.neilcsmith.praxis.video.opengl.internal.VertexBufferObject.java
License:Apache License
/** {@inheritDoc} */ public void setVertices(float[] vertices, int offset, int count) { isDirty = true;//w w w.j ava 2 s .com if (isDirect) { // BufferUtils.copy(vertices, byteBuffer, count, offset); buffer.clear(); buffer.put(vertices, offset, count); buffer.position(0); buffer.limit(count); } else { buffer.clear(); buffer.put(vertices, offset, count); buffer.flip(); byteBuffer.position(0); byteBuffer.limit(buffer.limit() << 2); } if (isBound) { GL15.glBufferData(GL15.GL_ARRAY_BUFFER, byteBuffer, usage); isDirty = false; } }
From source file:net.neilcsmith.praxis.video.opengl.internal.VertexBufferObject.java
License:Apache License
/** Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements * //from w w w. java 2s.c o m * @param shader the shader */ public void bind(ShaderProgram shader) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferHandle); if (isDirty) { byteBuffer.limit(buffer.limit() * 4); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, byteBuffer, usage); isDirty = false; } int numAttributes = attributes.size(); for (int i = 0; i < numAttributes; i++) { VertexAttribute attribute = attributes.get(i); shader.enableVertexAttribute(attribute.alias); int colorType = GL11.GL_FLOAT; boolean normalize = false; if (attribute.usage == VertexAttributes.Usage.ColorPacked) { colorType = GL11.GL_UNSIGNED_BYTE; normalize = true; } shader.setVertexAttribute(attribute.alias, attribute.numComponents, colorType, normalize, attributes.vertexSize, attribute.offset); } isBound = true; }
From source file:net.neilcsmith.praxis.video.opengl.internal.VertexBufferObject.java
License:Apache License
/** Unbinds this VertexBufferObject. * //w w w . j a v a 2 s . c o m * @param shader the shader */ public void unbind(ShaderProgram shader) { int numAttributes = attributes.size(); for (int i = 0; i < numAttributes; i++) { VertexAttribute attribute = attributes.get(i); shader.disableVertexAttribute(attribute.alias); } GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); isBound = false; }
From source file:net.neilcsmith.praxis.video.opengl.internal.VertexBufferObject.java
License:Apache License
/** Disposes of all resources this VertexBufferObject uses. */ public void dispose() { tmpHandle.clear();//from w w w . ja v a2 s . c o m tmpHandle.put(bufferHandle); tmpHandle.flip(); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); GL15.glDeleteBuffers(tmpHandle); bufferHandle = 0; }
From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java
License:Apache License
public void bindColors(int vboID, int size, int type, int strideBytes, int offsetBytes) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); GL11.glColorPointer(size, type, strideBytes, offsetBytes); }
From source file:net.smert.frameworkgl.opengl.helpers.VertexBufferObjectHelper.java
License:Apache License
public void bindNormals(int vboID, int type, int strideBytes, int offsetBytes) { GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); GL11.glNormalPointer(type, strideBytes, offsetBytes); }