Hello Guest

Bad Performance Need Help

  • 5 Replies
  • 736 Views
Bad Performance Need Help
« on: August 18, 2017, 07:47:30 »
Very Bad Performance When I Try to render about 16*16*16 Map Made Of Blocks
My Block Code
Code: [Select]
glBegin(GL_QUADS);
glColor3f(clr.x,clr.y,clr.z);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z+0.5f);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z-0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z-0.5f);

glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z-0.5f);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z-0.5f);

glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z+0.5f);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z+0.5f);

glColor3f(1,1,1);
glEnd();

glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f);

glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z-0.5f);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z-0.5f);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z+0.5f);

glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z-0.5f);

glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z+0.5f);

glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z-0.5f);
glVertex3f(pos.x-0.5f, pos.y+0.5f, pos.z+0.5f);

glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y+0.5f, pos.z+0.5f);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z-0.5f);

glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z+0.5f);
glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z+0.5f);

glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x-0.5f, pos.y-0.5f, pos.z+0.5f);

glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z-0.5f);
glVertex3f(pos.x+0.5f, pos.y-0.5f, pos.z+0.5f);
glColor3f(1,1,1);
glEnd();
and Map Code I Call It 1 Time
Code: [Select]
for (int i = 0; i < SizeX*SizeY*SizeZ;i++ ) {

Map.add(new Block(new Vector3f(x,y,z), 0));

if(x < SizeX) {
x++;
}
if(x == SizeX) {
if(y < SizeY) {
y++;
x=0;
}else {
x--;
}
}
if(y == SizeY) {
if(z < SizeZ) {
z++;
y = 0;
x = 0;
}
}
}
and Render Code  I call per Frame
Code: [Select]
for (int i = 0; i < Map.size();i++) {
Map.get(i).Draw();
}

Notes :
I'm Trying 16 x 16 x 16 Map
Minecraft Work better in the same machine
My OpenGL 1.4.0 - Build 4.14.10.4543
Pentium 4 2.8GHz
Windows XP pro 32bit
Ram 2.5 GB
« Last Edit: August 18, 2017, 09:52:34 by Andrew Alfazy »

*

Kai

Re: Bad Performance Need Help
« Reply #1 on: August 18, 2017, 09:54:02 »
Your best option is to use OpenGL Display Lists.

*

Offline Cornix

  • *****
  • 478
Re: Bad Performance Need Help
« Reply #2 on: August 18, 2017, 11:14:14 »
This is not really how you would build a game like minecraft. Even if you ditch the horribly slow immediate mode rendering you are using right now and replace it with VBO's or Display Lists you will still not get a comparable result. Games like minecraft do not render the entire world all the time. They carefully calculate exactly which blocks need to be rendered and which ones dont. They also calculate which sides of these blocks need to be rendered. Without doing this culling, the professionally made games would have awful performance as well.
« Last Edit: August 18, 2017, 11:22:47 by Cornix »

Re: Bad Performance Need Help
« Reply #3 on: August 18, 2017, 11:17:30 »
Thanks Guys ;D

Re: Bad Performance Need Help
« Reply #4 on: August 18, 2017, 11:52:52 »
OMG you are true I was Trying to render 134217728 vertices per frame :o
with my dead pc

*

Offline Cornix

  • *****
  • 478
Re: Bad Performance Need Help
« Reply #5 on: August 18, 2017, 13:05:05 »
The number of vertices is not really that big of a deal. The resulting fragments are much more important. Rendering a trillion very tiny triangles is easier than rendering a million really big ones.