Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.axicer.saintscube.game.world;
- import static org.lwjgl.opengl.GL11.*;
- import static org.lwjgl.opengl.GL15.*;
- import static org.lwjgl.opengl.GL20.*;
- import java.nio.FloatBuffer;
- import org.joml.Matrix4f;
- import org.lwjgl.BufferUtils;
- import org.lwjgl.opengl.Display;
- import fr.axicer.saintscube.game.world.block.Block;
- import fr.axicer.saintscube.render.Camera;
- import fr.axicer.saintscube.render.Texture;
- import fr.axicer.saintscube.render.TextureManager;
- import fr.axicer.saintscube.render.shader.ChunkShader;
- import fr.axicer.saintscube.render.shader.Shader;
- public class Chunk{
- public static final int SIZE = 16;
- public static final int MAX_BUILD_HEIGHT = 256;
- private FloatBuffer vertexBuffer;
- private FloatBuffer textureCoordBuffer;
- private FloatBuffer colorBuffer;
- private int vertexBufferId;
- private int textureCoordBufferId;
- private int colorBufferId;
- private int bufferSize;
- public boolean loaded;
- public int x,z;
- public Block[][][] blocks;
- public World world;
- public Chunk(int x, int z,World world) {
- this.x = x;
- this.z = z;
- this.world = world;
- blocks = new Block[SIZE][MAX_BUILD_HEIGHT][SIZE];
- loaded = false;
- }
- public void load(){
- if(loaded){
- reload();
- return;
- }
- vertexBuffer = BufferUtils.createFloatBuffer(SIZE*MAX_BUILD_HEIGHT*SIZE*6*4*3);
- textureCoordBuffer = BufferUtils.createFloatBuffer(SIZE*MAX_BUILD_HEIGHT*SIZE*6*4*2);
- colorBuffer = BufferUtils.createFloatBuffer(SIZE*MAX_BUILD_HEIGHT*SIZE*6*4*4);
- for(int x = 0 ; x < SIZE ; x++){
- for(int y = 0 ; y < MAX_BUILD_HEIGHT ; y++){
- for(int z = 0 ; z < SIZE ; z++){
- int xx = this.x * SIZE + x;
- int yy = y;
- int zz = this.z * SIZE + z;
- Block upb = getBlock(x, y+1, z);
- Block downb = getBlock(x, y-1, z);
- Block leftb = getBlock(x-1, y, z);
- Block rightb = getBlock(x+1, y, z);
- Block frontb = getBlock(x, y, z-1);
- Block backb = getBlock(x, y, z+1);
- boolean up = false;
- boolean down = false;
- boolean left = false;
- boolean right = false;
- boolean front = false;
- boolean back = false;
- if(upb != null){
- up = !upb.type.isTransparent();
- }
- if(downb != null){
- down = !downb.type.isTransparent();
- }
- if(leftb != null){
- left = !leftb.type.isTransparent();
- }
- if(rightb != null){
- right = !rightb.type.isTransparent();
- }
- if(frontb != null){
- front = !frontb.type.isTransparent();
- }
- if(backb != null){
- back = !backb.type.isTransparent();
- }
- if(up && down && left && right && front && back)continue;
- if(blocks[x][y][z] == null)continue;
- Block block = blocks[x][y][z];
- //TODO FIX FRONT FACE BAD SHADING
- int size = 0;
- float off = 0.7f;
- if(!up){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y+1, z) != null ||
- getBlock(x+1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z+1) != null ||
- getBlock(x, y+1, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x, y+1, z+1) != null ||
- getBlock(x+1, y+1, z+1) != null ||
- getBlock(x+1, y+1, z) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceUpVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceUpTextureData(xx, yy, zz));
- size++;
- }
- if(!down){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceDownVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceDownTextureData(xx, yy, zz));
- size++;
- }
- if(!left){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z-1) != null ||
- getBlock(x-1, y, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z-1) != null ||
- getBlock(x-1, y, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z+1) != null ||
- getBlock(x-1, y, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z+1) != null ||
- getBlock(x-1, y, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceLeftVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceLeftTextureData(xx, yy, zz));
- size++;
- }
- if(!right){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z-1) != null ||
- getBlock(x+1, y, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x+1, y+1, z) != null ||
- getBlock(x+1, y+1, z-1) != null ||
- getBlock(x+1, y, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x+1, y+1, z) != null ||
- getBlock(x+1, y+1, z+1) != null ||
- getBlock(x+1, y, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z+1) != null ||
- getBlock(x+1, y, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceRightVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceRightTextureData(xx, yy, zz));
- size++;
- }
- if(!front){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y, z-1) != null ||
- getBlock(x+1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y, z-1) != null ||
- getBlock(x-1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y, z-1) != null ||
- getBlock(x-1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[2] = off;
- }
- if(getBlock(x+1, y, z-1) != null ||
- getBlock(x+1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceFrontVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceFrontTextureData(xx, yy, zz));
- size++;
- }
- if(!back){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y, z+1) != null ||
- getBlock(x+1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y, z+1) != null ||
- getBlock(x-1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y, z+1) != null ||
- getBlock(x-1, y+1, z+1) != null ||
- getBlock(x, y+1, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x+1, y, z+1) != null ||
- getBlock(x+1, y+1, z+1) != null ||
- getBlock(x, y+1, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceBackVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceBackTextureData(xx, yy, zz));
- size++;
- }
- bufferSize += size*4;
- }
- }
- }
- vertexBuffer.flip();
- textureCoordBuffer.flip();
- colorBuffer.flip();
- vertexBufferId = glGenBuffers();
- glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
- glBufferData(GL_ARRAY_BUFFER, vertexBuffer, GL_STATIC_DRAW);
- textureCoordBufferId = glGenBuffers();
- glBindBuffer(GL_ARRAY_BUFFER, textureCoordBufferId);
- glBufferData(GL_ARRAY_BUFFER, textureCoordBuffer, GL_STATIC_DRAW);
- colorBufferId = glGenBuffers();
- glBindBuffer(GL_ARRAY_BUFFER, colorBufferId);
- glBufferData(GL_ARRAY_BUFFER, colorBuffer, GL_STATIC_DRAW);
- loaded = true;
- }
- public void reload(){
- if(!loaded){
- load();
- return;
- }
- unload();
- vertexBuffer.clear();
- textureCoordBuffer.clear();
- colorBuffer.clear();
- bufferSize = 0;
- for(int x = 0 ; x < SIZE ; x++){
- for(int y = 0 ; y < MAX_BUILD_HEIGHT ; y++){
- for(int z = 0 ; z < SIZE ; z++){
- int xx = this.x * SIZE + x;
- int yy = y;
- int zz = this.z * SIZE + z;
- Block upb = getBlock(x, y+1, z);
- Block downb = getBlock(x, y-1, z);
- Block leftb = getBlock(x-1, y, z);
- Block rightb = getBlock(x+1, y, z);
- Block frontb = getBlock(x, y, z-1);
- Block backb = getBlock(x, y, z+1);
- boolean up = false;
- boolean down = false;
- boolean left = false;
- boolean right = false;
- boolean front = false;
- boolean back = false;
- if(upb != null){
- up = !upb.type.isTransparent();
- }
- if(downb != null){
- down = !downb.type.isTransparent();
- }
- if(leftb != null){
- left = !leftb.type.isTransparent();
- }
- if(rightb != null){
- right = !rightb.type.isTransparent();
- }
- if(frontb != null){
- front = !frontb.type.isTransparent();
- }
- if(backb != null){
- back = !backb.type.isTransparent();
- }
- if(up && down && left && right && front && back)continue;
- if(blocks[x][y][z] == null)continue;
- Block block = blocks[x][y][z];
- int size = 0;
- float off = 0.7f;
- if(!up){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y+1, z) != null ||
- getBlock(x+1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z+1) != null ||
- getBlock(x, y+1, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x, y+1, z+1) != null ||
- getBlock(x+1, y+1, z+1) != null ||
- getBlock(x+1, y+1, z) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceUpVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceUpTextureData(xx, yy, zz));
- size++;
- }
- if(!down){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceDownVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceDownTextureData(xx, yy, zz));
- size++;
- }
- if(!left){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z-1) != null ||
- getBlock(x-1, y, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z-1) != null ||
- getBlock(x-1, y, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y-1, z) != null ||
- getBlock(x-1, y-1, z+1) != null ||
- getBlock(x-1, y, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x-1, y+1, z) != null ||
- getBlock(x-1, y+1, z+1) != null ||
- getBlock(x-1, y, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceLeftVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceLeftTextureData(xx, yy, zz));
- size++;
- }
- if(!right){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z-1) != null ||
- getBlock(x+1, y, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x+1, y+1, z) != null ||
- getBlock(x+1, y+1, z-1) != null ||
- getBlock(x+1, y, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x+1, y+1, z) != null ||
- getBlock(x+1, y+1, z+1) != null ||
- getBlock(x+1, y, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x+1, y-1, z) != null ||
- getBlock(x+1, y-1, z+1) != null ||
- getBlock(x+1, y, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceRightVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceRightTextureData(xx, yy, zz));
- size++;
- }
- if(!front){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y, z-1) != null ||
- getBlock(x+1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y, z-1) != null ||
- getBlock(x-1, y-1, z-1) != null ||
- getBlock(x, y-1, z-1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y, z-1) != null ||
- getBlock(x-1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[2] = off;
- }
- if(getBlock(x+1, y, z-1) != null ||
- getBlock(x+1, y+1, z-1) != null ||
- getBlock(x, y+1, z-1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceFrontVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceFrontTextureData(xx, yy, zz));
- size++;
- }
- if(!back){
- float[] shading = new float[]{1,1,1,1};
- if(getBlock(x+1, y, z+1) != null ||
- getBlock(x+1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[0] = off;
- }
- if(getBlock(x-1, y, z+1) != null ||
- getBlock(x-1, y-1, z+1) != null ||
- getBlock(x, y-1, z+1) != null){
- shading[1] = off;
- }
- if(getBlock(x-1, y, z+1) != null ||
- getBlock(x-1, y+1, z+1) != null ||
- getBlock(x, y+1, z+1) != null){
- shading[2] = off;
- }
- if(getBlock(x+1, y, z+1) != null ||
- getBlock(x+1, y+1, z+1) != null ||
- getBlock(x, y+1, z+1) != null){
- shading[3] = off;
- }
- colorBuffer.put(Block.faceColorData(shading));
- vertexBuffer.put(block.faceBackVertexData(xx, yy, zz));
- textureCoordBuffer.put(block.faceBackTextureData(xx, yy, zz));
- size++;
- }
- bufferSize += size*4;
- }
- }
- }
- vertexBuffer.flip();
- textureCoordBuffer.flip();
- colorBuffer.flip();
- glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
- glBufferData(GL_ARRAY_BUFFER, vertexBuffer, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, textureCoordBufferId);
- glBufferData(GL_ARRAY_BUFFER, textureCoordBuffer, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, colorBufferId);
- glBufferData(GL_ARRAY_BUFFER, colorBuffer, GL_STATIC_DRAW);
- loaded = true;
- }
- public void unload(){
- glDeleteBuffers(vertexBufferId);
- glDeleteBuffers(textureCoordBufferId);
- glDeleteBuffers(colorBufferId);
- loaded = false;
- }
- public Block getBlock(int x, int y, int z){
- if(y < 0 || y >= MAX_BUILD_HEIGHT)return null;
- if(x < 0){
- if(z < 0 ){
- if(world.getChunk(this.x-1, this.z-1) == null)return null;
- return world.getChunk(this.x-1, this.z-1).getBlock(Chunk.SIZE+x, y, Chunk.SIZE+z);
- }else if(z >= Chunk.SIZE){
- if(world.getChunk(this.x-1, this.z+1) == null)return null;
- return world.getChunk(this.x-1, this.z+1).getBlock(Chunk.SIZE+x, y, z-Chunk.SIZE);
- }else{
- if(world.getChunk(this.x-1, this.z) == null)return null;
- return world.getChunk(this.x-1, this.z).getBlock(Chunk.SIZE+x, y, z);
- }
- }else if(x >= Chunk.SIZE){
- if(z < 0 ){
- if(world.getChunk(this.x+1, this.z-1) == null)return null;
- return world.getChunk(this.x+1, this.z-1).getBlock(x-Chunk.SIZE, y, Chunk.SIZE+z);
- }else if(z >= Chunk.SIZE){
- if(world.getChunk(this.x+1, this.z+1) == null)return null;
- return world.getChunk(this.x+1, this.z+1).getBlock(x-Chunk.SIZE, y, z-Chunk.SIZE);
- }else{
- if(world.getChunk(this.x+1, this.z) == null)return null;
- return world.getChunk(this.x+1, this.z).getBlock(x-Chunk.SIZE, y, z);
- }
- }else{
- if(z < 0 ){
- if(world.getChunk(this.x, this.z-1) == null)return null;
- return world.getChunk(this.x, this.z-1).getBlock(x, y, Chunk.SIZE+z);
- }else if(z >= Chunk.SIZE){
- if(world.getChunk(this.x, this.z+1) == null)return null;
- return world.getChunk(this.x, this.z+1).getBlock(x, y, z-Chunk.SIZE);
- }else{
- return blocks[x][y][z];
- }
- }
- }
- public void addBlock(int x, int y, int z, Block b){
- if(y < 0 || y >= MAX_BUILD_HEIGHT)return;
- if(x < 0){
- if(z < 0 ){
- if(world.getChunk(this.x-1, this.z-1) == null)return;
- world.getChunk(this.x-1, this.z-1).addBlock(Chunk.SIZE+x, y, Chunk.SIZE+z, b);
- }else{
- if(world.getChunk(this.x-1, this.z) == null)return;
- world.getChunk(this.x-1, this.z).addBlock(Chunk.SIZE+x, y, z, b);
- }
- }else{
- if(z < 0 ){
- if(world.getChunk(this.x, this.z-1) == null)return;
- world.getChunk(this.x, this.z-1).addBlock(x, y, Chunk.SIZE+z, b);
- }else{
- blocks[x][y][z] = b;
- }
- }
- if(vertexBuffer != null){
- reload();
- int xx = this.x;
- int zz = this.z;
- if(x == 0){
- if(world.getChunk(xx-1, zz) != null){
- world.getChunk(xx-1, zz).reload();
- }
- }
- if(x == SIZE-1){
- if(world.getChunk(xx+1, zz) != null){
- world.getChunk(xx+1, zz).reload();
- }
- }
- if(z == 0){
- if(world.getChunk(xx, zz-1) != null){
- world.getChunk(xx, zz-1).reload();
- }
- }
- if(z == SIZE-1){
- if(world.getChunk(xx, zz+1) != null){
- world.getChunk(xx, zz+1).reload();
- }
- }
- }
- }
- public void removeBlock(int x, int y, int z){
- if(y < 0 || y >= MAX_BUILD_HEIGHT)return;
- if(x < 0){
- if(z < 0 ){
- if(world.getChunk(this.x-1, this.z-1) == null)return;
- world.getChunk(this.x-1, this.z-1).removeBlock(Chunk.SIZE+x, y, Chunk.SIZE+z);
- }else{
- if(world.getChunk(this.x-1, this.z) == null)return;
- world.getChunk(this.x-1, this.z).removeBlock(Chunk.SIZE+x, y, z);
- }
- }else{
- if(z < 0 ){
- if(world.getChunk(this.x, this.z-1) == null)return;
- world.getChunk(this.x, this.z-1).removeBlock(x, y, Chunk.SIZE+z);
- }else{
- blocks[x][y][z] = null;
- }
- }
- if(vertexBuffer != null){
- reload();
- int xx = this.x;
- int zz = this.z;
- if(x == 0){
- if(world.getChunk(xx-1, zz) != null){
- world.getChunk(xx-1, zz).reload();
- }
- }
- if(x == SIZE-1){
- if(world.getChunk(xx+1, zz) != null){
- world.getChunk(xx+1, zz).reload();
- }
- }
- if(z == 0){
- if(world.getChunk(xx, zz-1) != null){
- world.getChunk(xx, zz-1).reload();
- }
- }
- if(z == SIZE-1){
- if(world.getChunk(xx, zz+1) != null){
- world.getChunk(xx, zz+1).reload();
- }
- }
- }
- }
- public void update(){
- }
- public void render(){
- Shader.CHUNK.bind();
- TextureManager.ENV_TEXTURE.bind(0);
- Shader.CHUNK.setUniform("sampler", 0);
- Shader.CHUNK.setUniform("MVP", new Matrix4f().perspective(Camera.fov, (float)Display.getWidth()/(float)Display.getHeight(), 0.1f, 1000.0f));
- glEnableVertexAttribArray(ChunkShader.vertexColorLocation);
- glEnableVertexAttribArray(ChunkShader.vertexPositionLocation);
- glEnableVertexAttribArray(ChunkShader.vertexTexCoordLocation);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId);
- glVertexAttribPointer(ChunkShader.vertexPositionLocation, 3, GL_FLOAT, false, 0, 0);
- glBindBuffer(GL_ARRAY_BUFFER, textureCoordBufferId);
- glVertexAttribPointer(ChunkShader.vertexTexCoordLocation, 2, GL_FLOAT, true, 0, 0);
- glBindBuffer(GL_ARRAY_BUFFER, colorBufferId);
- glVertexAttribPointer(ChunkShader.vertexColorLocation, 4, GL_FLOAT, true, 0, 0);
- glDrawArrays(GL_QUADS, 0, bufferSize);
- glDisableVertexAttribArray(ChunkShader.vertexColorLocation);
- glDisableVertexAttribArray(ChunkShader.vertexPositionLocation);
- glDisableVertexAttribArray(ChunkShader.vertexTexCoordLocation);
- Texture.unbind();
- Shader.unbind();
- if(Camera.debug){
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glLineWidth(1);
- glDisable(GL_CULL_FACE);
- glBegin(GL_QUADS);
- glVertex3f(x*SIZE, 0, z*SIZE);
- glVertex3f(x*SIZE+SIZE, 0, z*SIZE);
- glVertex3f(x*SIZE+SIZE, MAX_BUILD_HEIGHT, z*SIZE);
- glVertex3f(x*SIZE, MAX_BUILD_HEIGHT, z*SIZE);
- glVertex3f(x*SIZE, 0, z*SIZE+SIZE);
- glVertex3f(x*SIZE+SIZE, 0, z*SIZE+SIZE);
- glVertex3f(x*SIZE+SIZE, MAX_BUILD_HEIGHT, z*SIZE+SIZE);
- glVertex3f(x*SIZE, MAX_BUILD_HEIGHT, z*SIZE+SIZE);
- glVertex3f(x*SIZE, 0, z*SIZE);
- glVertex3f(x*SIZE+SIZE, 0, z*SIZE);
- glVertex3f(x*SIZE+SIZE, 0, z*SIZE+SIZE);
- glVertex3f(x*SIZE, 0, z*SIZE+SIZE);
- glVertex3f(x*SIZE, MAX_BUILD_HEIGHT, z*SIZE);
- glVertex3f(x*SIZE+SIZE, MAX_BUILD_HEIGHT, z*SIZE);
- glVertex3f(x*SIZE+SIZE, MAX_BUILD_HEIGHT, z*SIZE+SIZE);
- glVertex3f(x*SIZE, MAX_BUILD_HEIGHT, z*SIZE+SIZE);
- glEnd();
- glEnable(GL_CULL_FACE);
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment