Example usage for org.lwjgl.opengl GL15 glGenBuffers

List of usage examples for org.lwjgl.opengl GL15 glGenBuffers

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL15 glGenBuffers.

Prototype

@NativeType("void")
public static int glGenBuffers() 

Source Link

Document

Generates buffer object names.

Usage

From source file:de.ikosa.mars.viewer.glviewer.engine.GLMeshBuilder.java

License:Open Source License

protected GLMesh createMesh(GLResources resourceManager, boolean fetchMaterial) {
    // create VBO buffers
    FloatBuffer interleavedBuffer = BufferUtils.createFloatBuffer(vertices.size() * 8);
    int stride = 12 + (hasNormals ? 12 : 0) + (hasTexCoords ? 8 : 0);
    int normalPosition = 12;
    int texCoordPosition = 12 + (hasNormals ? 12 : 0);

    // fill buffers
    for (GLVertex vertex : vertices) {
        interleavedBuffer.put(vertex.px);
        interleavedBuffer.put(vertex.py);
        interleavedBuffer.put(vertex.pz);
        if (hasNormals) {
            interleavedBuffer.put(vertex.nx);
            interleavedBuffer.put(vertex.ny);
            interleavedBuffer.put(vertex.nz);
        }/*  w w  w . ja va2  s  .c  o  m*/
        if (hasTexCoords) {
            interleavedBuffer.put(vertex.tu);
            interleavedBuffer.put(vertex.tv);
        }
    }

    interleavedBuffer.flip();

    // create VAO
    int vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // create VBOs
    int interleavedVboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, interleavedVboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, interleavedBuffer, GL15.GL_STATIC_DRAW);

    // position should always be there
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0);
    if (hasNormals)
        GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, normalPosition);
    if (hasTexCoords)
        GL20.glVertexAttribPointer(2, 2, GL11.GL_FLOAT, false, stride, texCoordPosition);

    // unbind buffers
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

    // create mesh object
    GLMesh mesh = createInstance(vaoId, interleavedVboId);

    // create submeshes for material groups

    for (String material : indices.keySet()) {
        GLMaterial glMaterial = fetchMaterial ? resourceManager.getMaterial(material) : GLMaterial.nullMaterial;
        // create index buffer
        List<GLIndex> indicesForMaterial = indices.get(material);
        IntBuffer indexBuffer = BufferUtils.createIntBuffer(indicesForMaterial.size());

        for (GLIndex index : indicesForMaterial) {
            indexBuffer.put(index.index);
        }
        indexBuffer.flip();

        int indexVboId = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexVboId);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL15.GL_STATIC_DRAW);

        GLSubMesh subMesh = new GLSubMesh(indexVboId, indicesForMaterial.size(), glMaterial, mesh);
        mesh.addSubMesh(subMesh);

    }

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    return mesh;
}

From source file:de.ikosa.mars.viewer.glviewer.GLHeightMapMeshBuilder.java

License:Open Source License

public GLHeightMapMesh createMesh() {
    ML.d(String.format("Writing mesh \"%s\" to buffer...", name));
    // create VBO buffers
    FloatBuffer interleavedBuffer = BufferUtils.createFloatBuffer(matrixSizeX * matrixSizeY * 9);
    int stride = 12 + 12 + 12;
    int normalPosition = 12;
    int texCoordPosition = 24;

    // fill buffers
    for (int y = 0; y < matrixSizeY; y++) {
        for (int x = 0; x < matrixSizeX; x++) {
            GLWorldVertex vertex = vMatrix[x][y];
            interleavedBuffer.put(vertex.px);
            interleavedBuffer.put(vertex.py);
            interleavedBuffer.put(vertex.pz);
            interleavedBuffer.put(vertex.nx);
            interleavedBuffer.put(vertex.ny);
            interleavedBuffer.put(vertex.nz);
            interleavedBuffer.put(vertex.tu);
            interleavedBuffer.put(vertex.tv);
            interleavedBuffer.put(vertex.tw);
        }/*from  ww w .  j a  va  2s  .  co m*/
    }

    interleavedBuffer.flip();

    ML.d("Done.");

    // create VAO
    int vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // create VBOs
    int interleavedVboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, interleavedVboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, interleavedBuffer, GL15.GL_STATIC_DRAW);

    // attribs
    GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, stride, 0);
    GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, stride, normalPosition);
    GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, stride, texCoordPosition);

    // unbind buffers
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

    // create index buffer
    iBuffer.flip();

    int indexVboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexVboId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, iBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

    GLTextureArray terrainTexture = (GLTextureArray) GLResources.global.getTexture("terrain");

    // create mesh object
    GLHeightMapMesh mesh = new GLHeightMapMesh(name, vaoId, interleavedVboId, indexVboId, indices,
            terrainTexture);
    return mesh;
}

