Draw many of the same object quickly in OpenGL

前端 未结 2 1292
时光取名叫无心
时光取名叫无心 2021-02-04 08:16

So I\'m working on a game and I need to draw a lot of the same object. Same shape, same size, same color, just different locations.

Right now my setup is like this.

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 09:09

    There's beautiful thing in OpenGL, called Display list. NeHe production has tutorial on them which should provide all necessary info and examples. But basically:

    GLuint displayList; // This should be class attribute
    displayList = glGenLists(1);    
    glNewList(displayList,GL_COMPILE);
    Renderer::draw();
    glEndList();
    

    And in real draw method just:

    glCallList( displayList);
    

    Don't forget to actualize precompiled display list each time you add/remove something.

提交回复
热议问题