Monday, August 15, 2022
HomeGame Developmentrendering - LWJGL eradicating voxel faces that aren't seen

rendering – LWJGL eradicating voxel faces that aren’t seen


I’m merely making an attempt to realize eradicating voxel faces that aren’t seen.What I’ve coded merely renders a bit of 16x16x16. I have already got again face culling enabled, which it does work. in order I am making an attempt to determine this out in regards to the faces, I figured that its the faces that by default usually are not speculated to render and solely render when there may be air as neighbor.versus render all by default until there is not air. I’m considering that these two methods of wording could make up completely different algorithms and due to this fact coding it many various methods. I simply do not know which is greatest. Both approach, I am unsure the best way to organize my code to make this occur. I imagine it could be as a consequence of my code being messy and that I’m a newbie that has alot to be taught.

bundle primary;

import org.lwjgl.glfw.GLFW;

import engine.graphics.Materials;
import engine.graphics.Mesh;
import engine.graphics.Renderer;
import engine.graphics.Shader;
import engine.graphics.Vertex;
import engine.io.Enter;
import engine.io.Window;
import engine.maths.Vector2f;
import engine.maths.Vector3f;
import engine.objects.Digital camera;
import engine.objects.GameObject;


public class Predominant implements Runnable {
    public remaining static int CHUNK_SIZE= 16;
    public Thread recreation;
    public Window window;
    public Renderer renderer;
    public Shader shader;
    public remaining int WIDTH = 1280, HEIGHT = 760;    
    public Mesh mesh = new Mesh(new Vertex[] {
            //Again 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)),
            
            //Entrance 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)),
            
            //Proper 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)),
            
            //Prime 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)),
            
            //Backside 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[] {
            //Again face
            0, 3, 1,    
            1, 3, 2,    
            
            //Entrance face
            4, 5, 7,
            7, 5, 6,
            
            //Proper face
            8, 11, 9,
            9, 11, 10,
            
            //Left face
            12, 13, 15,
            15, 13, 14,
            
            //Prime face
            16, 19, 17,
            17, 19, 18,
            
            //Backside face
            20, 21, 23,
            23, 21, 22
    }, new Materials("/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 Digital camera digital camera =new Digital camera(new Vector3f(0, 0, 1), new Vector3f(0, 0, 0));
    
    public void begin() {
        recreation = new Thread(this, "recreation");
        recreation.begin();
    }
    public  void init() {

        window = new Window(WIDTH, HEIGHT, "GAME");
        shader = new Shader("/shaders/mainVertex.glsl", "/shaders/mainFragment.glsl");
        renderer = new Renderer(window, shader);
        window.setBackgroundColor(.49f , .73f, .91f);
        window.create();
        mesh.create();
        shader.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();
        whereas (!window.shouldClose() && !Enter.iskeyDown(GLFW.GLFW_KEY_ESCAPE)) {
            replace();
            render();
            if (Enter.iskeyDown(GLFW.GLFW_KEY_F11)) window.setFullscreen( !window.isFullscreen());
            if (Enter.isButtonDown(GLFW.GLFW_MOUSE_BUTTON_LEFT)) window.mouseState(true);
                
        }
        shut();
    }
    personal void replace() {
        window.replace();
        digital camera.replace();
        }
    
    personal 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], digital camera); 
                
                    
                }
                }
                }
        //renderer.renderMesh(object, digital camera);
        window.swapbuffers();
    }
    personal void shut() {
        window.destroy();
        mesh.destroy();
        shader.destroy();

    }
    public static void primary(String[] args) {
        new Predominant().begin();

    }

}

You could possibly discover the dice in right here and the chunk
please let me know if there may be any extra code that you simply or one would wish to see to assist me any additional as I dont assume I have to put up my whole code however I could also be flawed. please and thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments