Does pyGame do 3d?

前端 未结 11 656
醉话见心
醉话见心 2020-12-29 21:45

I can\'t seem to find the answer to this question anywhere. I realise that you have to use pyOpenGL or something similar to do openGL stuff, but I was wondering if its possi

相关标签:
11条回答
  • 2020-12-29 21:56

    Simple: Just draw a bunch of polygons like:

    import pygame
    screen = pygame.display.set_mode((100, 100))
    While True:
       screen.fill((0, 0, 0))
       Pos = [(10, 10), (20, 10), (20, 20), (10, 20)]
       # first side (the front) in red
       pygame.draw.polygon(screen, (225, 0, 0), Pos)
       # outline in white
       pygame.draw.lines(screen, (225, 225, 225), Pos)
       # Second side (the back) in blue
       Pos2 = [(Pos[0[0]] + 2.5, Pos[0[1]] + 2.5), (Pos2[0[0]] + 5, Pos2[0[1]]), (Pos2[1[0]], Pos2[1[1]] + 5), (Pos2[0[0]], Pos2[0[1]] + 5)]
       pygame.draw.polygon(screen, (0, 0, 225), Pos2)
       pygame.draw.lines(screen, (225, 225, 225), Pos2)
       # Third side (the left but just 2 lines(not really)) in green 
       Pos3 = [Pos[0], Pos2[0], Pos2[3], Pos[3]]
       pygame.draw.polygon(screen, (0, 225, 0), Pos3)
       pygame.draw.lines(screen, (225, 225, 225), Pos3)
       # Fourth side (the right) in purple
       Pos4 = [Pos[1], Pos2[1], Pos2[2], Pos[2]]
       pygame.draw.polygon(screen, (225, 0, 225), Pos4)
       pygame.draw.lines(screen, (225, 225, 225), Pos4)
       pygame.display.flip()
    

    & there is a simple cube & I will soon provide a link for the full code to be able to rotate the cube & resize it

    This should give you an equivalent of what you would get by using OpenGL

    0 讨论(0)
  • 2020-12-29 22:03

    It is easy to make 3D driver for PyGame. PyGame has some assets for 3D game development. I am developing Py3D driver using PyGame now. When I finish, I'll show you link to download Py3D. I tried to make 3D game with PyGame, and I needed just small addon for PyGame. It is wrong you think you must use SDL, PyOpenGL, OpenGL, PyQt5, Tkinter. All of them are wrong for making 3D games. OpenGL and PyOpenGL or Panda3D are very hard to learn. All my games made on those drivers were awful. PyQt5 and Tkinter aren't drivers for making games, but they've got addons for it. Don't try to make any game on those drivers. All drivers where we need to use the math module are hard. You can easily make small addon for them, I think everybody can make driver for PyGame in 1-2 weeks.

    0 讨论(0)
  • 2020-12-29 22:09

    No, Pygame is a wrapper for SDL, which is a 2D api. Pygame doesn't provide any 3D capability and probably never will.

    3D libraries for Python include Panda3D and DirectPython, although they are probably quite complex to use, especially the latter.

    0 讨论(0)
  • 2020-12-29 22:11

    Well, if you can do 2d you can always do 3d. All 3d really is is skewed 2 dimensional surfaces giving the impression you're looking at something with depth. The real question is can it do it well, and would you even want to. After browsing the pyGame documentation for a while, it looks like it's just an SDL wrapper. SDL is not intended for 3d programming, so the answer to the real question is, No, and I wouldn't even try.

    0 讨论(0)
  • 2020-12-29 22:11

    You can do pseudo-3d games ( like "Doom" ) with pygame only:

    http://code.google.com/p/gh0stenstein/

    and if you browse the pygame.org site you may find more "3d" games done with python and pygame.

    However, if you really want to go into 3d programming you should look into OpenGl, Blender or any other real 3d lib.

    0 讨论(0)
提交回复
热议问题