Hello guys
I’m new around here and just come up with my first question. I started to work with Lwjgl to make a Minecraft like Voxel engine. After I implemented the movement and the mouse controls I wanted to implement the Blocks.
I decided to use the Slick Texture class because it’s the easiest way.
So I wrote the code to bind a texture for the top, the sides and the bottom of a block. When I created a test block it worked fine, also with a square of 10x10 blocks.
But when I wanted to render a whole chunk of blocks (16x16x100) it nearly froze.
First I thought it was because of looping through the array but after trying out some other ways to store the blocks I recognized it wasn’t.
I then removed the calls to bind the textures, and it ran perfectly fluent.
My question now is, why does this happen, and how could I add textures to the different sides of the block without running into such performance issues?
Here is the code that renders a block
public void render(){
float x = coordinate.x;
float y = coordinate.y;
float z = coordinate.z;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
top.bind();
glBegin(GL_QUADS);
//TOP
glNormal3f(0f, 1f, 0f);
glTexCoord2f(0f, 0f);
glVertex3f(x,y,z);
glTexCoord2f(0f, 1f);
glVertex3f(x, y, z+1);
glTexCoord2f(1f, 1f);
glVertex3f(x+1, y, z+1);
glTexCoord2f(1f, 0f);
glVertex3f(x+1, y, z);
glEnd();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
bottom.bind();
glBegin(GL_QUADS);
//BOTTOM
glNormal3f(0f, -1f, 0f);
glTexCoord2f(0f, 0f);
glVertex3f(x,y-1,z);
glTexCoord2f(0f, 1f);
glVertex3f(x, y-1, z+1);
glTexCoord2f(1f, 1f);
glVertex3f(x+1, y-1, z+1);
glTexCoord2f(1f, 0f);
glVertex3f(x+1, y-1, z);
glEnd();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
sides.bind();
glBegin(GL_QUADS);
//BACK
glNormal3f(0,0,-1);
glTexCoord2f(0f, 0f);
glVertex3f(x,y,z);
glTexCoord2f(1f, 0f);
glVertex3f(x+1, y, z);
glTexCoord2f(1f, 1f);
glVertex3f(x+1, y-1, z);
glTexCoord2f(0f, 1f);
glVertex3f(x, y-1, z);
//FRONT
glNormal3f(0,0,1);
glTexCoord2f(0f, 0f);
glVertex3f(x,y,z+1);
glTexCoord2f(1f, 0f);
glVertex3f(x+1, y, z+1);
glTexCoord2f(1f, 1f);
glVertex3f(x+1, y-1, z+1);
glTexCoord2f(0f, 1f);
glVertex3f(x, y-1, z+1);
//LEFT
glNormal3f(-1,0,0);
glTexCoord2f(0f, 0f);
glVertex3f(x,y,z);
glTexCoord2f(0f, 1f);
glVertex3f(x, y-1, z);
glTexCoord2f(1f, 1f);
glVertex3f(x, y-1, z+1);
glTexCoord2f(1f, 0f);
glVertex3f(x, y, z+1);
//RIGHT
glNormal3f(1,0,0);
glTexCoord2f(0f, 0f);
glVertex3f(x+1,y,z);
glTexCoord2f(0f, 1f);
glVertex3f(x+1, y-1, z);
glTexCoord2f(1f, 1f);
glVertex3f(x+1, y-1, z+1);
glTexCoord2f(1f, 0f);
glVertex3f(x+1, y, z+1);
glEnd();
}