List of usage examples for org.lwjgl.opengl ARBVertexBufferObject glGenBuffersARB
@NativeType("void") public static int glGenBuffersARB()
From source file:com.a2client.corex.MeshBuffer.java
License:Open Source License
public void load(Const.BUFFER_TYPE buffer_type, MyInputStream in) { try {/*from w w w .j av a2 s. c om*/ Count = in.readInt(); Stride = in.readInt(); int total = Count * Stride; byte[] bytes = new byte[total]; int readed = in.read(bytes); if (readed != total) { Log.error("MeshBuffer load wrong bytes, total=" + total + " readed=" + readed); return; } Data = ByteBuffer.allocateDirect(total); Data.put(bytes); Data.flip(); DataPtr = MemoryUtil.getAddress(Data); if (buffer_type == Const.BUFFER_TYPE.btIndex) { DType = ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB; RType = Const.RES_TYPE.rtMeshIdex; switch (Stride) { case 1: IndexType = GL11.GL_UNSIGNED_BYTE; break; case 2: IndexType = GL11.GL_UNSIGNED_SHORT; break; case 3: IndexType = GL11.GL_FALSE; break; case 4: IndexType = GL11.GL_UNSIGNED_INT; break; default: IndexType = GL11.GL_FALSE; } } else { DType = ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB; RType = Const.RES_TYPE.rtMeshVertex; } // ? ? VBO ID = ARBVertexBufferObject.glGenBuffersARB(); ARBVertexBufferObject.glBindBufferARB(DType, ID); ARBVertexBufferObject.glBufferDataARB(DType, Data, ARBBufferObject.GL_STATIC_DRAW_ARB); ResManager.Active.put(RType, this); // Data = null; } catch (IOException e) { e.printStackTrace(); } }
From source file:com.mitchellkember.mycraft.GameRenderer.java
License:Open Source License
/** * Creates the VBO that this GameRenderer will use. * //from w ww .j a va 2 s . c om * @throws LWJGLException if VBOs are not supported */ private void initializeData() throws LWJGLException { if (!GLContext.getCapabilities().GL_ARB_vertex_buffer_object) { Mycraft.LOGGER.log(Level.SEVERE, "GL_ARB_vertex_buffer_object not supported."); throw new LWJGLException("GL_ARB_vertex_buffer_object not supported"); } // Create it bufferObjectID = ARBVertexBufferObject.glGenBuffersARB(); // Vertex Data interleaved format: XYZST final int position = 3; final int texcoords = 2; final int sizeOfInt = 4; // 4 bytes in an int final int vertexDataSize = (position + texcoords) * sizeOfInt; // Bind it ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, bufferObjectID); // Vertex and texture pointers glVertexPointer(3, GL_INT, vertexDataSize, 0); glTexCoordPointer(2, GL_INT, vertexDataSize, position * sizeOfInt); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); }