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:io.root.gfx.glutils.GL.java

License:Apache License

public static int glGenBuffers() {
    return GL15.glGenBuffers();
}

From source file:itdelatrisu.opsu.render.CurveRenderState.java

License:Open Source License

/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve/*from ww  w. ja  v  a2  s  . co  m*/
 * @param borderColor the curve border color
 * @param curve the points along the curve
 */
private void draw_curve(Color color, Color borderColor, Vec2f[] curve) {
    staticState.initGradient();
    RenderState state = startRender();
    int vtx_buf;
    // the size is: floatsize * (position + texture coordinates) * (number of cones) * (vertices in a cone)
    FloatBuffer buff = BufferUtils
            .createByteBuffer(4 * (4 + 2) * (2 * curve.length - 1) * (NewCurveStyleState.DIVIDES + 2))
            .asFloatBuffer();
    staticState.initShaderProgram();
    vtx_buf = GL15.glGenBuffers();
    for (int i = 0; i < curve.length; ++i) {
        float x = curve[i].x;
        float y = curve[i].y;
        //if (i == 0 || i == curve.length - 1){
        fillCone(buff, x, y, NewCurveStyleState.DIVIDES);
        if (i != 0) {
            float last_x = curve[i - 1].x;
            float last_y = curve[i - 1].y;
            double diff_x = x - last_x;
            double diff_y = y - last_y;
            x = (float) (x - diff_x / 2);
            y = (float) (y - diff_y / 2);
            fillCone(buff, x, y, NewCurveStyleState.DIVIDES);
        }
    }
    buff.flip();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtx_buf);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
    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);
    for (int i = 0; i < curve.length * 2 - 1; ++i)
        GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2),
                NewCurveStyleState.DIVIDES + 2);
    GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
    GL20.glDisableVertexAttribArray(staticState.attribLoc);
    GL15.glDeleteBuffers(vtx_buf);
    endRender(state);
}

From source file:ivorius.ivtoolkit.models.data.IndexBufferObject.java

License:Apache License

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

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl15.java

License:Open Source License

@Override
public int genBuffer() {
    return GL15.glGenBuffers();
}

From source file:loon.core.graphics.opengl.LWjglGL11.java

License:Apache License

public void glGenBuffers(int n, int[] buffers, int offset) {
    for (int i = offset; i < offset + n; i++)
        buffers[offset] = GL15.glGenBuffers();
}

From source file:main.java.com.YeAJG.game.entity.Entity.java

License:Open Source License

private void SetupEntity(Vector3f[] vertex, Vector3f[] color, Vector2f[] uv) {

    // We'll define our quad using 4 vertices of the custom 'TexturedVertex' class
    vertices = new VertexData[vertex.length];

    for (int i = 0; i < vertex.length; i++) {
        vertices[i] = new VertexData();
        vertices[i].setXYZ(vertex[i].x, vertex[i].y, vertex[i].z);
        vertices[i].setRGBA(color[i].x, color[i].y, color[i].z, 1.0f);
        vertices[i].setST(uv[i].x, uv[i].y);
    }/*from ww w . j  a  v  a 2  s .  co m*/

    // Put each 'Vertex' in one FloatBuffer
    verticesByteBuffer = BufferUtils.createByteBuffer(vertices.length * VertexData.stride);
    FloatBuffer verticesFloatBuffer = verticesByteBuffer.asFloatBuffer();
    for (int i = 0; i < vertices.length; i++) {
        // Add position, color and texture floats to the buffer
        verticesFloatBuffer.put(vertices[i].getElements());
    }
    verticesFloatBuffer.flip();

    // OpenGL expects to draw vertices in counter clockwise order by default
    // TODO: Move this to Setup.
    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, verticesFloatBuffer, GL15.GL_STREAM_DRAW);

    // Put the position coordinates in attribute list 0
    GL20.glVertexAttribPointer(0, VertexData.positionElementCount, GL11.GL_FLOAT, false, VertexData.stride,
            VertexData.positionByteOffset);
    // Put the color components in attribute list 1
    GL20.glVertexAttribPointer(1, VertexData.colorElementCount, GL11.GL_FLOAT, false, VertexData.stride,
            VertexData.colorByteOffset);
    // Put the texture coordinates in attribute list 2
    GL20.glVertexAttribPointer(2, VertexData.textureElementCount, GL11.GL_FLOAT, false, VertexData.stride,
            VertexData.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);

    Game.cameraPos = new Vector3f(0, 0, -1);

    Game.exitOnGLError("setupQuad");
}

From source file:main.Loader.java

private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) {
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);//from   www . j  a  va2s.  c  o  m
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
    FloatBuffer buffer = storeDataInFloatBuffer(data);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
    GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}

From source file:main.Loader.java

private void bindIndicesBuffer(int[] indices) {
    int vboID = GL15.glGenBuffers();
    vbos.add(vboID);/*from ww w  . j  a  va2  s.c o m*/
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboID);
    IntBuffer buffer = storeDataInIntBuffer(indices);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

public void createWindow(int width, int height, String name) {
    this.width = width;
    this.height = height;
    glfwSetErrorCallback(errorCallback = Callbacks.errorCallbackPrint(System.err));
    if (glfwInit() != GL11.GL_TRUE)
        throw new IllegalStateException("Unable to initialize GLFW");
    glfwDefaultWindowHints(); // optional, the current window hints are
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE); // the window will stay
    // hidden/*  w ww.  j a  v a 2  s.  c  om*/
    glfwWindowHint(GLFW_RESIZABLE, GL11.GL_TRUE); // the window will be
    // resizable
    window = glfwCreateWindow(width, height, name, NULL, NULL);
    if (window == NULL)
        throw new RuntimeException("Failed to create the GLFW window");
    // glfwSetKeyCallback(window,this.keyCallback = keyCallback);
    glfwSetWindowSizeCallback(window, resizeCallback());
    ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(window, (vidmode.asIntBuffer().get(0) - width) / 2,
            (vidmode.asIntBuffer().get(1) - height) / 2);
    glfwMakeContextCurrent(window);
    Graphic.instance = this;
    glfwSwapInterval(1);
    GL.createCapabilities();
    setCapabilities();

    glfwShowWindow(window);

    // Setup an XNA like background color
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glDepthFunc(GL11.GL_LESS);

    GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0);
    // Map the internal OpenGL coordinate system to the entire screen
    GL11.glViewport(0, 0, width, height);
    matBuff = BufferUtils.createFloatBuffer(16);
    vaoId = GL30.glGenVertexArrays();
    vboiId = GL15.glGenBuffers();
    vboId = GL15.glGenBuffers();
    tid_charmap = texManager.loadTexture("textures/charmap.png", GL13.GL_TEXTURE0);
    shader.setupShader();
    // testQuad();

}

From source file:me.thehutch.fusion.engine.render.opengl.gl30.OpenGL30VertexArray.java

License:Open Source License

@Override
public void create() {
    ensureNotCreated("VertexArray is already created.");
    // Create the vertex array object
    this.vao = GL30.glGenVertexArrays();
    // Create the index buffer
    this.ibo = GL15.glGenBuffers();
    // Create the attributes list
    this.attributes = new TIntArrayList(3, -1);
    // Check for errors
    RenderUtil.checkGLError();/*from   w  ww.j a  va 2s. c  o m*/
    super.create();
}