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:wrapper.vbo.Vbo.java

License:Open Source License

public void edit_data(Vertex2d[] coordinates) {

    vertex = BufferUtils.createFloatBuffer(coordinates.length * 2);
    texture = BufferUtils.createFloatBuffer(coordinates.length * 2);
    vertcount = coordinates.length;/*from  w  w w . ja  v a2 s.co m*/
    for (int i = 0; i < coordinates.length; i++) {
        vertex.put(coordinates[i].x);
        vertex.put(coordinates[i].y);
        texture.put(coordinates[i].u);
        texture.put(coordinates[i].v);
    }
    vertex.rewind();
    texture.rewind();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertex);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texcoordid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, texture);
}

From source file:wrapper.vbo.Vbo.java

License:Open Source License

public void edit_data(Vertex3d[] coordinates) {

    vertex = BufferUtils.createFloatBuffer(coordinates.length * 3);
    texture = BufferUtils.createFloatBuffer(coordinates.length * 2);
    vertcount = coordinates.length;/*from   w  w  w  .  j a  v a2  s  . c om*/
    for (int i = 0; i < coordinates.length; i++) {
        vertex.put(coordinates[i].x);
        vertex.put(coordinates[i].y);
        vertex.put(coordinates[i].z);
        texture.put(coordinates[i].u);
        texture.put(coordinates[i].v);
    }
    vertex.rewind();
    texture.rewind();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertex);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texcoordid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, texture);
}

From source file:wrapper.vbo.Vbo.java

License:Open Source License

public void edit_data(ProgressiveBuffer[] b) {
    if (b[0].get_data() == null || b[1].get_data() == null) {
        return;/* w w  w  .j  a  v  a2 s  .c  o  m*/
    }
    vertex.clear();
    texture.clear();
    vertex = BufferUtils.createFloatBuffer(b[0].get_data().capacity());
    texture = BufferUtils.createFloatBuffer(b[1].get_data().capacity());
    b[0].get_data().rewind();
    b[1].get_data().rewind();
    vertex = b[0].get_data();
    texture = b[1].get_data();
    vertcount = b[0].get_data().capacity();

    vertex.rewind();
    texture.rewind();

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertex);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texcoordid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, texture);// doesnt
    // reassing
    // meaning its
    // more
    // efficient,
    // only for
    // removing
    // objects
}

From source file:wrapper.vbo.Vbo.java

License:Open Source License

public void clear_data() {
    vertex.clear();//from   ww  w. j av  a 2s  . c  o  m
    texture.clear();
    vertex = BufferUtils.createFloatBuffer(vertcount);
    texture = BufferUtils.createFloatBuffer(vertcount);
    vertex.rewind();
    texture.rewind();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertex);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texcoordid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, texture);
    vertcount = 0;

}

From source file:wrapper.vbo.Vbo.java

License:Open Source License

public void rebind(int size) {

    FloatBuffer temp = BufferUtils.createFloatBuffer(size);
    FloatBuffer temp_tex = BufferUtils.createFloatBuffer(size);
    vertex.rewind();/*w ww .  j a  v  a  2s  .c o  m*/
    maxlength = size;
    texture.rewind();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);// clear and generate
    // two new memory
    // locations with a
    // large amount of space
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp, GL15.GL_DYNAMIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp_tex, GL15.GL_DYNAMIC_DRAW);
    // reassign the previous data to this , useful for string generation.
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertex);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texid);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, texture);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

}

From source file:wrapper.vbo.Vbo.java

License:Open Source License

public void rebind_empty(int size) {

    FloatBuffer temp = BufferUtils.createFloatBuffer(size);
    FloatBuffer temp_tex = BufferUtils.createFloatBuffer(size);
    vertex.rewind();/*from  w w  w . j  a v  a  2 s .c o m*/
    maxlength = size;
    vertcount = 0;
    texture.rewind();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);// clear and generate
    // two new memory
    // locations with a
    // large amount of space
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp, GL15.GL_DYNAMIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, temp_tex, GL15.GL_DYNAMIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:wrapper.vbo.Vbo.java

License:Open Source License

public void render() {
    if (vertid != -1) {

        shader.bind();//from ww  w.j a va2s  . c  om
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texid);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
        GL20.glEnableVertexAttribArray(vertexattrib);
        GL20.glEnableVertexAttribArray(textureattrib);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
        GL20.glVertexAttribPointer(vertexattrib, 3, GL11.GL_FLOAT, false, 0, 0);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texcoordid);
        GL20.glVertexAttribPointer(textureattrib, 2, GL11.GL_FLOAT, false, 0, 0);
        GL20.glUniform3f(rotationuniform, rotation_x, rotation_y, rotation_z);
        GL20.glUniform3f(transformuniform, transformation.x, transformation.y, transformation.z);
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertcount);

        GL20.glDisableVertexAttribArray(vertexattrib);
        GL20.glDisableVertexAttribArray(textureattrib);

        GL11.glEnable(GL11.GL_BLEND);
        shader.unbind();
    } else {

        System.out.println("Error no bound vertid");
        return;
    }

}

