Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2 3 ... 7
  ignore  |  Print  
  Voxel - a start  (Read 21717 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Member


Medals: 1



« Posted 2013-03-08 20:26:28 »

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
Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-03-08 20:28:34 »

Either would be good.

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

Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #2 - Posted 2013-03-08 20:31:33 »

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!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Member


Medals: 1



« Reply #3 - Posted 2013-03-08 22:52:56 »

Am I correct in stating that a chunk is a big cube of cubes?
Offline Longor1996
« Reply #4 - Posted 2013-03-08 23:03:37 »

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

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Member


Medals: 1



« Reply #5 - Posted 2013-03-08 23:05:59 »

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

Thanks
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #6 - Posted 2013-03-08 23:20:52 »

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

Offline steg90

Senior Member


Medals: 1



« Reply #7 - Posted 2013-03-08 23:30:33 »

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

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #8 - Posted 2013-03-08 23:34:36 »

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.

Offline steg90

Senior Member


Medals: 1



« Reply #9 - Posted 2013-03-08 23:39:04 »

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!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longor1996
« Reply #10 - Posted 2013-03-08 23:41:12 »

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 for my bad English! That's because i am from Germany.
Offline steg90

Senior Member


Medals: 1



« Reply #11 - Posted 2013-03-08 23:43:32 »

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?...
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #12 - Posted 2013-03-08 23:48:04 »

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...

Offline steg90

Senior Member


Medals: 1



« Reply #13 - Posted 2013-03-08 23:50:41 »

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...
Offline dapy
« Reply #14 - Posted 2013-03-08 23:56:01 »

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.
Offline steg90

Senior Member


Medals: 1



« Reply #15 - Posted 2013-03-09 00:16:10 »

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  Roll Eyes

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
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?...
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #16 - Posted 2013-03-09 01:18:22 »

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
1  
glTranslatef()
into one instead of having three different calls to it.

Offline HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #17 - Posted 2013-03-09 01:44:57 »

Article on Simplex Noise

To use it:

1  
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.

Offline steg90

Senior Member


Medals: 1



« Reply #18 - Posted 2013-03-09 11:11:08 »

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
Offline steg90

Senior Member


Medals: 1



« Reply #19 - Posted 2013-03-10 19:30:14 »

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



Offline Agro
« Reply #20 - Posted 2013-03-10 19:34:37 »

Plus, only render cubes that are in your line of sight and your "rendering distance"

Offline steg90

Senior Member


Medals: 1



« Reply #21 - Posted 2013-03-10 20:14:10 »

Hi Agro,

So, was I correct in what I was saying?

And what do you mean about rendering distance?

Thanks
Offline Agro
« Reply #22 - Posted 2013-03-10 20:16:11 »

Like, the world can go on forever and forever, miles and miles of blocks. You shouldn't render any of the blocks you can't see. If you do, its plain useless since you can't see it or interact with it.

Minecraft adds an option to set your render distance. Tiny only renders a few blocks around you, then short, then normal then far.

Offline steg90

Senior Member


Medals: 1



« Reply #23 - Posted 2013-03-10 20:32:44 »

Yes, that is ok, not up to that bit of the code yet though, i.e. optimisation - still need to put my cubes / geometry into VB's!  At the mo still in display list.

Was just asking the question that am I correct in saying that the value you get from the height map you use to draw y amount of cubes?
Offline Agro
« Reply #24 - Posted 2013-03-10 20:39:34 »

Yes, that is the Y value (or amount of cubes) that will be in that height.

But notice that if you use 2D simplex or perlin noise, you cannot achieve caves or things that areas that have depth within other areas.

Offline steg90

Senior Member


Medals: 1



« Reply #25 - Posted 2013-03-10 20:42:57 »

Yes, will need to use something else for caves, anyone any suggestions??

Also, anybody know how to draw the voxels using one glTranslate?  As you can see
from my code snippet in my posts, I make three glTranslate calls for x, y and z.
Offline Agro
« Reply #26 - Posted 2013-03-10 20:49:07 »

Yeah, for caves, just use 3D simplex or perlin noise.

Offline steg90

Senior Member


Medals: 1



« Reply #27 - Posted 2013-03-10 21:03:12 »

Will need to look at that when get the basic landscape up.

Any clues on using less glTranslates?...
Offline Longor1996
« Reply #28 - Posted 2013-03-10 21:11:21 »


How about that?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
private void renderTheWorld()
   {
      for (int x = 0; x < xAmount; x++) {
         for (int y = 0; y < yAmount; y++) {
            for (int z = 0; z < zAmount; z++) {
               glTranslatef(x*2,y*2,z*2);
               glCallList(voxelList);  // display list  
              glTranslatef(x*-2,y*-2,z*-2);
            }
         }
      }
   }


I don't have time to test it, but it should work.

- Longor1996


PS: This is the most easy approach to render voxels, but it is also the most memory/calculationpower consuming approach.

Sorry for my bad English! That's because i am from Germany.
Offline steg90

Senior Member


Medals: 1



« Reply #29 - Posted 2013-03-10 21:28:35 »

Hey thanks for that - works fine.

I'm taking it also, we need to store the height in some array for each of the chunks and then when rendering the voxels in the update loop, use the heights we have stored in this array? Chunks being 16x16x16.

int heights[] = new int[16*16];  // will hold the height we generate from SimplexNoise or whatever

Thanks again,
Steve

Pages: [1] 2 3 ... 7
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (12 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (28 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!