Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  LWJGL BlockWorld  (Read 33567 times)
0 Members and 1 Guest are viewing this topic.
Offline Vermeer

JGO Coder


Medals: 16



« Posted 2013-02-28 21:20:51 »

Im trying to learn some basic 3D programming, so I'm attemping to make a small mincraft like game. It just a small personal project to learn and have fun coding.

Made cubes, added texture, moveable camera.

Next to do: create a dummy object to attach the camera too, create basic terrain generation, add extra chuncks!

I think I can do this... but any suggestions on creating a First Person view would be welcome!





Latest update
<a href="http://www.youtube.com/v/bVLixGQIwP4?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/bVLixGQIwP4?version=3&amp;hl=en_US&amp;start=</a>
Offline cheatsguy

Junior Devvie


Medals: 3


Gamer turned Pixel Artist turned Programmer


« Reply #1 - Posted 2013-03-02 00:37:27 »

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/
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #2 - Posted 2013-03-02 00:44:46 »

Download link and maybe some source code? I'm very interested in making my own cube game, but I'm having trouble with textures!

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

JGO Kernel


Medals: 310
Projects: 11
Exp: 3 years


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


« Reply #3 - Posted 2013-03-02 06:05:36 »

What exactly is your problem with the first person view?

Offline Vermeer

JGO Coder


Medals: 16



« Reply #4 - Posted 2013-03-02 15:24:22 »

Thank you for reading my post.

I just want to tidy the code up and do a little more, then in a day or two I will post the source and link to a runnable jar.

What exactly is your problem with the first person view?

I'm going to have a try at this, and let you know, I am expecting mouse look to be the main issue!

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #5 - Posted 2013-03-03 13:43:38 »

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 mouse
2) 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.

Offline Vermeer

JGO Coder


Medals: 16



« Reply #6 - Posted 2013-03-03 19:32:15 »

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 made a mistake - I used the devil texture loader, and runnable jars dont seem to like it.
So i have uploaded the elcipse project as a jar file - just unzip!
http://www.java-gaming.org/user-generated-content/members/167679/block3d.jar

I made a short video so you can see where its at.


<a href="http://www.youtube.com/v/8jDsvqzCC7o?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/8jDsvqzCC7o?version=3&amp;hl=en_US&amp;start=</a>

Online Agro
« Reply #7 - Posted 2013-03-03 19:58:30 »

http://www.java-gaming.org/topics/creating-a-3d-camera/27906/view.html

Offline Vermeer

JGO Coder


Medals: 16



« Reply #8 - Posted 2013-03-03 20:54:52 »




Thanks for that link. That is exactly what I need! There are some fantastic resources and help on this forum.

I will try and implement that tomorrow. Smiley
Offline Vermeer

JGO Coder


Medals: 16



« Reply #9 - Posted 2013-03-07 11:53:50 »

Update:

Changed texture loader to Slick-Util
Support for sprite sheet textures or single textures
Change UVmapping to allow differnt textures on different faces
Added fog
Added chunks
Added First Person View with mouse look
Added a very basic building with helper cube (not fully implimented) (unitil 3d picking)

Lots to do, hoping to have webstart version and playable jar in next update.

<a href="http://www.youtube.com/v/4xUYis3BpQA?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/4xUYis3BpQA?version=3&amp;hl=en_US&amp;start=</a>

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longor1996
« Reply #10 - Posted 2013-03-11 18:05:30 »

If you need block-picking in a uniform grid,
i recommend the bresenham-algorhytm.
Its fast and easy.

- Longor1996

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

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #11 - Posted 2013-03-11 20:36:19 »

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!

Offline Tim Spekler

« JGO Spiffy Duke »


Medals: 58
Projects: 2
Exp: 4 years



« Reply #12 - Posted 2013-03-11 21:01:12 »

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.html
Don'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.
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #13 - Posted 2013-03-12 20:39:46 »

It's funny, I actually contributed a little to that thread Tongue Thanks for the link though! I read over it again and I think I'm ready to have another try at it.

Offline Vermeer

JGO Coder


Medals: 16



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

If you need block-picking in a uniform grid,
i recommend the bresenham-algorhytm.
Its fast and easy.

- Longor1996
Thanks for that, ive used that in a 2d game, and for raycasting before. I will probably use this again.


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!

