Procedural voxel terrain

Hello guy’s. I wanna make a procedural voxel terrain, and i don’t know how i gonna made this. Can someone explain for me, how i can create a new chunk and delete the other chunk for create a procedural terrain in my “game”? I don’t know much about c++ and opengl.

the voxel code:

void drawVoxel(int x, int y, int z)
{
    glPushMatrix();
        glTranslatef(x,y,z);

        // Frontal face
        glBegin(GL_QUADS);
            glVertex3f(0.0, 0.0, 0.0);
            glVertex3f(0.0, 1.0, 0.0);
            glVertex3f(1.0, 1.0, 0.0);
            glVertex3f(1.0, 0.0, 0.0);
        glEnd();

        // Back face
        glBegin(GL_QUADS);
            glVertex3f(0.0, 0.0, 1.0);
            glVertex3f(0.0, 1.0, 1.0);
            glVertex3f(1.0, 1.0, 1.0);
            glVertex3f(1.0, 0.0, 1.0);
        glEnd();

        // Right face
        glBegin(GL_QUADS);
            glVertex3f(1.0, 0.0, 0.0);
            glVertex3f(1.0, 1.0, 0.0);
            glVertex3f(1.0, 1.0, 1.0);
            glVertex3f(1.0, 0.0, 1.0);
        glEnd();

        // Right face
        glBegin(GL_QUADS);
            glVertex3f(0.0, 0.0, 0.0);
            glVertex3f(0.0, 1.0, 0.0);
            glVertex3f(0.0, 1.0, 1.0);
            glVertex3f(0.0, 0.0, 1.0);
        glEnd();

        // Top face
        glBegin(GL_QUADS);
            glVertex3f(0.0, 1.0, 0.0);
            glVertex3f(0.0, 1.0, 1.0);
            glVertex3f(1.0, 1.0, 1.0);
            glVertex3f(1.0, 1.0, 0.0);
        glEnd();

        // Bottom face
        glBegin(GL_QUADS);
            glVertex3f(0.0, 0.0, 0.0);
            glVertex3f(0.0, 0.0, 1.0);
            glVertex3f(1.0, 0.0, 1.0);
            glVertex3f(1.0, 0.0, 0.0);
        glEnd();

        glColor3f(0.0, 2.0, 0.0);

    glPopMatrix();
}

The chunk generation code:

void drawChunk(int blockx, int blocky, int blockz)
{
    noise.SetNoiseType(FastNoiseLite::NoiseType_Perlin);
    float noiseData[128*128];
    int index = 0;

    // Draw terrain
    for(blockx = 0; blockx < tx; blockx++)
    {
        for(blockz = 0; blockz < tz; blockz++)
        {
            noiseData[index++] = altMax * noise.GetNoise((float)(blockx+seed) * 
            sqrt(tx),(float)(blockz+seed) * sqrt(tz));
            drawVoxel(blockx,floor(noiseData[index]),blockz);
        }
    }
}

How i can implement in my code?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.