From source file:engine.render.TexturedQuad.java

private void setupQuad(Vector2f size) {
    TexturedVertex v0 = new TexturedVertex();
    v0.setXYZ(-0.5f * size.x, 0.5f * size.y, 0);
    v0.setRGB(1, 0, 0);//from  w  w  w  .j a  va2s .  co m
    v0.setST(0, 0);
    TexturedVertex v1 = new TexturedVertex();
    v1.setXYZ(-0.5f * size.x, -0.5f * size.x, 0);
    v1.setRGB(0, 1, 0);
    v1.setST(0, 1);
    TexturedVertex v2 = new TexturedVertex();
    v2.setXYZ(0.5f * size.y, -0.5f * size.x, 0);
    v2.setRGB(0, 0, 1);
    v2.setST(1, 1);
    TexturedVertex v3 = new TexturedVertex();
    v3.setXYZ(0.5f * size.x, 0.5f * size.y, 0);
    v3.setRGB(1, 1, 1);
    v3.setST(1, 0);

    TexturedVertex[] vertices = new TexturedVertex[] { v0, v1, v2, v3 };

    FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length * TexturedVertex.elementCount);
    for (int i = 0; i < vertices.length; i++) {

        verticesBuffer.put(vertices[i].getElements());
    }
    verticesBuffer.flip();

    byte[] indices = { 0, 1, 2, 2, 3, 0 };
    indicesCount = indices.length;
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
    indicesBuffer.put(indices);
    indicesBuffer.flip();

    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);

    GL20.glVertexAttribPointer(0, TexturedVertex.positionElementCount, GL11.GL_FLOAT, false,
            TexturedVertex.stride, TexturedVertex.positionByteOffset);

    GL20.glVertexAttribPointer(1, TexturedVertex.colorElementCount, GL11.GL_FLOAT, false, TexturedVertex.stride,
            TexturedVertex.colorByteOffset);

    GL20.glVertexAttribPointer(2, TexturedVertex.textureElementCount, GL11.GL_FLOAT, false,
            TexturedVertex.stride, TexturedVertex.textureByteOffset);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL30.glBindVertexArray(0);

    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");
}

From source file:eu.over9000.veya.rendering.ChunkVAO.java

License:Open Source License

public void create() {
    // create objects

    if (holdsSolid) {
        this.ibo_handle_solid = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_solid);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_buffer_solid, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        this.vbo_handle_solid = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_solid);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, this.vbo_buffer_solid, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        this.vao_handle_solid = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(this.vao_handle_solid);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_solid);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.positionByteOffset);

        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.colorByteCount);//w  w  w  . jav a 2  s.c  om

        GL20.glEnableVertexAttribArray(2);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.textureByteOffset);

        GL20.glEnableVertexAttribArray(3);
        GL20.glVertexAttribPointer(3, Vertex.normalElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.normalByteOffset);

        GL20.glEnableVertexAttribArray(4);
        GL20.glVertexAttribPointer(4, Vertex.aoElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.aoByteOffset);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_solid);

        GL30.glBindVertexArray(0);
    }

    if (holdsTransparent) {
        this.ibo_handle_transparent = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_transparent);
        GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_buffer_transparent, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

        this.vbo_handle_transparent = GL15.glGenBuffers();
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_transparent);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, this.vbo_buffer_transparent, GL15.GL_STATIC_DRAW);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

        this.vao_handle_transparent = GL30.glGenVertexArrays();
        GL30.glBindVertexArray(this.vao_handle_transparent);

        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo_handle_transparent);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, Vertex.positionElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.positionByteOffset);

        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, Vertex.colorElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.colorByteOffset);

        GL20.glEnableVertexAttribArray(2);
        GL20.glVertexAttribPointer(2, Vertex.textureElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.textureByteOffset);

        GL20.glEnableVertexAttribArray(3);
        GL20.glVertexAttribPointer(3, Vertex.normalElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.normalByteOffset);

        GL20.glEnableVertexAttribArray(4);
        GL20.glVertexAttribPointer(4, Vertex.aoElementCount, GL11.GL_FLOAT, false, Vertex.stride,
                Vertex.aoByteOffset);

        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ibo_handle_transparent);

        GL30.glBindVertexArray(0);
    }

    // System.out.println("created ChunkVAO with " + this.vertexData.length + " vertices");
}

From source file:eu.over9000.veya.rendering.Shadow.java

License:Open Source License

