Java Code Examples for org.lwjgl.opengl.GL15#glBindBuffer()

The following examples show how to use org.lwjgl.opengl.GL15#glBindBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GL33Helper.java    From ldparteditor with MIT License 7 votes vote down vote up
public static void drawLinesRGB_GeneralSlow(float[] vertices) {
    int VBO_general = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);

    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_LINES, 0, vertices.length);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 2
Source File: DesktopComputeJobManager.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
@Override
public JsonObject executeComputeShader() {
  GL20.glUseProgram(program);
  checkError();
  GL43.glDispatchCompute(numGroups[0], numGroups[1], numGroups[2]);
  checkError();
  GL42.glMemoryBarrier(GL43.GL_SHADER_STORAGE_BARRIER_BIT);
  checkError();
  GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject);
  checkError();
  final IntBuffer dataFromComputeShader = GL15.glMapBuffer(GL43.GL_SHADER_STORAGE_BUFFER, GL15.GL_READ_ONLY)
      .asIntBuffer();
  checkError();
  final JsonArray jsonArray = new JsonArray();
  for (int i = 0; i < dataFromComputeShader.limit(); i++) {
    jsonArray.add(dataFromComputeShader.get(i));
  }
  final JsonObject result = new JsonObject();
  result.add("output", jsonArray);
  return result;
}
 
Example 3
Source File: GL33HelperPrimitives.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTrianglesIndexedRGB_Triangle(float[] vertices, int[] indices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_triangle);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertices);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_triangle);
    GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, indices);
   
    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);
    
    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4
   
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    
    GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0);
}
 
Example 4
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Restore the old OpenGL state that's backed up in {@code state}.
 * @param state the old state to restore
 */
private void restoreRenderState(RenderState state) {
	GL11.glEnable(GL11.GL_BLEND);
	GL20.glUseProgram(state.oldProgram);
	GL11.glDisable(GL11.GL_TEXTURE_1D);
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, state.oldArrayBuffer);
	if (!state.depthWriteEnabled)
		GL11.glDepthMask(false);
	if (!state.depthEnabled)
		GL11.glDisable(GL11.GL_DEPTH_TEST);
	if (state.texEnabled)
		GL11.glEnable(GL11.GL_TEXTURE_2D);
	if (state.smoothedPoly)
		GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
	if (!state.blendEnabled)
		GL11.glDisable(GL11.GL_BLEND);
}
 
Example 5
Source File: GL33Helper.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTriangleVAO_GeneralSlow(float[] vertices) {
    int VAO_general = GL30.glGenVertexArrays();
    int VBO_general = GL15.glGenBuffers();
    GL30.glBindVertexArray(VAO_general);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, 12, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);

    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(VAO_general);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 6
Source File: GL33HelperPrimitives.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTrianglesIndexedRGB_Quad(float[] vertices, int[] indices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_quad);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0 , vertices);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_quad);
    GL15.glBufferSubData(GL15.GL_ELEMENT_ARRAY_BUFFER, 0, indices);
   
    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);
    
    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4
   
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    
    GL11.glDrawElements(GL11.GL_TRIANGLES, 12, GL11.GL_UNSIGNED_INT, 0);
}
 
Example 7
Source File: DesktopComputeJobManager.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
@Override
public void prepareEnvironment(JsonObject environmentJson) {
  final JsonObject bufferJson = environmentJson.get("buffer").getAsJsonObject();
  final int bufferBinding = bufferJson.get("binding").getAsInt();
  final int[] bufferInput = UniformSetter.getIntArray(bufferJson.get("input").getAsJsonArray());
  final IntBuffer intBufferData = BufferUtils.createIntBuffer(bufferInput.length);
  intBufferData.put(bufferInput);
  intBufferData.flip();
  shaderStorageBufferObject = GL15.glGenBuffers();
  checkError();
  GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, shaderStorageBufferObject);
  checkError();
  GL15.glBufferData(GL43.GL_SHADER_STORAGE_BUFFER, intBufferData, GL15.GL_STATIC_DRAW);
  checkError();
  GL30.glBindBufferBase(GL43.GL_SHADER_STORAGE_BUFFER, bufferBinding, shaderStorageBufferObject);
  checkError();
  numGroups = UniformSetter.getIntArray(environmentJson.get("num_groups").getAsJsonArray());
}
 
