Search code examples
javaperformancerenderlwjgl

Render 20 000 rectangles really fast in LWJGL


Im making a game in Java and I want to render about 20000 rectangles at the same time really fast without using shaders. Is this really possible?


Solution

  • This depends on how big they are and how much of them are rendered. You can clip the rectangles not facing the camera. You can also stop rendering rectangles that are far away from the camera. You can also try to discard rectangles that won't be shown.

    You shouldn't render them in immediate mode. Try using VBOs/VAOs or Display Lists (deprecated) for this. This way the data (vertices and texture coordinates) are sent to the GPU only one time. (When rendered, you just call the id) If some of your geometry has the same shape, you can also use one display list / VAO for many meshes and move them around by translating/rotating/scaling the coordinate system.