public void renderQuad() {
    if (quadVAO == 0) {
        final float[] quadVertices = {
                // Positions        // Texture Coords
                -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
                1.0f, -1.0f, 0.0f, 1.0f, 0.0f, };
        // Setup plane VAO

        final FloatBuffer fb = BufferUtils.createFloatBuffer(quadVertices.length);

        fb.put(quadVertices);// w w  w  . j  a v a 2s .  co m
        fb.flip();

        quadVAO = GL30.glGenVertexArrays();
        quadVBO = GL15.glGenBuffers();
        GL30.glBindVertexArray(quadVAO);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, quadVBO);
        GL15.glBufferData(GL15.GL_ARRAY_BUFFER, fb, GL15.GL_STATIC_DRAW);
        GL20.glEnableVertexAttribArray(0);
        GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 5 * Float.BYTES, 0);
        GL20.glEnableVertexAttribArray(1);
        GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 5 * Float.BYTES, 3 * Float.BYTES);
    }
    GL30.glBindVertexArray(quadVAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, 4);
    GL30.glBindVertexArray(0);
}

From source file:fr.guillaume.prive.viper.core.graphic.GraphicMotor.java

private static void setupObjModels() {
    ObjModel spaceShipModel = ObjLoader.loadModel(new File("resources/model/fighter.obj"));
    FloatBuffer verticesBuffer = BufferUtils
            .createFloatBuffer(Vertex.ELEMENT_COUNT * spaceShipModel.getVertices().size());
    spaceShipModel.getVertices().stream().forEach((v) -> verticesBuffer.put(v.getElements()));
    verticesBuffer.flip();/*from w  w  w.j a v  a 2  s.c  om*/

    instance.shipVaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(instance.shipVaoId);
    instance.shipVboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, instance.shipVboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(0, Vertex.POSITION_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE, 0);
    GL20.glVertexAttribPointer(1, Vertex.NORMAL_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE,
            Vertex.NORMAL_BYTE_OFFSET);
    GL20.glVertexAttribPointer(2, Vertex.COLOR_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE,
            Vertex.COLOR_BYTE_OFFSET);
    GL20.glVertexAttribPointer(3, Vertex.TEXTURE_ELEMENT_COUNT, GL11.GL_FLOAT, false, Vertex.STRIDE,
            Vertex.TEXTURE_BYTE_OFFSET);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL30.glBindVertexArray(0);

    instance.shipVboiLenght = spaceShipModel.getIndices().length;
    IntBuffer indicesBuffer = BufferUtils.createIntBuffer(instance.shipVboiLenght);
    indicesBuffer.put(spaceShipModel.getIndices());
    indicesBuffer.flip();
    instance.shipVboiId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, instance.shipVboiId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
}

From source file:game.level.map.TileMapGenerator.java

License:Open Source License

public static int[] CreateTemplateMesh(int startX, int startY, float startZ, int WIDTH, int HEIGHT,
        MapTile[][] tiles) {//from w  w  w . j  a v  a 2  s.c o m
    long startTime;
    long endTime;
    startTime = System.currentTimeMillis();
    Map = DungeonGenerator.Generate(Game.MapLength, Game.MapLength);

    endTime = System.currentTimeMillis();
    System.out.println("Took " + Long.toString((endTime - startTime) / 1000) + " seconds to generate a map.");
    int count[] = CountWalls_Floors();
    int[] Handles = new int[3];
    int VBOVertexHandle = GL15.glGenBuffers();
    int VBOColorHandle = GL15.glGenBuffers();
    int VBONormalHandle = GL15.glGenBuffers();
    Random rGen = new Random();
    startTime = System.currentTimeMillis();
    FloatBuffer VertexPositionData = BufferUtils
            .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3));
    FloatBuffer VertexColorData = BufferUtils
            .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3));
    FloatBuffer VertexNormalData = BufferUtils
            .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3));
    for (float y = 0; y < Map.length; y++) {
        for (float x = 0; x < Map[0].length; x++) {
            if (Map[(int) y][(int) x] > 0) {
                tiles[(int) y][(int) x] = new WallTile();
                for (float x1 = 0; x1 < DIVISIONS; x1++) {
                    for (float y1 = 0; y1 < DIVISIONS; y1++) {
                        for (float z1 = 0; z1 < DIVISIONS; z1++) {
                            if (y1 == 0 || x1 == 0 || z1 == 0 || y1 == DIVISIONS - 1 || x1 == DIVISIONS - 1
                                    || z1 == DIVISIONS - 1) {
                                VertexPositionData
                                        .put(CreateCube(x * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS * x1,
                                                y * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS * y1,
                                                startZ - z1 * WALL_SCALAR, CUBE_LENGTH / DIVISIONS));
                                GenerateDefaultCubeData(VertexColorData, VertexNormalData,
                                        Map[(int) y][(int) x], rGen);
                            }
                        }
                    }
                }
            } else if (Map[(int) y][(int) x] == 0) {
                tiles[(int) y][(int) x] = new BlankTile();
            } else {
                tiles[(int) y][(int) x] = new FloorTile();
                VertexPositionData.put(CreateFloor(x * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS,
                        y * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS, startZ));
                GenerateDefaultFloorData(VertexColorData, VertexNormalData, Map[(int) y][(int) x], rGen);
            }

        }
    }

    // GEN CUBES HERE
    VertexPositionData.flip();
    VertexColorData.flip();
    VertexNormalData.flip();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBONormalHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexNormalData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    Handles[0] = VBOVertexHandle;
    Handles[1] = VBOColorHandle;
    Handles[2] = VBONormalHandle;
    endTime = System.currentTimeMillis();
    System.out.println("Took " + Long.toString((endTime - startTime) / 1000) + " seconds to build a map.");
    return Handles;

}