Example 8
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst)
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	if (pointsToRender == null) {
		for (int i = from * 2; i < to * 2 - 1; ++i) {
			if (spliceFrom <= i && i <= spliceTo)
				continue;
			GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	} else {
		Iterator<Integer> iter = pointsToRender.iterator();
		while (iter.hasNext()) {
			for (int i = iter.next() * 2, end = iter.next() * 2 - 1; i < end; ++i)
				GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 9
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public static void drawTriangle_GeneralSlow(float[] vertices) {
    int VBO_general = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, 12, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 10
Source File: Renderer.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void renderMesh(Mesh mesh) {
	GL30.glBindVertexArray(mesh.getVAO());
	GL30.glEnableVertexAttribArray(0);
	GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIBO());
	GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0);
	GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
	GL30.glDisableVertexAttribArray(0);
	GL30.glBindVertexArray(0);
}
 
Example 11
Source File: Mesh.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void create() {
	vao = GL30.glGenVertexArrays();
	GL30.glBindVertexArray(vao);
	
	FloatBuffer positionBuffer = MemoryUtil.memAllocFloat(vertices.length * 3);
	float[] positionData = new float[vertices.length * 3];
	for (int i = 0; i < vertices.length; i++) {
		positionData[i * 3] = vertices[i].getPosition().getX();
		positionData[i * 3 + 1] = vertices[i].getPosition().getY();
		positionData[i * 3 + 2] = vertices[i].getPosition().getZ();
	}
	positionBuffer.put(positionData).flip();
	
	pbo = GL15.glGenBuffers();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, pbo);
	GL15.glBufferData(GL15.GL_ARRAY_BUFFER, positionBuffer, GL15.GL_STATIC_DRAW);
	GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
	
	IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length);
	indicesBuffer.put(indices).flip();
	
	ibo = GL15.glGenBuffers();
	GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, ibo);
	GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
	GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}
 
Example 12
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 5 votes vote down vote up
private void destroyOpenGL() {  
    // Delete the texture
    GL11.glDeleteTextures(texIds[0]);
    GL11.glDeleteTextures(texIds[1]);
     
    // Delete the shaders
    GL20.glUseProgram(0);
    GL20.glDetachShader(pId, vsId);
    GL20.glDetachShader(pId, fsId);
     
    GL20.glDeleteShader(vsId);
    GL20.glDeleteShader(fsId);
    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);
     
    this.exitOnGLError("destroyOpenGL");
     
    Display.destroy();
}
 
Example 13
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
protected void bindGeometry(GeometryHandle geometry) {
	if(lastGeometry != geometry) {
		int id = 0;
		if (geometry != null) {
			id = geometry.getInternalId();
		}
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id);
		lastGeometry = geometry;
	}
}
 
Example 14
Source File: Vbo.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
public void unbind(){
	GL15.glBindBuffer(type, 0);
}
 
Example 15
Source File: Vbo.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
public void bind(){
	GL15.glBindBuffer(type, vboId);
}
 
Example 16
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 4 votes vote down vote up
private void setupQuad() {
    // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class
    TexturedVertex v0 = new TexturedVertex(); 
    v0.setXYZ(-0.5f, 0.5f, 0); v0.setRGB(1, 0, 0); v0.setST(0, 0);
    TexturedVertex v1 = new TexturedVertex(); 
    v1.setXYZ(-0.5f, -0.5f, 0); v1.setRGB(0, 1, 0); v1.setST(0, 1);
    TexturedVertex v2 = new TexturedVertex(); 
    v2.setXYZ(0.5f, -0.5f, 0); v2.setRGB(0, 0, 1); v2.setST(1, 1);
    TexturedVertex v3 = new TexturedVertex(); 
    v3.setXYZ(0.5f, 0.5f, 0); v3.setRGB(1, 1, 1); v3.setST(1, 0);
     
    TexturedVertex[] vertices = new TexturedVertex[] {v0, v1, v2, v3};
    // Put each 'Vertex' in one FloatBuffer
    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length *
            TexturedVertex.elementCount);
    for (int i = 0; i < vertices.length; i++) {
        // Add position, color and texture floats to the buffer
        verticesBuffer.put(vertices[i].getElements());
    }
    verticesBuffer.flip();  
    // OpenGL expects to draw vertices in counter clockwise order by default
    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, verticesBuffer, GL15.GL_STATIC_DRAW);
     
    // Put the position coordinates in attribute list 0
    GL20.glVertexAttribPointer(0, TexturedVertex.positionElementCount, GL11.GL_FLOAT, 
            false, TexturedVertex.stride, TexturedVertex.positionByteOffset);
    // Put the color components in attribute list 1
    GL20.glVertexAttribPointer(1, TexturedVertex.colorElementCount, GL11.GL_FLOAT, 
            false, TexturedVertex.stride, TexturedVertex.colorByteOffset);
    // Put the texture coordinates in attribute list 2
    GL20.glVertexAttribPointer(2, TexturedVertex.textureElementCount, GL11.GL_FLOAT, 
            false, TexturedVertex.stride, TexturedVertex.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);
     
    this.exitOnGLError("setupQuad");
}
 