Sure I will share any bits....Ill do that after this update..........


Update:Added jumpin, Added player holding block, added collision, added gui placeholder,
                                 added bitmap rendering, added loading and saving of world and all chunks,
                                 added basic 3d picker, placeable different blocks


To do: need to optimise rendering next, and make the 3d picker work correctly.

<a href="http://www.youtube.com/v/G0aY1arrrCQ?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/G0aY1arrrCQ?version=3&amp;hl=en_US&amp;start=</a>

Video is a little slow, game runs at 160fps (need a lot of optimising) but only 30fps while video capturing!

Offline Vermeer

JGO Coder


Medals: 16



« Reply #15 - Posted 2013-03-14 14:31:38 »

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  
   private int x;
   private int z;
   private byte[][][] 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  
    public int getblockID(int x,int y, int z){
      return chunk[x][y][z];
   }
   
   public void  setblockID(int x,int y, int z,byte id){
     
      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 object
Render the chunk as a VBO
Dont send chunks to draw that are behind you
when drawing block faces - check for adjacent blocks first..you may not need to draw them

Im happy to share and bits that may help.
Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #16 - Posted 2013-03-14 20:27:22 »

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  
   private int x;
   private int z;
   private byte[][][] 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  
    public int getblockID(int x,int y, int z){
      return chunk[x][y][z];
   }
   
   public void  setblockID(int x,int y, int z,byte id){
     
      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 object
Render the chunk as a VBO
Dont send chunks to draw that are behind you
when 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:
1  
2  
3  
4  
5  
6  
7  
8  
for(int x = 0; x < CHUNK_WIDTH; x++){
for(int z = 0; z < CHUNK_DEPTH; z++){
for(int y = 0; y < CHUNK_HEIGHT; y++){
glTranslatef(x, z, y);
cube = new BaseCube();
}
}
}

Or something along the lines of that, its pseudo code. Then, I create a new chunk to store the cubes in like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
private void newChunk(){
      glBindBuffer(GL_ARRAY_BUFFER, vbo.vboVHandle);
      glVertexPointer(3, GL_FLOAT, 0, 0L);
     
      glBindBuffer(GL_ARRAY_BUFFER, vbo.vboCHandle);
      glColorPointer(3, GL_FLOAT, 0, 0);
     
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);
      for(int x = 0; x < var1; x++){
         for(int z = 0; z < var2; z++){
            for(int y = 0; y < var3; y++){
               glPushMatrix();
               glTranslatef(x, y, z);
               glDrawArrays(GL_QUADS, 0, 24);
               glPopMatrix();
            }
         }
      }
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
   }

Its a terrible way to do it obviously, though, because I call
1  
glTranslatef
for 4096 blocks, and then I call it again to translate the chunk. It just isn't efficient. I was wondering if you used offSets instead of
1  
glTranslatef()
? So for instance, I could do something like this:
1  
2  
3  
4  
5  
6  
private float[] makeCube(float x, float y, float z)
   {
      int offset = Block.SIZE / 2;
      return new float[]
      { x + offset, y + offset, z, x - offset, y + offset, z, x - offset, y + offset, z - Block.SIZE, x + offset, y + offset, z - Block.SIZE, x + offset, y - offset, z - Block.SIZE, x - offset, y - offset, z - Block.SIZE, x - offset, y - offset, z, x + offset, y - offset, z, x + offset, y + offset, z - Block.SIZE, x - offset, y + offset, z - Block.SIZE, x - offset, y - offset, z - Block.SIZE, x + offset, y - offset, z - Block.SIZE, x + offset, y - offset, z, x - offset, y - offset, z, x - offset, y + offset, z, x + offset, y + offset, z, x - offset, y + offset, z - Block.SIZE, x - offset, y + offset, z, x - offset, y - offset, z, x - offset, y - offset, z - Block.SIZE, x + offset, y + offset, z, x + offset, y + offset, z - Block.SIZE, x + offset, y - offset, z - Block.SIZE, x + offset, y - offset, z };
   }

I copied that from a different thread. However, it doesn't work. Can I see your actual block rendering code to see how you do yours?
Thanks!

Offline Vermeer

JGO Coder


Medals: 16



« Reply #17 - Posted 2013-03-14 21:43:18 »

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.
Offline Longor1996
« Reply #18 - Posted 2013-03-15 17:18:25 »

Hi there!

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.

Basically this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
class ChunkRenderer{
    float tx = 0F;
    float ty = 0F;
    float tz = 0F;
   
    public void setBlockTranslation(int blockX,int blockY,int blockZ){
        tx = blockX;
        ty = blockY;
        tz = blockZ;
    }
   
    public void drawVertex3d(float x, float y,float z){
        GL11.glVertex3d(tx+x,ty+y,tz+z); //This can be replaced with a method that adds the vertex to an vertexbuffer.
    }
}


I use this method in Puzzlez Project, and its very (very) fast.
I can render ~400 (16³m) Chunks at 350 FPS and without a single glTranslate!

- Longor1996

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

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #19 - Posted 2013-03-15 20:11:59 »

Thank you very much! So would I add my block size to tx every time I want to draw a new cube? So for instance:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
class ChunkRenderer{
    float tx = 0F;
    float ty = 0F;
    float tz = 0F;
   
    public void setBlockTranslation(int blockX,int blockY,int blockZ){
        tx = blockX;
        ty = blockY;
        tz = blockZ;
    }
   
    public void drawVertex3d(float x, float y,float z){
        GL11.glVertex3d(tx+x,ty+y,tz+z); //This can be replaced with a method that adds the vertex to an vertexbuffer.
        tx += 16;
        ty += 16;
        tz += 16;
}
}

(16 is my block size). Would you do it like that?

Offline Longor1996
« Reply #20 - Posted 2013-03-15 20:28:16 »

No.

Your Chunk Rendermethod should look like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public void render(???){
    // Create a new ChunkRenderer
    ChunkRenderer renderer = new ChunkRenderer();
   
    // FOR every_block_in_chunk DO render_block
      for(int x = 0; x < var1; x++){
         int gx = chunk.chunkTotalPosX + x;
         for(int z = 0; z < var2; z++){
            int gz = chunk.chunkTotalPosZ + z;
            for(int y = 0; y < var3; y++){
                int gy = chunk.chunkTotalPosY + Y;
               
                // Translate to the Blocks global Position
                renderer.setBlockTranslation(gx,gy,gz);
               
                // Then Render the Block using the renderer
                //When you render a vertex using the renderer, it will be translated by the global block position
            }
         }
      }
}


You must NOT translate anything!
All translations are done by the ChunkRenderer
This would just terminate the sense behind using a ChunkRenderer.


For Example:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public void render(Chunk chunk){
    // Create a new ChunkRenderer
    ChunkRenderer renderer = new ChunkRenderer();
   
    // FOR every_block_in_chunk DO render_block
      for(int x = 0; x < var1; x++){
         int gx = chunk.chunkTotalPosX + x;
         for(int z = 0; z < var2; z++){
            int gz = chunk.chunkTotalPosZ + z;
            for(int y = 0; y < var3; y++){
                int gy = chunk.chunkTotalPosY + Y;
               
                // Translate to the Blocks global Position
                renderer.setBlockTranslation(gx,gy,gz);
               
                // Then Render the Block using the renderer
                //When you render a vertex using the renderer, it will be translated by the global block position
                int blockID = chunk.getBlock(x,y,z);
               
                renderer.renderBlock();
            }
         }
      }
}


The Block render Method would look like this (only for top surfaces):
1  
2  
3  
4  
5  
6  
7  
8  
9  
public void renderBlock(){
   
    // This would just draw the topside of the block
    // Notice how the vertex coordinates are local for the block
    drawVertex3d(0,1,0);
    drawVertex3d(1,1,0);
    drawVertex3d(1,1,1);
    drawVertex3d(0,1,1);
}


Important:
This can be optimized even more.
But that's for you to find out!

- Longor1996

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

JGO Kernel


Medals: 310
Projects: 11
Exp: 3 years


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


« Reply #21 - Posted 2013-03-15 20:31:41 »

Please don't tell me you are using immediate mode.

PLEASE!

PLEASE!!!!!

PLEASE!!!!!!!!!!!!!!!!

Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #22 - Posted 2013-03-15 20:45:02 »

Whats the problem with doing it the way I did it? If I don't use
1  
glTranslatef()
then isn't it ok? And another question, what is
1  
chunkTotalPosX
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):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public Chunk(int var1, int var2, int var3){
Block block;

int offset = 0;
for(int x = 0; x < var1; x++){
//do all the for loops
block = new Block(offset, offset, offset);
offSet += 16;
}
}

