Pretty basic. How would I go about actually removing or adding cubes? I know I have to use glMapBuffer and glUnMapBuffer, but how do I actually make an array of cubes and upload them to the VBO to be rendered? Also, I am currently rendering the cubes like this:

I dont think anything is currently wrong, if you're talking about how I'm rendering the cubes. I've just heard people saying that you should render a new cube everytime instead of the same one at different coordinates.

That depends on what you're doing. For static geometry then yes, go ahead and generate your cubes and store them in an array. For dynamic geometry, I wouldn't recommend it, at least not for cubes or anything more advanced than that. What are you expecting to gain?

My geometry will be dynamic. And I dont know what I expect to gain, I was just wondering if my way of doing it was wrong as I'm very new to VBOs. So how would you recommend me storing my cubes if you don't think an array would be good?

I'd recommend that you merge the data into one VBO by interleaving the vertex attributes. Other than that, I don't see what's wrong with rendering them one by one like you're currently doing. Although you say your geometry will be dynamic, exactly what will you be rendering using cubes?

I would call a cube world static, since it only changes very rarely. 99.9% of all frames won't have anything changed, so there's no need to regenerate the data. Split up the world into subsections so you don't have to regenerate the world every time something changes. You'll also have to manually cull faces that aren't visible and do frustum culling, but it's all in the thread I linked.

I read through that whole post, and I'm still a little confused on how to store all my vertex data in one VBO. Basically, what I want is to have a VBO with 16x16x16 cubes. Then I'll generate new chunks and translate the chunks to the correct position. When that's done, I want to draw the VBO in that chunk position, so I can avoid calling glTranslate a lot. I'm stuck on how I should store 4096 blocks in one VBO though. Should I make an array and then throw the array into the VBO?

The definitive theoretical maximum of vertices is 16*16*16 cubes * 6 faces * 4 vertices = 98 304 vertices per chunk. Each vertex needs a 3D float position and an RGBA color, so you get a total of 12 + 4 = 16 bytes per vertex. In total, you need a ByteBuffer with a length of 1 572 864. (1.5MBs of data, it's actually almost nothing). Whenever the geometry of a chunk needs to be regenerated, use this buffer to prepare vertex data for the chunk. Just loop through the 16x16x16 chunk of cubes. For each cube, check if any of the cube's neighbors is air to see if it's visible. If it is, just generate vertex positions for that face (vertexPosition = chunkWorldPosition + localPositionInsideChunk + cubeVertex) and store their data in the buffer. When you're done (note: you'll end up with a LOT less data than the maximum capacity of the buffer in 99.999% of all cases.) just flip the buffer. Tadaah! You now have a perfectly fine buffer ready to be sent of to the GPU with glBufferData()!

Since the data is already translated, you can draw chunks with just a few lines of code later.

1. Do you know of any good tutorials on how to texture 3d objects? I'm trying to texture my cubes now and I don't think using

1

glBindTexture ()

would be a good idea. I have heard about texture atlases, but I'm confused on how to bind the textures to the cube and draw them. Can I use a VBO?

2.I want to be able to pick the cubes in the 3D world and delete or add more. Can I use ray tracing to figure out where the current mouse position is in the world? Or do I have to 'flatten' the image down so its 2D and then just use the mouse position to pick cubes that way? I would a then 'unflatten' the image so it looks 3D again of course. I feel like that would be horribly inefficient though!

I am not so good at modern stuff but the way you bind a texture is by calling that function. TextureAtlas has multiple textures on it so you can bind it once and then render without having to bind a different texture. You do this by specifying different texture coordinates. If you are using modern opengl you do not need texture atlases.

You could probably pack all your different cube textures into a single 512*512 or 1024*1024 texture if they are lower resolutions. That is you would have dirt, grass, water, etc all on one texture so there is only one bind call when you render your cubes. You can get away with quite a few texture binds and still stay at 60fps. I would say that as long as you do not bind a texture on every single cube you should be ok. Another thing you could do is have the current texture id saved and before binding a new one see if it matches the texture that is already bound that way you could reduce a bind call which may happen often.

I think the best way is to ray trace and pick the first cube it intersects with.

Rendering textures is pretty much the same as plain colours. Firstly make sure GL_TEXTURE_2D is enabled. Then replace your per vertex colour values with texture coordinates.Bind the texture.Draw the primitive as per normal.

I want to add that I´m really new to this myself, but I sat with this all weekend, so I though I might share what I learned... Take a look at Davedes tutorial on how to load textures if you haven´t done that already:

And then you enable GL_TEXTURE_COORD_ARRAY the same way as you did with color and vertex:

1

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

So it´s basically the same as vertex and color. Just make sure you bind the texture with before the drawmethod.

glBindTexture(GL_TEXTURE_2D, textureID);

I notice you don´t use glVertexPointer() or glColorPointer() method? I thought you had to use that to draw a VBO? Can someone share some insight..? Edit: Did not read all the code in the first post. So never mind me...

This is highly suspicious code, as the value is written into a local variable, which is basically a no-op. The fact that there is also a field named 'vboV' doesn't change this.

Fix:

1 2 3

publicvoidgenBuffer() {vboV = GL15.glGenBuffers(); }

I figured it out, I just forgot to call

1

this.vboV

to actually reference the correct int. As for your question Vermeer, I don't entirely understand what you're asking, but yes, you can create a chunk based on a buffer. I've seen your thread, and I would highly recommend switching over to VBOs, I generally get around 20 FPS more than you do with no optimizations (face culling, only rendering visible cubes).

Thanks for your positive comments. I hope you get time to work on yours soon!Thanks to the suggestions you have posted in your thread I got VBO's working.

Will keep poping back to see how your getting on.

No problem! I think you're doing great, I'm actually very envious of how much work you're doing! I unfortunately will barely be able to code for the next couple of weeks at least, so don't expect much from me for a while :/

I tried to conquer textures this weekend, but it doesn't seem like they want to load. I create a new VBO to hold the block texture coordinates, bind the texture two different ways actually(maybe that's whats wrong), and then I create the VBO id for the the texture and call

So I tried to tackle textures today. I have a simple texture that looks like this:

However, when I apply the texture to the cubes, it looks like this:

Obviously I did something very wrong. I basically load the texture up using Slick, create a buffer that holds 2 * 3 * 6 * 4096 (vertex size, amount of vertices per face, faces, number of blocks in a chunk) bytes or whatever you measure that in, bind the texture and put the data into the buffer. I then render it out. Here's the relevant code:

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