import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
vertices = ((1, 1, 1), (1, 1, -1), (1, -1, -1), (1, -1, 1),
(-1, 1, 1), (-1, -1, -1), (-1, -1, 1), (-1, 1, -1))
edges = ((0, 4, 3), (6, 4, 3), (1, 3, 2), (5, 7, 2), (0, 4, 1), (7, 1, 4),
(3,6, 2), (5, 1, 6), (0, 3, 1), (2, 3, 5), (6, 5, 4), (7, 2, 4))
def draw_cube():
glBegin(GL_TRIANGLES)
for edge in edges:
for index in edge:
glVertex3fv(vertices[index])
glEnd()
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0, 0, -5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
draw_cube()
pygame.display.flip()
pygame.time.wait(20)
main()
输出量:
所需输出:
2条答案
按热度按时间zbq4xfa01#
定义一个颜色列表,其中一种颜色用于立方体的侧面:
使用
glColor3fv
设置颜色:启用Depth Test:
另请参阅PyGame和OpenGL即时模式
注意,你的脸索引也有问题。最小正确示例:
u4vypkhs2#
你好,请检查此链接Python Color Constants Module,然后创建一个变量
或将其插入到构建三角形的任何位置
然后让我们说它是一个平台:
我想应该可以