Java, rendering multiply Quads ( Cubes )

I’m trying to render many cubes ( 32 * 16 * 32 ) with texture,
the texture is from Honeyballs Minecraft TexturePack.
The problem is, it lags very much.
I’m using Windows 10, IntelliJ.
(Core i7 7700k, 16gb Ram, and a gtx 1070)

Thanks for help :slight_smile:

So… what have you done so far to try and diagnose your problem?

[li]Have you brought up the Windows Performance Monitor (Ctrl-Alt-Del -> Task Manager) to see what your app is busy doing? [/li][li]Have you retraced your code to make sure you’re not doing things needlessly? [/li][li]Have you run a profiler to see where your time is going? (At least run VerySleepy to see what’s eating all the time on the CPU) [/li][/ul]

Start with that.

Browsing your code, here are a few ideas for you to investigate:

it looks like you’re regenerating your world every single time you run through your gameloop – including reloading your textures. Why?

Also, you’re using “immediate mode” (glBegin(); … glColor/TexCoord/Vertex; repeat for all vertices; glEnd()) for sending vertices to the GPU, and you’re re-computing and re-sending this data every single frame. Immediate mode is the slowest way to provide geometry to OpenGL for rendering. Plus, you’re doing all this in an interpreted language, which makes it even slower. Learn about using vertex arrays and vertex buffer objects (VBOs) to upload the data for bunches of primitives all-in-one-upload using just a few GL calls. Using VBOs also allows you to re-use this data over and over (e.g. redraw it) without having to reupload it to the GPU.

Check out any modern OpenGL book (e.g. The OpenGL Programming Guide) or any modern OpenGL tutorial (e.g. LearnOpenGL or Learning Modern 3D Graphics Programming) for examples and explanations.

Once you master that, since you’re just rendering a whole bunch of blocks, you may want to look at using GPU instancing. What this basically allows you to do is tell the GPU how to render a block from quads, and then tell it what to draw in terms of blocks instead of in terms of quads.

Thank you very much :slight_smile: