I’m creating a simple game like Minecraft but it gives me 10 FPS even though I only draw a few cubes:
I tried reducing the render distance (50) but that wasn’t enough
Or I tried setting clock.tick(90) to clock.tick(200) but that didn’t work either.
Anyway, here’s my code:
# ...
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()