From source file:game.level.map.TileMapGenerator.java

License:Open Source License

public static int[] RebuildMesh(int[][] map, int startZ) {
    long startTime;
    long endTime;
    Map = map;//from ww  w  . j  a va  2  s.c  o m

    int count[] = CountWalls_Floors();
    int[] Handles = new int[3];
    int VBOVertexHandle = GL15.glGenBuffers();
    int VBOColorHandle = GL15.glGenBuffers();
    int VBONormalHandle = GL15.glGenBuffers();
    Random rGen = new Random();
    startTime = System.currentTimeMillis();
    FloatBuffer VertexPositionData = BufferUtils
            .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3));
    FloatBuffer VertexColorData = BufferUtils
            .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3));
    FloatBuffer VertexNormalData = BufferUtils
            .createFloatBuffer((int) ((count[0] + count[1] * 6 * DIVISIONS * DIVISIONS * DIVISIONS) * 4 * 3));
    for (float y = 0; y < Map.length; y++) {
        for (float x = 0; x < Map[0].length; x++) {
            if (Map[(int) y][(int) x] > 0) {

                for (float x1 = 0; x1 < DIVISIONS; x1++) {
                    for (float y1 = 0; y1 < DIVISIONS; y1++) {
                        for (float z1 = 0; z1 < DIVISIONS; z1++) {
                            if (y1 == 0 || x1 == 0 || z1 == 0 || y1 == DIVISIONS - 1 || x1 == DIVISIONS - 1
                                    || z1 == DIVISIONS - 1) {
                                VertexPositionData
                                        .put(CreateCube(x * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS * x1,
                                                y * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS * y1,
                                                startZ - z1 * WALL_SCALAR, CUBE_LENGTH / DIVISIONS));
                                GenerateDefaultCubeData(VertexColorData, VertexNormalData,
                                        Map[(int) y][(int) x], rGen);
                            }
                        }
                    }
                }
            } else if (Map[(int) y][(int) x] == 0) {

            } else {

                VertexPositionData.put(CreateFloor(x * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS,
                        y * CUBE_LENGTH + CUBE_LENGTH / DIVISIONS, startZ));
                GenerateDefaultFloorData(VertexColorData, VertexNormalData, Map[(int) y][(int) x], rGen);
            }

        }
    }

    // GEN CUBES HERE
    VertexPositionData.flip();
    VertexColorData.flip();
    VertexNormalData.flip();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBONormalHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexNormalData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    Handles[0] = VBOVertexHandle;
    Handles[1] = VBOColorHandle;
    Handles[2] = VBONormalHandle;
    endTime = System.currentTimeMillis();
    System.out.println("Took " + Long.toString((endTime - startTime) / 1000) + " seconds to build a map.");
    return Handles;

}

From source file:go.graphics.swing.opengl.LWJGLDrawContext.java

License:Open Source License

private int allocateVBO() {
    return GL15.glGenBuffers();
}

From source file:gui.lwjgl.GUIElementLoader.java

/**
 * Stores data in an attribute list of a VAO.
 *
 * @param vaoID The id of the VAO to which data will be added.
 * @param attributeNumber The number of the attribute list in which the data
 * will be stored./*w ww.j a  v a 2 s. co m*/
 * @param data The data that will be stored in the attribute list.
 */
private static void storeDataInAttributeList(int vaoID, int attributeNumber, int coordinateSize, float[] data) {
    // bind VAO so that it can be used.
    bindVAO(vaoID);

    // Create new VBO.
    int vboID = GL15.glGenBuffers();

    // Adds VBO to list so that it can be cleared when needed.
    vbos.add(vboID);

    // VBO has to be bound aswel.
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);

    // Converts float array to an instance of FloatBuffer, which can
    // be stored in a VBO.
    FloatBuffer buffer = Convert.toReadableFloatBuffer(data);

    // Puts the buffer into the VBO, and GL_STATIC_DRAW tells it that it 
    // won't ever be modified.
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);

    // Specifies that this is for the Vertex Array.
    GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);

    // Unbind the VBO.
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    // unbind VAO so that another may be bound.
    unbindVAO();
}