I split my map into chunks and am only going to draw the visible ones. Minecraft I learned takes the same approach.
The problem I am having is speed. My game runs majorly slow for some reason.
I am drawing only 3*3 = 9 chunks
Minecraft draws 9*9 = 81 chunks and still gets a higher framerate.
My game barely gets 30fps and Minecraft gets 210-450fps!
I dont understand why its so slow.
I have included links to both, so that you can see what I am talking about as well as my Chunk drawing code.
Someone please make a great observation, this is really killing me. I have no idea why it's so slow and can not work on other componets until the framerate problem is fixed.
Thanks a TON in Advance.
Coder Walker
Happy early Christmas :c-penguin:
Project Block: (2mb includes SDL and OpenGL dll's)
ProjectBlock.zip
PASSWORD FOR THE ZIP IS "block"
Minecraft Alpha (In Browser Java):
Minecraft
Chunk Drawing Code:
position is the number of blocks in that chunk
grid is an array that holds the x,y and z of each block
void chunk::draw(float x, float y, float z)
{
glPushMatrix();
glColor4f( 1.0, 1.0, 1.0, 1.0 );
glTranslatef(x,y,z);
glEnable( GL_TEXTURE_2D );
for(int a=0;a<position;a++)
{
glPushMatrix();
glTranslatef(grid[a].x,grid[a].y,grid[a].z);
glBindTexture( GL_TEXTURE_2D,grid[a].tex );
//Front
glBegin( GL_QUADS );
glNormal3f(0.0f, 0.0f, -1.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 0 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 0, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 1, 0 );
//Back
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 0, 1 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 1 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 1, 1 );
//Top
glNormal3f(0.0f, 1.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 1, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 1, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 1, 1 );
//Bottom
glNormal3f(0.0f, -1.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 0, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 0, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 0, 1 );
//Left
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(0, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(0, 1, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(0, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(0, 0, 1 );
//Right
glNormal3f(1.0f, 0.0f, 0.0f);
glTexCoord2d(1.0,1.0);glVertex3f(1, 1, 1 );
glTexCoord2d(1.0,0.0);glVertex3f(1, 1, 0 );
glTexCoord2d(0.0,0.0);glVertex3f(1, 0, 0 );
glTexCoord2d(0.0,1.0);glVertex3f(1, 0, 1 );
glEnd();
glPopMatrix();
//printf("%d\n",a);
}
glPopMatrix();
Every object in the game will be the block or Cube. So there has got to be a further optimization to this. Please help me find it.


Sign In
Create Account

Back to top









