any possibility of a download link? looks good so far, but we can't do much without a download!

Busy between school, work, life, games, programming and general screwing around.If you'd like some pixel art for your game, send me a PM, i'll see what I can do.Current project: http://elementalwarblog.wordpress.com/

I don't know if it's the best or 'correct' method, but what I usually do for mouse-look is in a first-person game is this:

1) read the relative X/Y movement values of the mouse2) use these values to change 2 rotation angle values of your Player object that define where he is looking: Add the relative X movement of the mouse to the rotation angle of your Player class that defines the rotation along the Y axis. Add the relative Y movement of the mouse to the value that defines the rotation along the X axis.3) when rendering the 3D scene, the first thing you do is call glTranslate to put the player at the correct position (using its x,y,z location values)4) after that, use glRotate to rotate the camera along the Y and X axis using your 2 rotation angle values in your Player object.5) when you press forward while the player is on the ground, use one of your rotation angle values (the one that defines the rotation along the Y axis) in your Player object to calculate the updated position.

Like I said, I don't know if it's the best method (I'm hardly a 3D expert), but it works for me and is quite easy.

Thank you erikd... Yes that is the way i am going to do it. I have made a start. Just need to do the bit of maths to get that fully working. Thank you for your time, that reasurres me that im aproaching it correctly.

Update:I have made the 3d camers, you can now walk around. mouse look really done, but you can click on left/right of screen to turn.. keys wasd, r & f (look up / down)Blocks have basic collision detection. Jumping is rubish atm, but it was to test the height collision. whole project will be refactored soon, to make way for chunks, and VBO's

I've been trying to do the same thing as you're doing for a long time, could you possibly post some of your chunk code? I.E. the actual creation of your blocks and how you place them? I use

1

glTranslatef()

, but thats horribly slow and I cant seem to figure out the offsets to correctly render the blocks. If you could help at all I would be very grateful!

There is a post (a recent one) that can help you out on how to generate chunks and place them: http://www.java-gaming.org/topics/voxel-a-start/28942/view.htmlDon't hesitate to look into the "OpenGL Development" section of the site, you'll find many pieces of information.You can use display list (instead of VBO) for a start, it's a bit easier to understand and brings some really good performance.

I've been trying to do the same thing as you're doing for a long time, could you possibly post some of your chunk code? I.E. the actual creation of your blocks and how you place them? I use

1

glTranslatef()

, but thats horribly slow and I cant seem to figure out the offsets to correctly render the blocks. If you could help at all I would be very grateful!

There is 2 parts to your question.

My chunks have these main properties. The x and z store the chunks position relative to 0,0. so a chunk may be -3,9 which is (-3*16) blocks in X and (9*16) in z

then the blocks are bytes, storing the block ID ie 1 for grass or something. 0 for Air.

1 2 3

privateintx;privateintz;privatebyte[][][] chunk;

The blocks are then say 4,3,7 so it position in the game world is (-3*16)+4 , 3 , (9*16)+7

The chunks have a method to set and get blocks

1 2 3 4 5 6 7 8 9

publicintgetblockID(intx,inty, intz){returnchunk[x][y][z]; }

publicvoidsetblockID(intx,inty, intz,byteid){

chunk[x][y][z]=id;

}

at the moment I declare chunks manually with chunks[4] = new Chunk(-1,-1,"AE");as you see I have an array of chunks to store them. the "AE" is for the file of that chunk to save it.the (-1,-1) are the positions as described above.

With regard to drawing the blocks. - Im drawing them 1 at a time which is not the best way,

but yes, you have to reset the view, then translate each block.

Optimisation inclue:Cull faces,Make a display list and render all the chunk as 1 objectRender the chunk as a VBODont send chunks to draw that are behind youwhen drawing block faces - check for adjacent blocks first..you may not need to draw them

I've been trying to do the same thing as you're doing for a long time, could you possibly post some of your chunk code? I.E. the actual creation of your blocks and how you place them? I use

1

glTranslatef()

, but thats horribly slow and I cant seem to figure out the offsets to correctly render the blocks. If you could help at all I would be very grateful!

There is 2 parts to your question.

My chunks have these main properties. The x and z store the chunks position relative to 0,0. so a chunk may be -3,9 which is (-3*16) blocks in X and (9*16) in z

then the blocks are bytes, storing the block ID ie 1 for grass or something. 0 for Air.

1 2 3

privateintx;privateintz;privatebyte[][][] chunk;

The blocks are then say 4,3,7 so it position in the game world is (-3*16)+4 , 3 , (9*16)+7

The chunks have a method to set and get blocks

1 2 3 4 5 6 7 8 9

publicintgetblockID(intx,inty, intz){returnchunk[x][y][z]; }

publicvoidsetblockID(intx,inty, intz,byteid){

chunk[x][y][z]=id;

}

at the moment I declare chunks manually with chunks[4] = new Chunk(-1,-1,"AE");as you see I have an array of chunks to store them. the "AE" is for the file of that chunk to save it.the (-1,-1) are the positions as described above.

With regard to drawing the blocks. - Im drawing them 1 at a time which is not the best way,

but yes, you have to reset the view, then translate each block.

Optimisation inclue:Cull faces,Make a display list and render all the chunk as 1 objectRender the chunk as a VBODont send chunks to draw that are behind youwhen drawing block faces - check for adjacent blocks first..you may not need to draw them

Im happy to share and bits that may help.

Hmm actually very helpful, however the only part I'm having trouble with is using offsets to render my blocks within the chunk. I use VBOs and I just can't seem to render out two chunks without hitting 1 fps! Here's a run down of my chunk class right now:

I have three nested for loops that call a class that creates cubes. Like this:

Hi opiop65,I will upload my rendering code tomorrow. Had a quick look at ur code, firstly I notice that you are making lots of cube objects in your chunks.I don't know what's in your cube class, but the data that your storing may only need to be 1 byte rather than making a copy of the entire cube class for each block.

I'll post code tomorrow, but its something like

If(ID==3) cube.render( with texture perimeters' and so on)

But all my array has is 1 byte for each cube. My cube class is only created once.

I just wanted to say that there is an even faster way to render an chunk,without using glTranslate at all.

It's actually quite simple:First, you need to make a "ChunkRenderer" Class,this class simply wraps all opengl draw commands that are neede to, well, draw stuff!The important thing is, that the wrapper-method that draws vertices, applys a translation vector to them.

Is that the total amount of chunks or the total amount of blocks in the x axis? Sorry, I'm a little confused right now :/ I thought up some code last night where I pretty much draw cubes like this(pseudo code):

That might not format very well... but anyway, that was just some of pseudo code. Is that bad? All I do is draw vertices and add 16(the blocksize) to some vertices to achieve the 3D effect. So when I need to get to draw the vertex of the bottom front face, I just do something like this:

1

(x + offSet, z, y)

offSet is then increased by 16 to be able to access the other vertices. Is that bad?

It doesnt matter what the Renderer implementation does.Im using Display Lists in Puzzlez Project, because VBO just never work for me.If you wan't to use VBO's, the same Code can be used with just a few modifications.In Puzzlez Project, im using a Abstract Renderer Class that does all the Chunk Rendering.

Is that the total amount of chunks or the total amount of blocks in the x axis? Sorry, I'm a little confused right now :/ I thought up some code last night where I pretty much draw cubes like this(pseudo code):

That might not format very well... but anyway, that was just some of pseudo code. Is that bad? All I do is draw vertices and add 16(the blocksize) to some vertices to achieve the 3D effect. So when I need to get to draw the vertex of the bottom front face, I just do something like this:

1

(x + offSet, z, y)

offSet is then increased by 16 to be able to access the other vertices. Is that bad?

chunkTotalPosX/Y/Z is the Total Position of the Chunk in the Worldspace.That means that the "TotalPos" is just the chunk coordinates multiplied by the chunksize.

The problem with glTranslate is:It is just a big waste of memory and calculation time!If you use glTranslate, the Graphicscard has to calculate a lot more, because every block is a single mesh.If you send the blocks already translated to the Graphicscard, the Graphicscard can render the chunk as a single big mesh wich is much faster.

I too, tryed to draw blocks with glTranlste first, then realised it is insaneley slow with big amounts of blocks.Just think of this:How many blocks are on the screen in Minecraft?A thousand? A ten-thousand? No, it goes into the millions!

If you would use a glTranslate for every single block,this would simply not be possible anymore.

Enough explanation why using glTranslate for every single block is the worst possible idea?

It kind of does matter whether you use immediate mode or display lists/VBOs/VAOs.

Quote

The problem with glTranslate is:It is just a big waste of memory and calculation time!If you use glTranslate, the Graphicscard has to calculate a lot more, because every block is a single mesh.If you send the blocks already translated to the Graphicscard, the Graphicscard can render the chunk as a single big mesh wich is much faster.

Those points are true, but your solution of immediate mode is even worse.

Quote

The problem with immediate mode is:It is just a big waste of memory and calculation time!If you use glTranslate(), the Graphicscard has to calculate a little more, because every block is a single mesh.If you send the blocks already translated to the Graphicscard, the Graphicscard can render the chunk as a single big mesh which is much faster. But if you use immediate mode, you aren't sending them to the graphics card as a single big mesh, so it is much slower

I think that if you are going to help, help people go forwards, not backwards.If you actually are using VBOs, use VBOs in the example. Otherwise it's misleading.

Anyway:

@OP: I recommend using VBOs.Here's the most bare-bones implementation I could find from my old code.Note that it renders tiles, not voxels. It can be adapted quite easily for 3D though.

is terrible! I'm trying to convert all my code over to offsets, just like in my pseudo code. That's why I'm confused, you keep talking about glTranslatef(), but it wasn't anywhere in my code! I was just wondering if increasing offSet like this:

1

offSet += 16

and then drawing like this:

1

(x + offSet, z + offSet, y)

(which would draw the bottom left corner of the back face of the cube). I don't see how that is bad, but you keep saying it is!

It kind of does matter whether you use immediate mode or display lists/VBOs/VAOs.

Quote

The problem with glTranslate is:It is just a big waste of memory and calculation time!If you use glTranslate, the Graphicscard has to calculate a lot more, because every block is a single mesh.If you send the blocks already translated to the Graphicscard, the Graphicscard can render the chunk as a single big mesh wich is much faster.

Those points are true, but your solution of immediate mode is even worse.

Quote

The problem with immediate mode is:It is just a big waste of memory and calculation time!If you use glTranslate(), the Graphicscard has to calculate a little more, because every block is a single mesh.If you send the blocks already translated to the Graphicscard, the Graphicscard can render the chunk as a single big mesh which is much faster. But if you use immediate mode, you aren't sending them to the graphics card as a single big mesh, so it is much slower

I think that if you are going to help, help people go forwards, not backwards.If you actually are using VBOs, use VBOs in the example. Otherwise it's misleading.

Anyway:

@OP: I recommend using VBOs.Here's the most bare-bones implementation I could find from my old code.Note that it renders tiles, not voxels. It can be adapted quite easily for 3D though.

And i don't care about that.The OP can use whatever method he wants to draw his vertices.If it is IntermdiateMode, DisplayLists or VBO's, that's his decision.I use DisplayLists, because VBO's never work for me, and let that be my problem.

is terrible! I'm trying to convert all my code over to offsets, just like in my pseudo code. That's why I'm confused, you keep talking about glTranslatef(), but it wasn't anywhere in my code! I was just wondering if increasing offSet like this:

1

offSet += 16

and then drawing like this:

1

(x + offSet, z + offSet, y)

(which would draw the bottom left corner of the back face of the cube). I don't see how that is bad, but you keep saying it is!

@OPWoops, Sorry for the confusion!

Yes,I say that using glTrnslate per Block is bad.No, im not saying that offsets are bad.

Actually, the Block Translation (The Offset of the Block in the world) is done by the ChunkRenderer per vertex.Means that:Every time you "draw" a vertice, the vertice will be drawen with an offset.The "offset" is the global position of the block in the world.From what i understand, your blocks have a size of 16, and your chunks are made up of 16x16x16 blocks, is that right?

// Draw the Top Surface of the Block// (Your blocks are 16 units big, right? So let's draw the top surface)this.drawVertex(0,16,0);this.drawVertex(16,16,0);this.drawVertex(16,16,16);this.drawVertex(0,16,16);

I can't really explain it very good, because my english is not the best.Just ask as many questions as possible!Im better in explaining stuff piece by piece than explaining everything at once.

- Longor1996

PS: How you draw a vertice doesn't matter and i really don't care about that part.Use VBO's: They are faster, but more complicated to use.Use DisplayLists: They are easier to use, but slower because of intermediate-mode.Use Textures: I tried that once, it works too, but it is utterly complicated.

So I played around with offSets a little, but I ran into a few problems. First, I'm going to apologize for using immediate mode, I didn't feel like using VBOs because this is just a little test. Second, here's a picture of the cube:Looks fine!But then I enable

1

glEnable(GL_CULL_FACE)

I then cull the back face and the cube ends up looking like this:Obviously, the faces are screwed up. I render out my faces like this:

Firstly Opi, Im using Immediate mode at the moment. I know its not the best but I'm learning too, and it a good way to learn some basics.I think you must be drawing the vertices in the wrong order. You can specify which - back or front to cull. here is my intermediate cube, It does not have offsets for translation (yet)but it has offsets for texture, to allow drawing of tiles.

size: is size of the texture ie= 0.25 of the width h and voffsett are the offest sizes so maybe 0.5f and 0.25 to select which tile it is on the texture sheet.

GL11.glTexCoord2f(Hoffset + size, Voffset + size); GL11.glVertex3f(-i, -i, -i); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset + size, Voffset ); GL11.glVertex3f(-i, i, -i); // Top Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset ); GL11.glVertex3f(i, i, -i); // Top Left Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset + size); GL11.glVertex3f(i, -i, -i); // Bottom Left Of The Texture and Quad

// Top Face

GL11.glNormal3f(0.0f, i, 0.0f); // Normal Pointing Up

GL11.glTexCoord2f(Hoffset, Voffset + size); GL11.glVertex3f(-i, i, -i); // Top Left Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset);GL11.glVertex3f(-i, i, i); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(Hoffset + size, Voffset); GL11.glVertex3f(i, i, i); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset + size, Voffset + size);GL11.glVertex3f(i, i, -i); // Top Right Of The Texture and Quad

// Bottom Face

GL11.glNormal3f(0.0f, -i, 0.0f); // Normal Pointing Down

GL11.glTexCoord2f(Hoffset + size,Voffset + size); GL11.glVertex3f(-i, -i, -i); // Top Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset + size); GL11.glVertex3f(i, -i, -i); // Top Left Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset);GL11.glVertex3f(i, -i, i); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(Hoffset + size, Voffset); GL11.glVertex3f(-i, -i, i); // Bottom Right Of The Texture and Quad

// Right face

GL11.glNormal3f(i, 0.0f, 0.0f); // Normal Pointing Right

GL11.glTexCoord2f(Hoffset + size, Voffset + size); GL11.glVertex3f(i, -i, -i); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset + size, Voffset);GL11.glVertex3f(i, i, -i); // Top Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset); GL11.glVertex3f(i, i, i); // Top Left Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset + size); GL11.glVertex3f(i, -i, i); // Bottom Left Of The Texture and Quad

// Left Face

GL11.glNormal3f(-i, 0.0f, 0.0f); // Normal Pointing Left

GL11.glTexCoord2f(Hoffset,Voffset + size); GL11.glVertex3f(-i, -i, -i); // Bottom Left Of The Texture and QuadGL11.glTexCoord2f(Hoffset + size,Voffset + size); GL11.glVertex3f(-i, -i, i); // Bottom Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset + size,Voffset);GL11.glVertex3f(-i, i, i); // Top Right Of The Texture and QuadGL11.glTexCoord2f(Hoffset, Voffset); GL11.glVertex3f(-i, i, -i); // Top Left Of The Texture and QuadGL11.glEnd(); }

My next move is to switch to VBO. Thank you everyone for all the code you have put on, when(if) i get it working ill pop that on. I am doing a lot a glTranslate atm, and im going to change that to 1 per chunk. Then see how that goes with VBO's. Im happy to share stuff, but you have also to remember Im just having fun getting things to work, and learning, so the solutions I present may not be the best, but with all your discussions, input, sharing of solutions and problems hopefully we can all learn what we want.

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