Bad Performance Need Help

Started by Andrew Alfazy, August 18, 2017, 07:47:30

Previous topic - Next topic

Andrew Alfazy

Very Bad Performance When I Try to render about 16*16*16 Map Made Of Blocks
My Block Code
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
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
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

Kai


Cornix

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.

Andrew Alfazy


Andrew Alfazy

OMG you are true I was Trying to render 134217728 vertices per frame :o
with my dead pc

Cornix

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.