Hi,
You mean the glEnd in my createChunkList code? All works with it where it is?
Yep, raycasting looks cool, how do you get the direction the player is facing, this some
simple trig?
Just wanting to optimize the binding of different textures…
Hi,
You mean the glEnd in my createChunkList code? All works with it where it is?
Yep, raycasting looks cool, how do you get the direction the player is facing, this some
simple trig?
Just wanting to optimize the binding of different textures…
You are making three major mistakes:
No, like Riven said:
private void renderBlock(Block.BlockType type) {
GL11.glTexCoord2f(0.0f, 0.0f);
off_glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad
GL11.glTexCoord2f(1.0f, 0.0f);
off_glVertex3f( 0.5f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad
[...]
off_glVertex3f(-0.5f, 0.5f, -0.5f); // Top Left Of The Texture and Quad
GL11.glEnd(); // this one here ########################
glColor3f(1,1,1);
}
[quote]Yep, raycasting looks cool, how do you get the direction the player is facing, this some
simple trig?
[/quote]
I have made my own Ray class and it takes an origin of Vector3 and a uniform delta of Vector3. Then the uniform vector gets scaled by scalarProduct.
uniRay.setPosition(-pos.getX(),-pos.getY(),-pos.getZ());
uniRay.setDelta((float)Math.sin(Math.toRadians(-rotY))*(float)-Math.cos(Math.toRadians(-rotX)),
(float)Math.sin(Math.toRadians(-rotX)),
(float)-Math.cos(Math.toRadians(-rotY))*(float)Math.cos(Math.toRadians(-rotX)));
uniRay.scalarProduct(RAY_LENGTH); // change length of the uniform vector
The rotX variables are the rotation in degrees on every axis by the player.
The off_vertex does get the tx/ty/tz values ?!
Single texture for the block textures - you mean I’m binding them again?? Or have one big texture which has multiple textures in it?
glBegin / glEnd - in my createChunkList method?
I appreciate your advice @Longor1996
Oops, lol, removed it now. Thanks for pointing it out guys.
You have lost me with the ray class, guess I need to research some ray cast stuff, is the game math book any good, I notice there is a new edition?
Hi.
Where? I can’t see any getter/setter that sets the values for the method.
Yep. Multiple textures in a single Texture. This is the way to go. (Google: Tile Atlas/Map)
Yep. You are using them wrong. You only need one at the beginning of the nested loop that draws the blocks, and at the end of the nested loop.
Thanks!
If you really study math with this one, you will be up to the task of 3D game programming.
http://gamemath.com/about-the-book/
I am not advertising, I just love this book as it helped me so much btw.
But you can of course also do it without it.
@Sparky83 I will get that book
@Longor1996 - I originally use to have the glBegin out of the nested loops, my issue is needing to bind the texture before the glBegin and to do that I use:
GetBlock(x,y,z);
for (int x = 0; x < Chunk.CHUNK_SIZE; x++) {
for (int y = 0; y < Chunk.CHUNK_SIZE; y++) {
for (int z = 0; z < Chunk.CHUNK_SIZE; z++) {
Block block = GetBlock(x,y,z);
TextureBuffer texture = TextureManager.getInstance().getTexture(block.getType());
GL11.glBindTexture(GL_TEXTURE_2D, texture.textureId);
glBegin(GL11.GL_QUADS);
Need another way of getting the current block in order to get its texture id so I can bind its texture before the glBegin…
Is there a way of binding a texture to a block before the above stage?
Thanks
If you wan’t to give every cube it’s own texture, you have to use glBegin/glEnd inside the nested loop.
And this will give you very big performance drops!
As I said: Use a texture atlas! Then you have to bind the atlas only once right before drawing the chunks and that’s it.
Can this be done even when using displaylists?
Thanks,
Steve
Yes. You just have to bind an texture atlas,
and then specify the texture coordinates per face in a way that only a defined portion af the atlas is visible.
Say, you atlas contains 4 textures, and has a power-of-two size of 32x32.
Then the code to use only the texture in the top left corner of the atlas is:
glTexCoord(0,0);
glVertex(0,0);
glTexCoord(0.5,0);
glVertex(1,0);
glTexCoord(0.5,0.5);
glVertex(1,1);
glTexCoord(0,0.5);
glVertex(0,1);
Im always happy to help!
Oh, and there is a lot more of things that you can do to optimize your voxel-engine.
But some of them are invented by myself and therefore secret!
Hi steg,
Hope your project is going well. I posted my entire code in my thread, it uses a texture atlas 16x16 sprites
It’s 512 x512 texture, so 1/16 = 0.0625 for each offset texture. Gives you quite a few block to play with. For grass, the offsets are just changed so you can draw the sides an top differently. See – GrassBlock !
This forum is not a chat room.
Ok, sorry about that.
Think I’ve worked out texture atlas.
I’ve got a texture atlas of 1024x1024, textures are 64x64.
So, that is 1024 / 64 = 16 textures wide
1024 / 64 = 16 textures high
Then I just do 1 / 16 to give texture x-coordinate (i.e. 0.0625f )
and this is the same for texture y-coordinate.
So, to get 4th texture, I use this:
GL11.glTexCoord2f(4.0f * 0.0625f, 1 * 0.0625f);
GL11.glVertex3f(-0.1f, 0.1f, -0.1f); // Top Left Of The Texture and Quad
GL11.glTexCoord2f(4.0f * 0.0625f, 0.0f * 0.0625f);
GL11.glVertex3f(-0.1f, 0.1f, 0.1f); // Bottom Left Of The Texture and Quad
GL11.glTexCoord2f(5 * 0.0625f, 0.0f * 0.0625f);
GL11.glVertex3f( 0.1f, 0.1f, 0.1f); // Bottom Right Of The Texture and Quad
GL11.glTexCoord2f(5 * 0.0625f, 1 * 0.0625f);
GL11.glVertex3f( 0.1f, 0.1f, -0.1f); // Top Right Of The Texture and Quad
Hope this may help somebody?!
Thanks,
Steve
It is going slowly, lol, been busy working.
Thanks with regards to textures, worked it out now, going to use atlas so only one texture bind.
Will have a look at your code if I get chance, although I do enjoy trying to work things out - oh and the help on these forums is invaluable!
It is great to see so many people working on these cube worlds, sure has given me an insight into using OpenGL. Thanks everyone!
Yes the fun is figuring it out, you learn it that way. But sometimes it can be frustrating when it just won’t work. This forum is so helpful and inspiring when things just won’t work how you want. I agree thanks everyone!
This forum is not a chat room.
Why don’t you guys exchange email addresses, instead of accounting for about a quarter of JGO postings.