Then the block:
1  
2  
3  
4  
5  
6  
7  
FloatBuffer verticeData;
public Block(int xOffSet, int zOffSet, int yOffSet){
//vbo stuff
verticeData.put(x, z, y,
                     x + offSet, z, y
                    //do rest of faces
}


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?

Offline Longor1996
« Reply #23 - Posted 2013-03-15 20:54:39 »

Please don't tell me you are using immediate mode.

PLEASE!

PLEASE!!!!!

PLEASE!!!!!!!!!!!!!!!!

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.

Example:
1  
2  
3  
4  
public interface IChunkTessellator{
    public abstract void drawVertex(float x,float y,float z);
    public abstract void drawVertex(float x,float y,float z,float u,float v);
}


Then i just make an implementation:
1  
2  
3  
4  
5  
6  
7  
8  
9  
public class ChunkTessellator_DisplayList {
    public void drawVertex(float x,float y,float z){
        GL11.glVertex3f(tx+x,ty+y,tz+z);
    }
    public abstract void drawVertex(float x,float y,float z,float u,float v){
        GL11.glTexCoord2f(u,v);
        drawVertex(x,y,z);
    }
}


I could also just make an implementation that uses VBO's to render Chunks.

Fun Fact:
My whole Render System is so abstract, i could just use it with directX!
Is that enough explanation?


(Small Edit here: I would never replace my core-renderer with directX, that would be way too much work for me, but i could do it if i was insane!)


Whats the problem with doing it the way I did it? If I don't use
1  
glTranslatef()
then isn't it ok? And another question, what is
1  
chunkTotalPosX
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):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public Chunk(int var1, int var2, int var3){
Block block;

int offset = 0;
for(int x = 0; x < var1; x++){
//do all the for loops
block = new Block(offset, offset, offset);
offSet += 16;
}
}

