Java LWJGL 2D VBO的慢速FPS性能

时间:2013-09-02 00:09:12

标签: java opengl 2d lwjgl

我和朋友正在研究一些LWJGL 2D相关的东西。我正在研究VBO,并且能够让它发挥作用。现在,当使用它来绘制瓷砖时,它们可以工作。但是,我的FPS显着下降。也许我做错了什么。

这是我的代码。

public void drawTextureRect(float x, float y, float width, float height,
        String textureName) {
    // Bind the texture to draw
    texture = loadTexture(textureName);
    texture.bind();

    // Set triangle vertex data
    FloatBuffer vertices = BufferUtils.createFloatBuffer(6);
    vertices.put(new float[] { x, y, x + width, y, x, height + y });

    // Set texture coordinates
    FloatBuffer textcoord = BufferUtils.createFloatBuffer(6);
    textcoord.put(new float[] { 0, 0, 1, 0, 0, 1 });
    // Allow OpenGL to interpret the Text Coordinates & Vertex Data
    textcoord.flip();
    vertices.flip();


    int VertexHandle = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, VertexHandle);
    glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    int TextureHandle = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, TextureHandle);
    glBufferData(GL_ARRAY_BUFFER, textcoord, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindBuffer(GL_ARRAY_BUFFER, VertexHandle);
    glVertexPointer(2, GL_FLOAT, 0, 0L);

    glBindBuffer(GL_ARRAY_BUFFER, TextureHandle);
    glTexCoordPointer(2, GL_FLOAT, 0, 0L);

    // Enable Vertex and Texture Arrays
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    // Draw Triangle
    glDrawArrays(GL_TRIANGLES, 0, 3);

    // Unable Vertex and Textures
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

    /*  SECOND TRIANGLE */
    // Set Second Triangle Coordinates
    FloatBuffer vertices2 = BufferUtils.createFloatBuffer(6);
    vertices2.put(new float[] { x + width, y + height, x, height + y,
            x + width, y });

    // Set Second Texture Coordinates
    FloatBuffer textcoord2 = BufferUtils.createFloatBuffer(6);
    textcoord2.put(new float[] { 1, 1, 0, 1, 1, 0 });

    // Allow OpenGl to interpret the Text Coordinates & Vertex Data
    textcoord2.flip();
    vertices2.flip();

    int VertexHandle2 = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, VertexHandle2);
    glBufferData(GL_ARRAY_BUFFER, vertices2, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    int TexCord = glGenBuffers();
    glBindBuffer(GL_ARRAY_BUFFER, TexCord);
    glBufferData(GL_ARRAY_BUFFER, textcoord2, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindBuffer(GL_ARRAY_BUFFER, VertexHandle2);
    glVertexPointer(2, GL_FLOAT, 0, 0L);

    glBindBuffer(GL_ARRAY_BUFFER, TexCord);
    glTexCoordPointer(2, GL_FLOAT, 0, 0L);

    // Enable Vertex and Texture Arrays
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    // Draw Triangle
    glDrawArrays(GL_TRIANGLES, 0, 3);

    // Unable Vertex and Textures
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);

    glDeleteBuffers(TextureHandle);
    glDeleteBuffers(TexCord);
    glDeleteBuffers(VertexHandle);
    glDeleteBuffers(VertexHandle2);
}`

0 个答案:

没有答案
相关问题