I am creating a simple Game, like minecraft.
But i stumbled upon a problem. Its not optimized!
Its giving me 10 FPS, even tho i am drawing only a few of cubes
Screenshot:
I tried making render distance (50) less, but that is not enough
Or i tried setting clock.tick(90) to clock.tick(200), but that didnt also work.
Anyways, Theres my code: (if not enough, i could give pastebin link)
# ...
def Cube(x, y, z, r, g, b, distancefromcamera):
if distancefromcamera > 50:
return
glPushMatrix()
glTranslatef(x, y, z)
glBegin(GL_QUADS)
glColor3f(r,g,b)
for surface in surfaces:
for vertex in surface:
glVertex3fv(mulsequence(vertices[vertex], cubesize/2))
glEnd()
glPopMatrix()
# ...
def main():
# ...
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE or event.key == pygame.K_RETURN:
pygame.quit()
quit()
glLoadIdentity()
mouseMove = pygame.mouse.get_rel()
pygame.mouse.set_pos((displayCenter[0],displayCenter[1]))
up_down_angle += mouseMove[1]*0.25
glRotatef(up_down_angle, 1.0, 0.0, 0.0)
fps = str(int(clock.get_fps()))
pygame.display.set_caption(fps)
pressedkeys = pygame.key.get_pressed()
glPushMatrix()
glLoadIdentity()
# ...
glRotatef(mouseMove[0]*0.25, 0.0, 1.0, 0.0)
rotationx += mouseMove[0]*0.25
glMultMatrixf(viewMatrix)
viewMatrix = glGetFloatv(GL_MODELVIEW_MATRIX)
# apply view matrix
glPopMatrix()
glMultMatrixf(viewMatrix)
glPushMatrix()
glLightfv(GL_LIGHT0, GL_POSITION, [1, -1, 1, 0])
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
for i in range(100):
for l in range(100):
distancefromcamera = (i-posx-50)**2 + (l-posz-50)**2
Cube(i-50,0,l-50,0.5,0.9,0.2, distancefromcamera)
glPopMatrix()
pygame.display.flip()
clock.tick(90)
main()