Then the block:
1  
2  
3  
4  
5  
6  
7  
FloatBuffer verticeData;
public Block(int xOffSet, int zOffSet, int yOffSet){
//vbo stuff
verticeData.put(x, z, y,
                     x + offSet, z, y
                    //do rest of faces
}


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?

- Longor1996

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

JGO Kernel


Medals: 310
Projects: 11
Exp: 3 years


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


« Reply #24 - Posted 2013-03-15 22:35:49 »

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

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
   public void createBuffer()
   {
      FloatBuffer buf = BufferStorage.getBuffer(tiles.size() * 6 * 8); // 6 = vertices; 8 = floats per vertex
      vc = 0;
     
      for(Entry<Vector2Int, Tile> tile : tiles.entrySet()) // Tiles are stored in a HashMap
      {
         int x = tile.getKey().x + chunkpos.x*CHUNKSIZE;
         int y = tile.getKey().y + chunkpos.y*CHUNKSIZE; // tile position + (chunkpos*chunksize)
         
         float[] color = {1, 1, 1, 1};
         
         float[][] vertices = new float[][]{{x, y+1}, {x+1, y+1}, {x, y}, {x+1, y}};
         float[][] texCoords = tile.getValue().getTexCoords();
         buf.put(vertices[0]).put(texCoords[0]).put(color);
         buf.put(vertices[1]).put(texCoords[1]).put(color);
         buf.put(vertices[2]).put(texCoords[2]).put(color);
         buf.put(vertices[3]).put(texCoords[3]).put(color);
         buf.put(vertices[2]).put(texCoords[2]).put(color);
         buf.put(vertices[1]).put(texCoords[1]).put(color);
         vc += 6;
      }
     
      buf.flip();
     
      glBindBuffer(GL_ARRAY_BUFFER, buffer);
      glBufferData(GL_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
      glBindBuffer(GL_ARRAY_BUFFER, 0);
     
      outdatedBuffer = false;
      BufferStorage.addBuffer(buf);
   }

   public void render()
   {
      if(outdatedBuffer)
         createBuffer();
     
      glBindBuffer(GL_ARRAY_BUFFER, buffer);
     
      glVertexPointer(2, GL_FLOAT, 8*4, 0L);
      glTexCoordPointer(2, GL_FLOAT, 8*4, 2*4L);
      glColorPointer(4, GL_FLOAT, 8*4, 4*4L);
     
      glDrawArrays(GL_TRIANGLES, 0, vc);
     
      glBindBuffer(GL_ARRAY_BUFFER, 0);
   }

Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #25 - Posted 2013-03-16 13:03:11 »

Oh, I know
1  
glTranslatef()
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!

Offline Longor1996
« Reply #26 - Posted 2013-03-16 14:57:56 »

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

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
   public void createBuffer()
   {
      FloatBuffer buf = BufferStorage.getBuffer(tiles.size() * 6 * 8); // 6 = vertices; 8 = floats per vertex
      vc = 0;
     
      for(Entry<Vector2Int, Tile> tile : tiles.entrySet()) // Tiles are stored in a HashMap
      {
         int x = tile.getKey().x + chunkpos.x*CHUNKSIZE;
         int y = tile.getKey().y + chunkpos.y*CHUNKSIZE; // tile position + (chunkpos*chunksize)
         
         float[] color = {1, 1, 1, 1};
         
         float[][] vertices = new float[][]{{x, y+1}, {x+1, y+1}, {x, y}, {x+1, y}};
         float[][] texCoords = tile.getValue().getTexCoords();
         buf.put(vertices[0]).put(texCoords[0]).put(color);
         buf.put(vertices[1]).put(texCoords[1]).put(color);
         buf.put(vertices[2]).put(texCoords[2]).put(color);
         buf.put(vertices[3]).put(texCoords[3]).put(color);
         buf.put(vertices[2]).put(texCoords[2]).put(color);
         buf.put(vertices[1]).put(texCoords[1]).put(color);
         vc += 6;
      }
     
      buf.flip();
     
      glBindBuffer(GL_ARRAY_BUFFER, buffer);
      glBufferData(GL_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
      glBindBuffer(GL_ARRAY_BUFFER, 0);
     
      outdatedBuffer = false;
      BufferStorage.addBuffer(buf);
   }

   public void render()
   {
      if(outdatedBuffer)
         createBuffer();
     
      glBindBuffer(GL_ARRAY_BUFFER, buffer);
     
      glVertexPointer(2, GL_FLOAT, 8*4, 0L);
      glTexCoordPointer(2, GL_FLOAT, 8*4, 2*4L);
      glColorPointer(4, GL_FLOAT, 8*4, 4*4L);
     
      glDrawArrays(GL_TRIANGLES, 0, vc);
     
      glBindBuffer(GL_ARRAY_BUFFER, 0);
   }


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.


Oh, I know
1  
glTranslatef()
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!

@OP
Woops, 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?

So, what you have to do is:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
FOR every_block_in_a_chunk DO {
    int x = blockXCoordinateInChunk + theChunkPositionMeasuredInBlocksX;
    int y = blockYCoordinateInChunk + theChunkPositionMeasuredInBlocksY;
    int z = blockZCoordinateInChunk + theChunkPositionMeasuredInBlocksZ;
   
    chunkRenderer.setTheBlockTranslation(x,y,z);
    chunkRenderer.doRenderTheBlockByUsingHisID(blockID);
}



// Chunk Renderer
int totalBlockPositionInWorldRenderSpaceX = 0;
int totalBlockPositionInWorldRenderSpaceY = 0;
int totalBlockPositionInWorldRenderSpaceZ = 0;

setTheBlockTranslation(int bposX,int bposY,int bposZ)
{
    // Because the Blocks are 16x16x16 Units Big, multiply the global block coordinates by 16 to get the global block render coordinates.
    totalBlockPositionInWorldRenderSpaceX = bposX * 16;
    totalBlockPositionInWorldRenderSpaceY = bposY * 16;
    totalBlockPositionInWorldRenderSpaceZ = bposZ * 16;
}

doRenderTheBlockUsingHisID(int blockID){
   
    // 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);
   
    // Draw all the other surfaces...
}

drawVertex(flaot blockvertex_x,float blockvertex_y,float blockvertex_z){
    // The Translation for the Block Vertices is done HERE.
    drawAVertex(
        totalBlockPositionInWorldRenderSpaceX + blockvertex_x;
        totalBlockPositionInWorldRenderSpaceY + blockvertex_y;
        totalBlockPositionInWorldRenderSpaceZ + blockvertex_z;
    );
}


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.

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

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #27 - Posted 2013-03-16 18:27:45 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
public Cube(int offSet){

      glBegin(GL_QUADS);

      glColor3f(1, 0, 0);
      glVertex3f(0 + offSet, 0 + offSet, 0);
      glVertex3f(0, 0 + offSet, 0);
      glVertex3f(0, 0, 0);
      glVertex3f(0 + offSet, 0, 0);

      glColor3f(1, 0, 1);
      glVertex3f(0, 0 + offSet, 0 + offSet);
      glVertex3f(0 + offSet, 0 + offSet, 0 + offSet);
      glVertex3f(0 + offSet, 0, 0 + offSet);
      glVertex3f(0, 0, 0 + offSet);

      glColor3f(1, 1, 1);
      glVertex3f(0 + offSet, 0, 0);
      glVertex3f(0, 0, 0);
      glVertex3f(0, 0, 0 + offSet);
      glVertex3f(0 + offSet, 0, 0 + offSet);

      glColor3f(0, 0, 1);
      glVertex3f(0, 0 + offSet, 0);
      glVertex3f(0 + offSet, 0 + offSet, 0);
      glVertex3f(0 + offSet, 0 + offSet, 0 + offSet);
      glVertex3f(0, 0 + offSet, 0 + offSet);

      glColor3f(1, 1, 0);
      glVertex3f(0, 0 + offSet, 0);
      glVertex3f(0, 0 + offSet, 0 + offSet);
      glVertex3f(0, 0, 0 + offSet);
      glVertex3f(0, 0, 0);

      glColor3f(0, 2, 1);
      glVertex3f(0 + offSet, 0 + offSet, 0 + offSet);
      glVertex3f(0 + offSet, 0 + offSet, 0);
      glVertex3f(0 + offSet, 0, 0);
      glVertex3f(0 + offSet, 0, 0 + offSet);
      glEnd();

   }

Did I just render the faces backwards or something?
1  
offSet
is set to 10.

Offline Vermeer

JGO Coder


Medals: 16



« Reply #28 - Posted 2013-03-16 19:13:11 »

Sorry not been updating much, had things to do.

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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
   public void Render(int textureID,float Hoffset, float Voffset,float size){
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);//select texture
     
      //
      GL11.glBegin(GL11.GL_QUADS);
     
      // Front Face ..............................................................................................
      GL11.glNormal3f(0.0f, 0.0f, i); // Normal Pointing Towards Viewer
     
      //                  x ,   y
      GL11.glTexCoord2f(Hoffset, Voffset + size); GL11.glVertex3f(-i, -i, i); // Bottom Left Of The Texture and Quad
     
      GL11.glTexCoord2f(Hoffset + size, Voffset + size );   GL11.glVertex3f(i, -i, i); // Bottom Right Of The Texture and Quad
     
      GL11.glTexCoord2f(Hoffset + size,Voffset );GL11.glVertex3f(i, i, i); // Top Right Of The Texture and Quad
     
      GL11.glTexCoord2f(Hoffset, Voffset );   GL11.glVertex3f(-i, i, i); // Top Left Of The Texture and Quad
     
     
     
     
   
      // Back Face
      GL11.glNormal3f(0.0f, 0.0f, -i); // Normal Pointing Away From Viewer
     
      GL11.glTexCoord2f(Hoffset + size,  Voffset + size); GL11.glVertex3f(-i, -i, -i); // Bottom Right Of The Texture and Quad
      GL11.glTexCoord2f(Hoffset + size, Voffset  ); GL11.glVertex3f(-i, i, -i); // Top Right Of The Texture and Quad
      GL11.glTexCoord2f(Hoffset, Voffset  );   GL11.glVertex3f(i, i, -i); // Top Left Of The Texture and Quad
      GL11.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 Quad
      GL11.glTexCoord2f(Hoffset, Voffset);GL11.glVertex3f(-i, i, i); // Bottom Left Of The Texture and Quad
      GL11.glTexCoord2f(Hoffset + size, Voffset);   GL11.glVertex3f(i, i, i); // Bottom Right Of The Texture and Quad
      GL11.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 Quad
      GL11.glTexCoord2f(Hoffset, Voffset + size);   GL11.glVertex3f(i, -i, -i); // Top Left Of The Texture and Quad
      GL11.glTexCoord2f(Hoffset, Voffset);GL11.glVertex3f(i, -i, i); // Bottom Left Of The Texture and Quad
      GL11.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 Quad
      GL11.glTexCoord2f(Hoffset + size, Voffset);GL11.glVertex3f(i, i, -i); // Top Right Of The Texture and Quad
      GL11.glTexCoord2f(Hoffset, Voffset);   GL11.glVertex3f(i, i, i); // Top Left Of The Texture and Quad
      GL11.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 Quad
      GL11.glTexCoord2f(Hoffset + size,Voffset + size);   GL11.glVertex3f(-i, -i, i); // Bottom Right Of The Texture and Quad
      GL11.glTexCoord2f(Hoffset + size,Voffset);GL11.glVertex3f(-i, i, i); // Top Right Of The Texture and Quad
      GL11.glTexCoord2f(Hoffset, Voffset);   GL11.glVertex3f(-i, i, -i); // Top Left Of The Texture and Quad
      GL11.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.

Offline Vermeer

JGO Coder


Medals: 16



« Reply #29 - Posted 2013-03-17 19:38:34 »

Trying VBO's



VBO one block at a time.
Thats not fast enough. Next test - to send 16*16 blocks to VBO at once, and see what difference is.

I also tried using offseting blocks insead of glTranslate for each block and there was no difference in framerate for 9 16^3 chunks.


Now Im getting confused with it all, but below is my code to draw a VBO textured cube

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
// create geometry buffer (both vertex and texture)
   FloatBuffer vcBuffer = BufferUtils.createFloatBuffer((6*18) + (6*12)); //18 ver + 12 text  6 faces
   
   //front face
   //triangle 1 bottom
   vcBuffer.put(-0.5f).put(-0.5f).put(+0.5f); // vertex
   vcBuffer.put(0).put(1); // texture    
   vcBuffer.put(+0.5f).put(-0.5f).put(+0.5f); // v
   vcBuffer.put(1).put(1); //    t
   vcBuffer.put(+0.5f).put(+0.5f).put(+0.5f); // v
   vcBuffer.put(1).put(0); // t
   
   //triangle 2  top
   vcBuffer.put(-0.5f).put(-0.5f).put(+0.5f); // v
   vcBuffer.put(0).put(1); // t  
   vcBuffer.put(+0.5f).put(+0.5f).put(+0.5f); // v
   vcBuffer.put(1).put(0); // t
   vcBuffer.put(-0.5f).put(+0.5f).put(+0.5f); // v
   vcBuffer.put(0).put(0); //t

   // right face
   // triangle 1 bottom
   vcBuffer.put(+0.5f).put(-0.5f).put(+0.5f); // v
   vcBuffer.put(0).put(1); //
   vcBuffer.put(+0.5f).put(-0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(1); //
   vcBuffer.put(+0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(0); //

   // triangle 2 top
   vcBuffer.put(+0.5f).put(-0.5f).put(+0.5f); // v
   vcBuffer.put(0).put(1); // c green
   vcBuffer.put(+0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(0); // c red
   vcBuffer.put(+0.5f).put(+0.5f).put(+0.5f); // v
   vcBuffer.put(0).put(0); // c blue

   //back face
   //triangle 1 bottom
   vcBuffer.put(+0.5f).put(-0.5f).put(-0.5f); // vertex
   vcBuffer.put(0).put(1); // texture    
   vcBuffer.put(-0.5f).put(-0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(1); //    
   vcBuffer.put(-0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(0); //
   
   //triangle 2  top
   vcBuffer.put(+0.5f).put(-0.5f).put(-0.5f); // v
   vcBuffer.put(0).put(1); // c   green  
   vcBuffer.put(-0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(0); // c    red  
   vcBuffer.put(+0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(0).put(0); // c   blue

   //top face
   //triangle 1 bottom
   vcBuffer.put(-0.5f).put(+0.5f).put(+0.5f); // vertex
   vcBuffer.put(0).put(1); // texture    
   vcBuffer.put(+0.5f).put(+0.5f).put(+0.5f); // v
   vcBuffer.put(1).put(1); //    
   vcBuffer.put(+0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(0); //
   
   //triangle 2  top
   vcBuffer.put(-0.5f).put(+0.5f).put(+0.5f); // v
   vcBuffer.put(0).put(1); // c   green  
   vcBuffer.put(+0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(1).put(0); // c    red  
   vcBuffer.put(-0.5f).put(+0.5f).put(-0.5f); // v
   vcBuffer.put(0).put(0); // c   blue
   
   // left face
      // triangle 1 bottom
      vcBuffer.put(-0.5f).put(-0.5f).put(-0.5f); // v
      vcBuffer.put(0).put(1); //
      vcBuffer.put(-0.5f).put(-0.5f).put(+0.5f); // v
      vcBuffer.put(1).put(1); //
      vcBuffer.put(-0.5f).put(+0.5f).put(+0.5f); // v
      vcBuffer.put(1).put(0); //

      // triangle 2 top
      vcBuffer.put(-0.5f).put(-0.5f).put(-0.5f); // v
      vcBuffer.put(0).put(1); // c green
      vcBuffer.put(-0.5f).put(+0.5f).put(+0.5f); // v
      vcBuffer.put(1).put(0); // c red
      vcBuffer.put(-0.5f).put(+0.5f).put(-0.5f); // v
      vcBuffer.put(0).put(0); // c blue
     
      //top face
      //triangle 1 bottom
      vcBuffer.put(+0.5f).put(-0.5f).put(-0.5f); // v
      vcBuffer.put(1).put(0); //
      vcBuffer.put(+0.5f).put(-0.5f).put(+0.5f); // v
      vcBuffer.put(1).put(1); //
      vcBuffer.put(-0.5f).put(-0.5f).put(+0.5f); // vertex
      vcBuffer.put(0).put(1); // texture    
         
     
     
      //triangle 2  top
      vcBuffer.put(-0.5f).put(-0.5f).put(-0.5f); // v
      vcBuffer.put(0).put(0); // c   blue
      vcBuffer.put(+0.5f).put(-0.5f).put(-0.5f); // v
      vcBuffer.put(1).put(0); // c    red  
      vcBuffer.put(-0.5f).put(-0.5f).put(+0.5f); // v
      vcBuffer.put(0).put(1); // c   green  
     
     
     
   
   
   vcBuffer.flip();
   
   
   IntBuffer ib = BufferUtils.createIntBuffer(1);
   glGenBuffersARB(ib);
   
   
   int vcHandle = ib.get(0);
   
   glEnableClientState(GL_VERTEX_ARRAY);
   GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
   //glEnableClientState(GL_COLOR_ARRAY);
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, vcHandle);
   glBufferDataARB(GL_ARRAY_BUFFER_ARB, vcBuffer, GL_STATIC_DRAW_ARB);  
   
   // the 20 stride   =   3x4byte for the vertex and 2*4 bytes for colour    
   // Vpointer starts at 0  (0<<2)
   // the textures start at 3*4  = 3<<2
   glVertexPointer(3, GL_FLOAT, /* stride **/20, /* offset **/0 << 2); // float at index 0
   //glColorPointer(3, GL_FLOAT, /* stride **/(3 * 2) << 2, /* offset **/(3*1) << 2); // float at index 3
   GL11.glTexCoordPointer(2, GL_FLOAT, /* stride **/20, /* offset **/(3*1) << 2);
   //glDrawArrays(GL_TRIANGLES, 0, 6/* elements */);
   glTranslatef(1f, -7f, 0f);
   
   for (int n = 0; n<128; n++){
   //glDrawArrays(GL_TRIANGLES, 0, 6);
     
      for ( int  m = 0; m<128; m++){
         glTranslatef(0f, 0f, -1f);
   glDrawArrays(GL_TRIANGLES, 0, 42);
   //glDrawArrays(GL_TRIANGLES, 0, 6); //draw front only
   //glDrawArrays(GL_TRIANGLES, 6, 12);
   //glDrawArrays(GL_TRIANGLES, 12, 18);
      }
   glTranslatef(1f, 0f, +128f);
   }
   
   
   
   
   
   
   
   
   
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
   GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
   //glDisableClientState(GL_COLOR_ARRAY);  //glDisableClientState(GL_COLOR_ARRAY);
   glDisableClientState(GL_VERTEX_ARRAY);
   
   // cleanup VBO handles
   ib.put(0, vcHandle);
   glDeleteBuffersARB(ib);


I welcome any suggestions!
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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (105 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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