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

The following examples show how to use org.lwjgl.opengl.GL15#glBufferData() . 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: 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 3
Source File: VBORenderType.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Can be called runtime to have the Buffer rebuilt,
 * doing so has very limited applications and is not recommended.
 */
public void rebuild() {
    if (bufferId == -1) {
        bufferId = GL15.glGenBuffers();
    }

    BufferBuilder builder = new BufferBuilder(getBufferSize());
    builder.begin(getDrawMode(), getVertexFormat());
    factory.accept(getVertexFormat(), builder);
    builder.finishDrawing();
    Pair<BufferBuilder.DrawState, ByteBuffer> pair = builder.getNextBuffer();
    ByteBuffer buffer = pair.getSecond();
    count = buffer.remaining() / getVertexFormat().getSize();

    GL15.glBindBuffer(GL_ARRAY_BUFFER, bufferId);
    GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
    GL15.glBindBuffer(GL_ARRAY_BUFFER, 0);
}
 
Example 4
Source File: GL33Helper.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTrianglesIndexedRGB_GeneralSlow(float[] vertices, int[] indices) {
    int VBO_general = GL15.glGenBuffers();
    int EBO_general = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, 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.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0);

    GL15.glDeleteBuffers(VBO_general);
    GL15.glDeleteBuffers(EBO_general);
}
 
Example 5
Source File: GL33Helper.java    From ldparteditor with MIT License 6 votes vote down vote up
public void drawTrianglesIndexedRGB_General(float[] vertices, int[] indices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, 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.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0);
}
 
Example 6
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public GeometryHandle storeGeometry(float[] geometry, EGeometryFormatType type, boolean writable, String name) {
	GeometryHandle geometryBuffer = allocateVBO(type, name);

	bindGeometry(geometryBuffer);
	try(MemoryStack stack = MemoryStack.stackPush()) {
		ByteBuffer bfr = stack.malloc(4*geometry.length);
		bfr.asFloatBuffer().put(geometry);
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, bfr, writable ? GL15.GL_DYNAMIC_DRAW : GL15.GL_STATIC_DRAW);
		setObjectLabel(KHRDebug.GL_BUFFER, geometryBuffer.getInternalId(), name + "-vertices");
	}

	return geometryBuffer;
}
 
Example 7
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 8
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 9
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public static void drawTrianglesIndexedTextured_GeneralSlow(float[] vertices, int[] indices) {
    int VAO_general = GL30.glGenVertexArrays();
    int VBO_general = GL15.glGenBuffers();
    int EBO_general = GL15.glGenBuffers();
    GL30.glBindVertexArray(VAO_general);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_general);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);

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

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

    GL20.glEnableVertexAttribArray(TEX_COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(TEX_COLOUR_SHADER_LOCATION, 4, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 24);

    GL20.glEnableVertexAttribArray(UV_SHADER_LOCATION);
    GL20.glVertexAttribPointer(UV_SHADER_LOCATION, 2, GL11.GL_FLOAT, false, RGB_UV_STRIDE, 40);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawElements(GL11.GL_TRIANGLES, indices.length, GL11.GL_UNSIGNED_INT, 0);

    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(VAO_general);
    GL15.glDeleteBuffers(VBO_general);
    GL15.glDeleteBuffers(EBO_general);
}
 
Example 10
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public GeometryHandle generateGeometry(int vertices, EGeometryFormatType type, boolean writable, String name) {
	GeometryHandle vertexBufferId = allocateVBO(type, name);

	bindGeometry(vertexBufferId);
	GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices*type.getBytesPerVertexSize(), writable ? GL15.GL_DYNAMIC_DRAW : GL15.GL_STATIC_DRAW);
	setObjectLabel(KHRDebug.GL_BUFFER, vertexBufferId.getInternalId(), name + "-vertices");
	return vertexBufferId;
}
 
Example 11
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public void drawLinesRGB_General(float[] vertices) {
    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);
}
 
Example 12
Source File: GL33HelperPrimitives.java    From ldparteditor with MIT License 4 votes vote down vote up
public static void createVBO_PrimitiveArea() {
    VBO_triangle = GL15.glGenBuffers();
    EBO_triangle = GL15.glGenBuffers();
    VBO_quad = GL15.glGenBuffers();
    EBO_quad = GL15.glGenBuffers();
    VBO_line = GL15.glGenBuffers();
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_quad);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, new float[48], GL15.GL_DYNAMIC_DRAW);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_quad);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, new int[12], GL15.GL_DYNAMIC_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);
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_triangle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, new float[36], GL15.GL_DYNAMIC_DRAW);
    
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO_triangle);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, new int[6], GL15.GL_DYNAMIC_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);
    
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_line);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, new float[12], GL15.GL_DYNAMIC_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);
}
 
Example 13
Source File: LwjglGLExt.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void glBufferData(int target, IntBuffer data, int usage) {
    checkLimit(data);
    GL15.glBufferData(target, data, usage);
}
 
Example 14
Source File: BufferHelper.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void glBufferData(int target, ByteBuffer data, int usage) {
	GL15.glBufferData(target, data, usage);
}
 
Example 15
Source File: vboWithIndices.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);
    
    new Thread(new Runnable() {
        
        @Override
        public void run() {

            while (isRendering.get()) {
                
                final float zoom = cp.getZoom();
                final Matrix4f viewport_translation = cp.getTranslation();
                final float STEP = 22f * zoom * View.PIXEL_PER_LDU;
                cp.setRotationWidth(STEP);
                
                Matrix4f viewport_transform = new Matrix4f();
                Matrix4f.setIdentity(viewport_transform);
                Matrix4f.scale(new Vector3f(zoom, zoom, zoom), viewport_transform, viewport_transform);
                Matrix4f.mul(viewport_transform, viewport_translation, viewport_transform);
                cp.setViewport(viewport_transform);
                viewport = viewport_transform;
                
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
    
    
    // Set up vertex data (and buffer(s)) and attribute pointers
    float[] vertices = new float[]{
         0.5f,  0.5f, 0.0f,  // Top Right
         0.5f, -0.5f, 0.0f,  // Bottom Right
        -0.5f, -0.5f, 0.0f,  // Bottom Left
        -0.5f,  0.5f, 0.0f   // Top Left 
    };
    int[] indices = new int[]{  // Note that we start from 0!
        0, 1, 3,  // First Triangle
        1, 2, 3   // Second Triangle
    };
    
    VAO = GL30.glGenVertexArrays();
    VBO = GL15.glGenBuffers();
    EBO = 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);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);

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

    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 16
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 17
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 18
Source File: Vbo.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
public void storeData(FloatBuffer data){
	GL15.glBufferData(type, data, GL15.GL_STATIC_DRAW);
}
 
Example 19
Source File: Vbo.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
public void storeData(IntBuffer data){
	GL15.glBufferData(type, data, GL15.GL_STATIC_DRAW);
}
 
Example 20
Source File: Vbo.java    From LowPolyWater with The Unlicense 4 votes vote down vote up
public void allocateData(long sizeInBytes){
	GL15.glBufferData(type, sizeInBytes, usage);
}