# LWJGL removing voxel faces that are not visible

I am simply trying to achieve removing voxel faces that are not visible.What I have coded simply renders a chunk of 16x16x16. I already have back face culling enabled, which it does work. so as I'm trying to figure this out about the faces, I figured that its the faces that by default are not supposed to render and only render when there is air as neighbor.as opposed to render all by default unless there isn't air. I am thinking that these two ways of wording can make up different algorithms and therefore coding it many different ways. I just don't know which is best. Either way, I'm not sure how to arrange my code to make this happen. I believe it may be due to my code being messy and that I am a beginner that has alot to learn.

package main;

import org.lwjgl.glfw.GLFW;

import engine.graphics.Material;
import engine.graphics.Mesh;
import engine.graphics.Renderer;
import engine.graphics.Vertex;
import engine.io.Input;
import engine.io.Window;
import engine.maths.Vector2f;
import engine.maths.Vector3f;
import engine.objects.Camera;
import engine.objects.GameObject;

public class Main implements Runnable {
public final static int CHUNK_SIZE= 16;
public Window window;
public Renderer renderer;
public final int WIDTH = 1280, HEIGHT = 760;
public Mesh mesh = new Mesh(new Vertex[] {
//Back face
new Vertex(new Vector3f(-0.5f,  0.5f, -0.5f), new Vector2f(0.0f, 0.0f)),
new Vertex(new Vector3f(-0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 0.5f)),
new Vertex(new Vector3f( 0.5f, -0.5f, -0.5f), new Vector2f(0.5f, 0.5f)),
new Vertex(new Vector3f( 0.5f,  0.5f, -0.5f), new Vector2f(0.5f, 0.0f)),

//Front face
new Vertex(new Vector3f(-0.5f,  0.5f,  0.5f), new Vector2f(0.0f, 0.0f)),
new Vertex(new Vector3f(-0.5f, -0.5f,  0.5f), new Vector2f(0.0f, 0.5f)),
new Vertex(new Vector3f( 0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
new Vertex(new Vector3f( 0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),

//Right face
new Vertex(new Vector3f( 0.5f,  0.5f, -0.5f), new Vector2f(0.0f, 0.0f)),
new Vertex(new Vector3f( 0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 0.5f)),
new Vertex(new Vector3f( 0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
new Vertex(new Vector3f( 0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),

//Left face
new Vertex(new Vector3f(-0.5f,  0.5f, -0.5f), new Vector2f(0.0f, 0.0f)),
new Vertex(new Vector3f(-0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 0.5f)),
new Vertex(new Vector3f(-0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
new Vertex(new Vector3f(-0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),

//Top face
new Vertex(new Vector3f(-0.5f,  0.5f,  0.5f), new Vector2f(0.5f, 0.0f)),
new Vertex(new Vector3f(-0.5f,  0.5f, -0.5f), new Vector2f(0.5f, 0.5f)),
new Vertex(new Vector3f( 0.5f,  0.5f, -0.5f), new Vector2f(1.0f, 0.5f)),
new Vertex(new Vector3f( 0.5f,  0.5f,  0.5f), new Vector2f(1.0f, 0.0f)),

//Bottom face
new Vertex(new Vector3f(-0.5f, -0.5f,  0.5f), new Vector2f(0.0f, 0.5f)),
new Vertex(new Vector3f(-0.5f, -0.5f, -0.5f), new Vector2f(0.0f, 1.0f)),
new Vertex(new Vector3f( 0.5f, -0.5f, -0.5f), new Vector2f(0.5f, 1.0f)),
new Vertex(new Vector3f( 0.5f, -0.5f,  0.5f), new Vector2f(0.5f, 0.5f)),
}, new int[] {
//Back face
0, 3, 1,
1, 3, 2,

//Front face
4, 5, 7,
7, 5, 6,

//Right face
8, 11, 9,
9, 11, 10,

//Left face
12, 13, 15,
15, 13, 14,

//Top face
16, 19, 17,
17, 19, 18,

//Bottom face
20, 21, 23,
23, 21, 22
}, new Material("/textures/Grass.png"));
public GameObject[][][] objects;
public GameObject object = new GameObject(new Vector3f(0, 0, 0), new Vector3f(0, 0, 0), new Vector3f(1, 1, 1), mesh);
public Camera camera =new Camera(new Vector3f(0, 0, 1), new Vector3f(0, 0, 0));

public void start() {
game.start();
}
public  void init() {

window = new Window(WIDTH, HEIGHT, "GAME");
window.setBackgroundColor(.49f , .73f, .91f);
window.create();
mesh.create();
objects = new GameObject[CHUNK_SIZE][CHUNK_SIZE][CHUNK_SIZE];
for (int x = 0; x < CHUNK_SIZE; x++) {
for (int y = 0; y < CHUNK_SIZE; y++) {
for (int z = 0; z < CHUNK_SIZE; z++) {
objects[x][y][z] = new GameObject(new Vector3f(x, y, z), new Vector3f(0, 0, 0), new Vector3f(1, 1, 1), mesh);
}
}
}

}
public void run() {
init();
while (!window.shouldClose() && !Input.iskeyDown(GLFW.GLFW_KEY_ESCAPE)) {
update();
render();
if (Input.iskeyDown(GLFW.GLFW_KEY_F11)) window.setFullscreen( !window.isFullscreen());
if (Input.isButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) window.mouseState(true);

}
close();
}
private void update() {
window.update();
camera.update();
}

private void render() {
for (int x = 0; x < CHUNK_SIZE; x++) {
for (int y = 0; y < CHUNK_SIZE; y++) {
for (int z = 0; z < CHUNK_SIZE; z++) {
renderer.renderMesh(objects[x][y][z], camera);

}
}
}
//renderer.renderMesh(object, camera);
window.swapbuffers();
}
private void close() {
window.destroy();
mesh.destroy();

}
public static void main(String[] args) {
new Main().start();

}

}


You may be able to notice the cube in here and the chunk please let me know if there is any more code that you or one would need to see to help me any further as I dont think I need to post my entire code but I may be wrong. please and thank you

• Have you tried implementing past answers about how to build chunks without internal faces? Aug 15, 2022 at 1:22
• So I tried understanding That and since Im really new at this especially at the lwjgl, Im not really getting much "lwjgl" terminology from it. If any thing, what I got from it is another way of doing it. not really on how to implement it on my own code. Just hoping for some enlightenment. @DMGregory Aug 21, 2022 at 23:15
• What specific step did you run into difficulty porting to lwjgl? Aug 21, 2022 at 23:27
• If by "porting" you mean translating to the lwjgl or interpreting to it, well I dont know how to do so. I dont even have the words "uv, int3, or normals" in my code, I dont have "block types". also some constructive criticism is welcomed, I know My code isnt great. But I also know its possible the way I have it I think Cause Ive made it this far. @DMGregory Aug 21, 2022 at 23:52
• Does a Batch rendering Have anything to do with this btw? @DMGregory Aug 22, 2022 at 0:19