Example usage for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER

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

Introduction

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

Prototype

int GL_ARRAY_BUFFER

To view the source code for org.lwjgl.opengl GL15 GL_ARRAY_BUFFER.

Click Source Link

Document

Accepted by the target parameters of BindBuffer, BufferData, BufferSubData, MapBuffer, UnmapBuffer, GetBufferSubData, GetBufferParameteriv, and GetBufferPointerv.

Usage

From source file:fr.ign.cogit.geoxygene.appli.gl.GLSimpleComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context/*from   ww w  .j  a v a2 s .co m*/
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }

    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);
    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);

    glBindVertexArray(0);

}

From source file:fr.ign.cogit.geoxygene.appli.gl.GLTextComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context/*from www . java 2  s.  c  om*/
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        // System.err.println("loc = " + input.getLocation() + " "
        // + input.getComponentCount() + " " + input.getGlType()
        // + " stride = " + this.getStride() + " shift = " + byteShift
        // + " name = " + input.getName() + " "
        // + this.getClass().getSimpleName());
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }
    // System.err.println("previous");
    // for (int nAttrib = 0; nAttrib < GLSimpleVertex.ATTRIBUTES_COUNT;
    // nAttrib++)
    // {
    // GL20.glVertexAttribPointer(GLSimpleVertex.ATTRIBUTES_ID[nAttrib],
    // GLSimpleVertex.ATTRIBUTES_COMPONENT_NUMBER[nAttrib],
    // GLSimpleVertex.ATTRIBUTES_TYPE[nAttrib],
    // false, GLSimpleVertex.VERTEX_BYTESIZE,
    // GLSimpleVertex.ATTRIBUTES_BYTEOFFSET[nAttrib]);
    // System.err.println("loc = " + GLSimpleVertex.ATTRIBUTES_ID[nAttrib] +
    // " " +
    // GLSimpleVertex.ATTRIBUTES_COMPONENT_NUMBER[nAttrib] + " "
    // + GLSimpleVertex.ATTRIBUTES_TYPE[nAttrib] + " stride = " +
    // GLSimpleVertex.VERTEX_BYTESIZE + " shift = " +
    // GLSimpleVertex.ATTRIBUTES_BYTEOFFSET[nAttrib]);
    // glEnableVertexAttribArray(GLSimpleVertex.ATTRIBUTES_ID[nAttrib]);
    //
    // }

    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedVerticesBuffer());

    // glBindBuffer(GL_ARRAY_BUFFER, 0);

    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedIndicesBuffer());

    glBindVertexArray(0);

}

From source file:fr.ign.cogit.geoxygene.util.gl.GLGradientComplex.java

License:Open Source License

/**
 * Bind Buffers with gl Context/*from www. j ava 2  s.c om*/
 */
private void generateVao() {
    // Create a new Vertex Array Object in memory and select it (bind)
    this.vaoId = GL30.glGenVertexArrays();
    if (this.vaoId <= 0) {
        logger.error("VAO ID is invalid " + this.vaoId);
    }
    glBindVertexArray(this.vaoId);

    // create the Vertex VBO
    this.vboVerticesId = glGenBuffers();
    if (this.vboVerticesId <= 0) {
        logger.error("VBO(Vertices) ID is invalid " + this.vboVerticesId);
    }
    glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vboVerticesId);

    int byteShift = 0;
    for (GLInput input : this.getInputs()) {
        GL20.glVertexAttribPointer(input.getLocation(), input.getComponentCount(), input.getGlType(),
                input.isNormalized(), this.getStride(), byteShift);
        byteShift += input.getComponentCount() * GLTools.sizeInBytes(input.getGlType());
        glEnableVertexAttribArray(input.getLocation());

    }

    glBufferData(GL_ARRAY_BUFFER, this.getFlippedVerticesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedVerticesBuffer());

    // glBindBuffer(GL_ARRAY_BUFFER, 0);

    // create the index VBO
    this.vboIndicesId = glGenBuffers();
    if (this.vboIndicesId <= 0) {
        logger.error("VBO(Indices) ID is invalid " + this.vboIndicesId);
    }

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this.vboIndicesId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, this.getFlippedIndicesBuffer(), GL_STATIC_DRAW);

    // displayBuffer(this.getFlippedIndicesBuffer());

    glBindVertexArray(0);

}

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

License:Open Source License

public void DeleteVBOFromMemory() {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glDeleteBuffers(VBOVertexHandle);
    GL15.glDeleteBuffers(VBOColorHandle);
    GL15.glDeleteBuffers(VBONormalHandle);
    VBOVertexHandle = 0;/*from   w w w .  j a  va 2s. co m*/
    VBOColorHandle = 0;
    VBONormalHandle = 0;
}

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

License:Open Source License

public void Render() {
    GL11.glPushMatrix();//  w w w  .  ja  v a 2  s .co  m
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0L);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
    GL11.glColorPointer(3, GL11.GL_FLOAT, 0, 0L);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBONormalHandle);
    GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0L);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    if (DebugMode) {
        GL11.glDrawArrays(GL11.GL_LINE_LOOP, 0, Quads * 16);
    } else {
        GL11.glDrawArrays(GL11.GL_QUADS, 0, Quads * 16);
    }

    for (int y = 0; y < tiles.length; y++) {
        for (int x = 0; x < tiles[0].length; x++) {
            if (tiles[y][x].IsFloor) {
                try {
                    tiles[y][x].Render(x, y);
                } catch (Exception e) {

                }

            }
        }
    }
    GL11.glPopMatrix();
    // }
}

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 . ja  va2s  .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;//  ww  w  . j  a  v a2 s .  co  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:gameEngine.Core.VOs.java

public static int createVAOFromModel(Model data) {

    VAO newVAO = new VAO();
    VBO newVBO = new VBO();
    List<vertexAtribute> vertexAtributes = new ArrayList();
    vertexAtribute newVertexAtrib = new vertexAtribute();
    vertexAtribute newColorAtrib = new vertexAtribute();
    vertexAtribute newNormalAtrib = new vertexAtribute();

    FloatBuffer newBuffer = BufferUtils
            .createFloatBuffer(data.verticies.length + data.color.length + data.normals.length);
    newBuffer.put(data.verticies);//from  ww w  .j  ava 2 s.c  o  m
    newBuffer.put(data.color);
    newBuffer.put(data.normals);
    newBuffer.flip();

    newVertexAtrib.setAtributes(0, 3, 0, 0, false);
    newColorAtrib.setAtributes(1, 4, 0, data.verticies.length * 4, false);
    newNormalAtrib.setAtributes(2, 3, 0, data.verticies.length * 4 + data.color.length * 4, false);

    vertexAtributes.add(newVertexAtrib);
    vertexAtributes.add(newColorAtrib);
    vertexAtributes.add(newNormalAtrib);

    newVBO.setAttributes(0, GL15.GL_ARRAY_BUFFER, GL15.GL_STATIC_DRAW, GL11.GL_FLOAT, 0, newBuffer,
            vertexAtributes);

    List<VBO> vbos = new ArrayList();
    vbos.add(newVBO);

    newVAO.setAtributes(data.fileName, GL_TRIANGLES, 0, data.verticies.length / 3, vbos);

    vaos.add(newVAO);
    Integer theID = nextID;
    nextID++;
    ID.add(theID);
    return theID;
}

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

License:Open Source License

private void bindArrayBuffer(GeometryHandle geometry) throws IllegalBufferException {
    int id;//  ww w.ja  va  2  s  .c  om
    if (geometry == null) {
        id = 0;
    } else {
        if (!geometry.isValid()) {
            throw new IllegalBufferException("Geometry handle is not valid: " + geometry);
        }
        id = geometry.getInternalId();
    }
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id);
}

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

License:Open Source License

@Override
public GLBuffer startWriteGeometry(GeometryHandle geometry) throws IllegalBufferException {
    if (canUseVBOs) {
        bindArrayBuffer(geometry);//from  ww  w .  ja va 2 s . c  o m
        ByteBuffer buffer = GL15.glMapBuffer(GL15.GL_ARRAY_BUFFER, GL15.GL_WRITE_ONLY)
                .order(ByteOrder.nativeOrder());
        return new GLByteBufferWrapper(buffer);

    } else {
        return new GLByteBufferWrapper(getGeometryBuffer(geometry));
    }
}