LWJGL - Voxel Engine

Block class:
http://pastebin.java-gaming.org/c73e2821254

Grass:
http://pastebin.java-gaming.org/73e2292145c

Init texture_2d

GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureID());
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

Hi

That’s odd, as your other stone blocks are ok! Just the first one to be rendered? Or last?

I’ll have a good look over the grass one, that mistake is on every block, so it must be the co-ordinates, or are you drawing those blocks somehow differently to the rest of the blocks?

Will have a look over it.

The difference between grass and the rest of the blocks is that it uses another texture for the top side and the bottom side. Also, I took the grass texture coords from the opposite direction starting from the left bottom corner of the texture instead of the top left corner. I did that because the grass was displayed rotated.

Also, the buggish corner is the first of the last z row, I think.

for(int x = 0; x < World.CHUNK_WIDTH; x++) {

			for (int y = 0; y < World.CHUNK_HEIGHT; y++) {

				for (int z = 0; z < World.CHUNK_LENGTH; z++) {

					blocks.add(new Air(this.x + x * Block.width, y * Block.height, this.z + z * Block.length));

				}

			}

		}

I figured out that the second problem occurs only on blocks that don’t use the same texture for all the 6 sides. It happends only to blocks like grass.

up.

I managed to find whats causes these two problems (by myself :cranky:), and I managed to fix them.

Fyi, the problem was that some sides need to be drawn clockwise and some others counter clockwise. Also, this fixed the face-culling bug I faced.

UCw7bgGoBD8

This is the current state of my voxel engine. I used lists so far, and it seems that I have to move to arrays.

Looking good,

Do you do a check to see if cube is in view before rendering?

Any collision checks yet?

Keep up the good work.

I got a collision check that actually works the only problem is that I haven’t figured out yet how to stop camera movement when it collides. It may sounds simple but II get some weird results. Even though, it print a collision message when you collide to a block.

About your rendering question, I only use front face culling.

After turning lists into arrays I got way more fps. 256 of 16^3 chunks almost 2k fps.

That is looking really good. Love the trees.

Good how your limiting chunk drawing. Nice work.

Good about the culling, although depending on how many faces you are checking, it sometimes can slow the renderer down unless you partition your chunks into some form of data structure such as octree.

As for stop player moving through a block, I do something like:


if (Keyboard.isKeyDown(Keyboard.KEY_W))// move forwards
{
	
	if(!isCollision(1))
	{
		camera.walkBackwards(movementSpeed * dt);
	}
}

Where isCollision returns true or false, if false, no collision, so player here can move forwards.

PS - did you create a function for the trees?

I randomly place blocks at the shape of a tree at the top of each chunk.

Going to be looking at putting trees in myself. Did you create a method that would not put any blocks on top of a tree?

Thanks

I don’t think you’d need that if you’re only using 2D perlin/simplex noise. If you plant the trees at random locations, its impossible for a block to be above it. Just make sure you’re planting the trees on grass :slight_smile:

Hi @Argo,

So, I’m using the simplex noise class, this is how I generate a simple 16^3 chunk with it:


	public int SetupLandscape()
	{
		Random rr = new Random();
		for (int x = 0; x < CHUNK_SIZE; x++) {
			for (int z = 0; z < CHUNK_SIZE; z++) {		
				int height = (int) (SimplexNoise.noise(x / 16f, z / 16f) *16f);
				if(height<1) height=1;
				for(int y = 0; y <= height; y++) // set these blocks on
				{
					Blocks[x][y][z].SetActive(true);
					if(rr.nextBoolean())
						Blocks[x][y][z].SetType(BlockType.BlockType_Grass);
					else
						Blocks[x][y][z].SetType(BlockType.BlockType_Dirt);
						
				}
			}
		}
		return this.rebuildChunk();
	}


So, you are saying when I have done that I can place a tree anywhere as long as it is grass? I think I need to call the above, then create another method which would plant a tree at random locations within this chunk as long as the height of the block we are putting it on is not going to allow our tree to go out of the bounds of the chunk. i.e. if our tree is going to be 12 blocks in height, we need to put it on a block that is less than 4 on the Y-axis - this make sense or am I talking garbage?!

Thanks

I don’t use any advanced methods to generate my world. I just generate some random ints for each block type, and then I call my my generateTree function which generates 2 number from 1 to 6 (one for x, and on for z axis) and I just spawn a tree there.


0UCS_vIceRI

  • Added Collision Detection.
  • Added Gravity, and jumping.
  • Enabled vsync to 60.
  • I moved to arrays from lists.

Looking good. Did you use voxel space for collision or AABB?

I basically just got player position and converted to voxel space and indexed into chunk/block array.

Take it your trees are all the same height then? How do you manage placing the tree on top of a block so it doesn’t appear below one?

I used AABB.

After chunk generation I save the top y value so I can use it to stuff like spawning trees.

Steg, how I would do it is first generate the whole entire world. Then pick out random X and Z values that have space in your world, get the highest block in that place, and spawn a tree on that block above it. That’s how I would do it atm. You can also check the distance from other trees to make sure they aren’t too close together.

Also, if you want, you can just loop through your X and Z width and spawn trees every 5x5 or so blocks.

@Argo - sounds good, any good advice on finding space, guess checking blocks above?

@Pauler - With your AABB, do you check every block?

Thanks guys