我想每帧调用glBegin和glEnd一次

gra*_*rry 0 java opengl lwjgl

正如在标题中我希望每帧/更新只能调用glBegin和glEnd一次,因为我已经听到并且正在经历如果你每次更新多次调用它会大幅减速.

这是我的渲染函数的代码:

GL11.glTranslatef(0, 0, -10);
    int x = 0;

    while (x < World.BLOCKS_WIDTH - 1) {
        int y = 0;
        while (y < World.BLOCKS_HEIGHT - 1) {

            if( x * World.BLOCK_SIZE  <= Display.getHeight() ||  y * World.BLOCK_SIZE <= 
                Display.getWidth() ||  x * World.BLOCK_SIZE >= 0 || 
                y * World.BLOCK_SIZE >= 0 ) {

            blocks.b[data.blocks[x][y]].draw(x + Main.PosX, y + Main.PosY);

            }

            y++;
        }
        x++;

}
Run Code Online (Sandbox Code Playgroud)

任何帮助赞赏.

这是我的块类:

GL11.glPushMatrix();
    GL11.glTranslatef(Xa * World.BLOCK_SIZE, Ya * World.BLOCK_SIZE, 0);
    //GL11.glRotatef(0, 0, 1, 0);
    //GL11.glRotatef(0, 1, 0, 0);

    Texture.bind();



        GL11.glBegin(GL11.GL_QUADS);
        GL11.glColor3f(1f, 1f, 1f);
        //GL11.glNormal3f(0, 0, 1);
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(0, 0);
        GL11.glTexCoord2f(0, 1);
        GL11.glVertex2f(0, S);
        GL11.glTexCoord2f(1, 1);
        GL11.glVertex2f(S, S);
        GL11.glTexCoord2f(1, 0);
        GL11.glVertex2f(S, 0);
        GL11.glEnd();


        GL11.glPopMatrix();

}
Run Code Online (Sandbox Code Playgroud)

PS.我可以理解一点纯粹的OpenGL.

dat*_*olf 5

减速不是由于glBegin ... glEnd,而是巨大数量的glNormal,glTexCoord,...... glVertex在中间调用.这称为立即模式,自Ope​​nGL-1.1发布以来一直不合时宜,支持Vertex Arrays.那是在15年前.

请使用Vertex Arrays,最好与Vertex Buffer Objects结合使用; 这就是真正的性能提升来自哪里.