From source file:wrath.client.graphics.Model.java

License:Open Source License

/**
 * Creates a 2D or 3D model from a list of verticies.
 * Models are always assumed to be made with triangles, and will be rendered as such.
 * @param name The {@link java.lang.String} name of the Model.
 * @param verticies The list of verticies in the model. One point is represented by (x, y, z), and there must be at least 3 points.
 * @param indicies The list of points to connect for OpenGL. Look up indicies in OpenGL for reference.
 * @param normals The list of 3 float vectors describing the normal vector of the model's surface.
 * @param useDefaultShaders If true, shaders will be set up automatically.
 * @return Returns the {@link wrath.client.graphics.Model} object of your model.
 *//*  ww  w .  j a v  a 2s  .co  m*/
public static Model createModel(String name, float[] verticies, int[] indicies, float[] normals,
        boolean useDefaultShaders) {
    // Generating VAO
    int vaoid = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoid);

    // Generating Verticies VBO
    int vtvboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtvboid);
    FloatBuffer vbuffer = BufferUtils.createFloatBuffer(verticies.length);
    vbuffer.put(verticies);
    vbuffer.flip();
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(VERTICIES_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0);

    // Generating Normals VBO
    int nmvboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, nmvboid);
    FloatBuffer nbuffer = BufferUtils.createFloatBuffer(normals.length);
    nbuffer.put(normals);
    nbuffer.flip();
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, nbuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(NORMALS_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0);

    // Generating Indicies VBO
    int invboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, invboid);
    IntBuffer ibuffer = BufferUtils.createIntBuffer(indicies.length);
    ibuffer.put(indicies);
    ibuffer.flip();
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, ibuffer, GL15.GL_STATIC_DRAW);

    // Creating Model Object
    Model model;
    File mfile = new File("assets/models/" + name);
    if (!mfile.exists())
        model = new Model(name, vaoid, new Integer[] { vtvboid, invboid, nmvboid }, verticies, indicies,
                normals, useDefaultShaders);
    else
        model = new Model(name, vaoid, new Integer[] { vtvboid, invboid, nmvboid }, null, null, null,
                useDefaultShaders);

    Game.getCurrentInstance().getLogger().println("Loaded model '" + name + "' with " + verticies.length
            + " verticies, " + indicies.length + " indicies, and " + normals.length + " normals.");
    if (useDefaultShaders)
        model.attachShader(ShaderProgram.DEFAULT_SHADER);

    // Unbinding OpenGL Objects
    GL30.glBindVertexArray(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    Game.getCurrentInstance().addToTrashCleanup(model);
    Game.getCurrentInstance().addToRefreshList(model);
    return model;
}

From source file:wrath.client.graphics.Model.java

License:Open Source License

/**
 * Applies a {@link wrath.client.graphics.Texture} to the model to be rendered on top of the Model.
 * Only one can be attached at a time./*from   w  w w.  j  a v a 2  s  .  co  m*/
 * @param texture The {@link wrath.client.graphics.Texture} to associate with this model.
 * @param textureCoords The (u, v) coordinates of the texture to the model.
 */
public void attachTexture(Texture texture, float[] textureCoords) {
    this.texture = texture;
    if (this.textureCoords != null)
        textureCoords = this.textureCoords;
    if (shader == null)
        Game.getCurrentInstance().getLogger().println(
                "Warning: If no shader is present to pass texture co-ordinates, then the texture will not render!");
    GL30.glBindVertexArray(vao);
    int vboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboid);
    FloatBuffer vbuffer = BufferUtils.createFloatBuffer(textureCoords.length);
    vbuffer.put(textureCoords);
    vbuffer.flip();
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(TEXTURE_ATTRIB_INDEX, 2, GL11.GL_FLOAT, false, 0, 0);

    if (shader != null)
        shader.bindAttribute(TEXTURE_ATTRIB_INDEX, "in_TextureCoord");
    GL30.glBindVertexArray(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    vbos.add(vboid);
    EntityRenderer.preLoadedModels.put(name + "," + texture.getTextureFile().getName(), this);
}

From source file:wrath.client.graphics.Model.java

License:Open Source License

