Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9258919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:31:42+00:00 2026-06-18T12:31:42+00:00

First off, my code is in no way optimized. I’m also using old glTranslatf()

  • 0

First off, my code is in no way optimized. I’m also using old glTranslatf() and all that because I don’t know the new way of doing things. Here’s my code:

public class GenChunk {

Chunk c;
VBO vbo = new VBO();

int worldSize = 16;
int var4 = 16; // x
int var5 = 16; // z
int var6 = 16; // y

int xOffSet = 0;
int zOffSet = 0;

public GenChunk() {
    gen();
}

public void gen() {
    for (int x = xOffSet; x < worldSize; x++) {
        for (int z = zOffSet; z < worldSize; z++) {
            for (int y = 0; y < worldSize; y++) {
                glPushMatrix();
                glTranslatef(x, z, y);
                newChunk();
                glPopMatrix();
                xOffSet += 16;
                zOffSet += 16;
            }
        }
    }
}

private void newChunk() {

    vbo = new VBO();

    glBindBuffer(GL_ARRAY_BUFFER, vbo.vboVHandle);
    glVertexPointer(3, GL_FLOAT, 0, 0L);

    glBindBuffer(GL_ARRAY_BUFFER, vbo.vboCHandle);
    glColorPointer(3, GL_FLOAT, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    for (int y = 0; y < var6; y++) {
        for (int x = 0; x < var5; x++) {
            for (int z = 0; z < var6; z++) {
                glPushMatrix();
                glTranslatef(x, z, y);
                glDrawArrays(GL_QUADS, 0, 24);
                glPopMatrix();
            }
        }

    }
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
}

}

And the VBO class:

public class VBO {

public int vboVHandle;

public int vboCHandle;

public float size = 0.5f;
public float color = 0.5f;

public FloatBuffer vertices;
public FloatBuffer colorData;

public VBO(){

colorData = BufferUtils.createFloatBuffer(3 * 4 * 6);
colorData.put(new float[]{
        -color, color, color,
        color, color, color,
        -color, color, color,
        color, color, color,

        -color, color, color,
        color, color, color,
        -color, color, color,
        color, color, color,

        -color, color, color,
        color, color, color,
        -color, color, color,
        color, color, color,

        -color, color, color,
        color, color, color,
        -color, color, color,
        color, color, color,

        -color, color, color,
        color, color, color,
        -color, color, color,
        color, color, color,

        -color, color, color,
        color, color, color,
        -color, color, color,
        -color, color, color
});
colorData.flip();

vertices = BufferUtils.createFloatBuffer(3 * 4 * 6);
vertices.put(new float[] {
        -size, -size, size,
        size, -size, size,
        size, size, size,
        -size, size, size,

        -size, -size, -size,
        -size, size, -size,
        size, size, -size,
        size, -size, -size,

        -size, size, -size,
        -size, size, size,
        size, size, size,
        size, size, -size,

        -size, -size, -size,
        size, -size, -size,
        size, -size, size,
        -size, -size, size,

        size, -size, -size,
        size, size, -size,
        size, size, size,
        size, -size, size,

        -size, -size, -size,
        -size, -size, size,
        -size, size, size,
        -size, size, -size});
vertices.flip();

vboVHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboVHandle);
glBufferData(GL_ARRAY_BUFFER, vertices, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);


vboCHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboCHandle);
glBufferData(GL_ARRAY_BUFFER, colorData, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

}

}
I render out two chunks, so approximately 8000 cubes. I’ve heard of people rendering out 10,000 cubes and still maintaining 60 FPS, yet when I render two chunks, I get 1 FPS. My hardware is not the problem, its decent. I know I need to optimize my code like crazy, but I’m worried that even with optimizations, it’ll still be slow! Can anyone tell me what I’m doing wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:31:44+00:00Added an answer on June 18, 2026 at 12:31 pm

    Using a VBO with a single cube in it and glTranslate()ing it around will not help your performance at all.

    A VBO for a given chunk should contain multiple cubes (at 163, up to 2048 for the worst-case checkerboard volume). You should only issue glTranslate()s at the chunk level, not per-cube.

    EDIT:

    You have your volume database, generally stored in a 3D array of some sort. Each element of the array is a class/struct (or even just an int or char!) that holds your block type information (grass, dirt, rock, etc.) and other state. You also need a function like bool IsOpaque( const BlockType& block) that can tell you if the given block is graphically opaque or not.

    Iterate over all the blocks in a given chunk. If a block IsOpaque() check its six neighbors (±X, ±Y, ±Z). If a neighbor !IsOpaque() generate the vertexes for two triangles (or one quad) for that side of a cube (translated appropriately (not via glTranslatef()!) depending on the position in the chunk) and append them to a buffer.

    When you’re done iterating over the chunk upload the buffer of vertexes to a VBO.

    Or you can get fancier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off I want to start off saying that I don't know anything about
First off, I'm not all that familiar with cookies but I know how they
First off I want to make the claim that I am in no way
First off, I know I can copy "this" on instantiation, but that doesn't work
First off, it is nice that they are trying to get code completion on
First off sorry for a re-post, I voted to delete my old post because
First off, sorry for what I know is terrible idiomatic Ruby code. I am
First off, I am not sure that the way that I am planning (and
First off, I'm new to LINQ, so I don't really know the ins and
First off, I know this may be a very stupid question, so don't shoot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.