Example 17
Source File: OpenGL3_TheQuadTextured.java    From ldparteditor with MIT License 4 votes vote down vote up
private void loopCycle() {
    // Logic
    while(Keyboard.next()) {
        // Only listen to events where the key was pressed (down event)
        if (!Keyboard.getEventKeyState()) continue;
         
        // Switch textures depending on the key released
        switch (Keyboard.getEventKey()) {
        case Keyboard.KEY_1:
            textureSelector = 0;
            break;
        case Keyboard.KEY_2:
            textureSelector = 1;
            break;
        }
    }
     
    // Render
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
     
    GL20.glUseProgram(pId);
     
    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texIds[textureSelector]);
     
    // 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);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
     
    GL20.glUseProgram(0);
     
    this.exitOnGLError("loopCycle");
}
 
Example 18
Source File: vboWithRGBA.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void init() {
    
    Matrix4f.setIdentity(viewport);
    shaderProgram = new GLShader("primitive.vert", "primitive.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    shaderProgram.use();
    
    GL11.glClearDepth(1.0f);
    GL11.glClearColor(View.primitive_background_Colour_r[0], View.primitive_background_Colour_g[0], View.primitive_background_Colour_b[0], 1.0f);
    
    // Set up vertex data (and buffer(s)) and attribute pointers
    float[] vertices = new float[]{
         0.5f,  0.5f, 0.0f,  // Top Right
         0.0f,  0.0f, 1.0f,  // Normal
         1.0f, 0.0f, 0.0f, 1.0f, // Colour
         
         0.5f, -0.5f, 0.0f,  // Bottom Right
         0.0f,  0.0f, 1.0f,  // Normal
         0.0f, 1.0f, 0.0f, 1.0f, // Colour
         
        -0.5f, -0.5f, 0.0f,  // Bottom Left
        0.0f,  0.0f, 1.0f,  // Normal
        0.0f, 0.0f, 1.0f, 1.0f, // Colour
    };
    
    VAO = GL30.glGenVertexArrays();
    VBO = GL15.glGenBuffers();
    // Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
    GL30.glBindVertexArray(VAO);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, 0);
    
    GL20.glEnableVertexAttribArray(NORMAL_SHADER_LOCATION);
    GL20.glVertexAttribPointer(NORMAL_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, 3 * 4);
    
    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 4, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, (3 + 3) * 4);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind

    GL30.glBindVertexArray(0); // Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs), remember: do NOT unbind the EBO, keep it bound to this VAO

}
 
Example 19
Source File: Vbo.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
public void bind(){
	GL15.glBindBuffer(type, vboId);
}
 
Example 20
Source File: GearGL33.java    From ldparteditor with MIT License 3 votes vote down vote up
public void draw(GLMatrixStack stack, GLShader shader, float x, float y, float z, float r, float g, float b) {
    
    final GLShader backup = stack.getShader();
    
    stack.setShader(shader);
    shader.use();
    
    stack.glPushMatrix();
    stack.glLoadIdentity();
    stack.glTranslatef(x, y, z);

    final int colour = shader.getUniformLocation("color"); //$NON-NLS-1$
    GL20.glUniform3f(colour, r, g, b);
    final int VBO = GL15.glGenBuffers();
    final int EBO = GL15.glGenBuffers();        
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, bvertices, GL15.GL_STREAM_DRAW);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, bindices, GL15.GL_STREAM_DRAW);
    
    GL20.glEnableVertexAttribArray(0);
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 12, 0);
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawElements(GL11.GL_TRIANGLES, bindices.capacity(), GL11.GL_UNSIGNED_INT, 0);

    GL15.glDeleteBuffers(VBO);
    GL15.glDeleteBuffers(EBO);

    stack.setShader(backup);
    backup.use();
    
    stack.glPopMatrix();
}