@Override
public void reload() {
    float[] varray = null;
    float[] narray = null;
    int[] iarray;

    File modelFile = new File("assets/models/" + name);
    if (modelFile.exists()) {
        ArrayList<String> src = readObjFile(modelFile);
        ArrayList<Vector3f> verticies = new ArrayList<>();
        ArrayList<Vector2f> texCoords = new ArrayList<>();
        ArrayList<Vector3f> normals = new ArrayList<>();
        ArrayList<Integer> indicies = new ArrayList<>();
        float[] tarray = null;

        boolean tmp = true;
        for (String inp : src) {
            String[] buf = inp.split(" ");
            if (inp.startsWith("v "))
                verticies.add(new Vector3f(Float.parseFloat(buf[1]), Float.parseFloat(buf[2]),
                        Float.parseFloat(buf[3])));
            else if (inp.startsWith("vt "))
                texCoords.add(new Vector2f(Float.parseFloat(buf[1]), Float.parseFloat(buf[2])));
            else if (inp.startsWith("vn "))
                normals.add(new Vector3f(Float.parseFloat(buf[1]), Float.parseFloat(buf[2]),
                        Float.parseFloat(buf[3])));
            else if (inp.startsWith("f ")) {
                if (tmp) {
                    varray = new float[verticies.size() * 3];
                    narray = new float[verticies.size() * 3];
                    tarray = new float[verticies.size() * 2];
                    tmp = false;// w  w w . j ava2  s . c o  m
                }

                for (int x = 1; x <= 3; x++) {
                    String[] curDat;
                    if (buf[x].contains("//")) {
                        curDat = buf[x].split("//");

                        int ptr = Integer.parseInt(curDat[0]) - 1;
                        indicies.add(ptr);
                        Vector3f norm = normals.get(Integer.parseInt(curDat[1]) - 1);
                        narray[ptr * 3] = norm.x;
                        narray[ptr * 3 + 1] = norm.y;
                        narray[ptr * 3 + 2] = norm.z;
                    } else {
                        curDat = buf[x].split("/");

                        int ptr = Integer.parseInt(curDat[0]) - 1;
                        indicies.add(ptr);
                        Vector2f tex = texCoords.get(Integer.parseInt(curDat[1]) - 1);
                        tarray[ptr * 2] = tex.x;
                        tarray[ptr * 2 + 1] = 1 - tex.y;
                        Vector3f norm = normals.get(Integer.parseInt(curDat[2]) - 1);
                        narray[ptr * 3] = norm.x;
                        narray[ptr * 3 + 1] = norm.y;
                        narray[ptr * 3 + 2] = norm.z;
                    }
                }
            }
        }

        int i = 0;
        for (Vector3f ve : verticies) {
            varray[i] = ve.x;
            varray[i + 1] = ve.y;
            varray[i + 2] = ve.z;
            i += 3;
        }
        iarray = new int[indicies.size()];
        for (int z = 0; z < indicies.size(); z++)
            iarray[z] = indicies.get(z);

        textureCoords = tarray;
        indiciesLen = iarray.length;
    } else {
        varray = verticies;
        narray = normals;
        iarray = indicies;
        indiciesLen = indicies.length;
    }

    // Generating VAO
    vao = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vao);

    // Generating Verticies VBO
    int vtvboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtvboid);
    FloatBuffer vbuffer = BufferUtils.createFloatBuffer(varray.length);
    vbuffer.put(varray);
    vbuffer.flip();
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vbuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(VERTICIES_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0);

    // Generating Normals VBO
    int nmvboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, nmvboid);
    FloatBuffer nbuffer = BufferUtils.createFloatBuffer(narray.length);
    nbuffer.put(narray);
    nbuffer.flip();
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, nbuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(NORMALS_ATTRIB_INDEX, 3, GL11.GL_FLOAT, false, 0, 0);

    // Generating Indicies VBO
    int invboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, invboid);
    IntBuffer ibuffer = BufferUtils.createIntBuffer(iarray.length);
    ibuffer.put(iarray);
    ibuffer.flip();
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, ibuffer, GL15.GL_STATIC_DRAW);

    // Generating Texture VBO
    int texvboid = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texvboid);
    FloatBuffer tbuffer = BufferUtils.createFloatBuffer(textureCoords.length);
    tbuffer.put(textureCoords);
    tbuffer.flip();
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, tbuffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(TEXTURE_ATTRIB_INDEX, 2, GL11.GL_FLOAT, false, 0, 0);

    // Creating Model Object
    vbos.add(vtvboid);
    vbos.add(invboid);
    vbos.add(nmvboid);
    vbos.add(texvboid);
    Game.getCurrentInstance().getLogger().println("Reloaded model '" + name + "'!");
    if (defaultShaders)
        this.attachShader(ShaderProgram.DEFAULT_SHADER);

    // Unbinding OpenGL Objects
    GL30.glBindVertexArray(0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}