Voxel - a start

Hi,

Only just started to use LWJGL and OpenGL (I’m use to using Direct3D…).

I’ve decided as a challenge to create a voxel engine, who isn’t?! What I have at the
moment is rendering 15x15x15 cubes within a skybox. I’ve done a camera so you can
move around the cubes and the skybox rotates accordingly.
Now, I need some advice…What is my next step?
Would it be:

Convert drawing cubes from display lists to VBO?

or

Create a chunk class, so draw chunks of cubes? (Any good articles on this?)

Thanks,
Steve

Either would be good.

Try to make chunks a power of 2 (probably 16x16x16)

Im currently also (struggling) to do the same thing as you. 16^3 chunks are the best way to go. I havent figured out how to do my cube offsets yet, but when genning a chunk, you need to offset the cubes and then translate the chunk, dont translate the individual cubes. Wish I could figure it out!

Am I correct in stating that a chunk is a big cube of cubes?

A ‘Chunk’ is simply a piece (‘chunk’) of a game-world, a file, a hypertable, or anything that is really big.

  • Longor1996

Ok, and in this context, a lot of cubes?

Thanks

In this context, it is. However, it can still be anything else.

When making chunks, do you have blocks in there that are inactive, thus these don’t get created?

A chunk is a division of the world.

If you just do everything cube by cube, that’s (in a 16^3 world) 4096 draw calls (assuming one call per cube)

But if you do everything by the entire world, a single change requires (in a 256^3 world) 16777216 cubes to be re-drawn.
And you also make it impossible for the world to be infinite.

That’s why there is a ‘halfway’ approach. Not too big, not too small.

Ok, so send 16x16x16 in one go to the gnu, take it this is done via VBO and glDrawArrays?

How do you get these ‘chunks’ to be different heights - this through a height map (an image made from some form of noise)?

Thanks all and sorry for so many questions!

What do you mean with ‘chunks being different heights’?
If you mean terrain generation, you should take a look into simplex/fractal/perlin noise.

  • Longor1996

Sorry, was thinking incorrectly, the ‘landscape’ is made up from the blocks and by having blocks active and inactive gives the different ‘heights’ in chunks?..

Not sure what you mean, but no, the height is created by some simplex or perlin noise or something similar. Inactive and active blocks don’t affect terrain generation. I don’t really know what you mean by inactive or active blocks though…

Incative and active blocks I mean, inactive would mean this is ‘air’ and won’t be drawn.

I’m fine with using heightmaps for terrain generation, but for something along the lines of mine craft, how is this landscape generated…

Markus describes the technique he used in Minecraft here.

Thanks for the link, interesting read.

I use to use 2d height map when generating terrain. Still unsure how you would use one for rendering blocks…maybe it is late and I need some sleep ::slight_smile:

Atm, I just render 15x15x15 cubes, no height map involved, thus get one large cube, this is my renderTheWorld method:


private void renderTheWorld()
	{
		for (int x = 0; x < xAmount; x++) {
			for (int y = 0; y < yAmount; y++) {
				for (int z = 0; z < zAmount; z++) {
					glCallList(voxelList);  // display list	
					glTranslatef(0f, 0.0f, 2f);
				}
				glTranslatef(0f, 2f, -zAmount * 2f);
			}
			glTranslatef(2f, -yAmount * 2f, 0);
		}
	}

This gives me this:


https://sites.google.com/site/gwgamedevelopment/

How do I apply heights to the blocks?..

Like we’ve said, you need to use some noise algorithm to generate the heights. It doesn’t have to be a super advanced one, you can use Random(), but you can’t just arbitrarily create height values.

Edit:
Also, combine all your

glTranslatef()

into one instead of having three different calls to it.

Article on Simplex Noise

To use it:


int height = (int) (SimplexNoise.noise(x/16F, y/16F)*16F);

You can change the 16s to whatever you want to see what happens.

Try not to use glTranslatef all the time. (only use it for moving the player around)
Just change the coordinates of the cubes you’re rendering.

Thanks,

So, just use on glTranslatef to position all the cubes? I take it need to modify the loops then?

Do I specify the height withing the glTranslate?

Thanks,
Steve

Am I thinking correctly here, the height you get from height map is for how many voxels you draw upwards if that makes any sense? i.e. the y-amount? Say the voxels which are just cubes, I get the number 20 from the height map, I draw 20 cubes on top of each other?

Thanks