如何为每对三角形添加颜色?
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()
输出:
所需的输出:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
定义一个带有一种颜色的颜色列表,用于立方体的侧面:
使用
glcolor3fv
设置颜色:启用:
See also
注意,您的面部索引也存在问题。最小正确的示例:
Define an list of colors with one color for side of the cube:
Use
glColor3fv
to set the color:Enable the Depth Test:
See also PyGame and OpenGL immediate mode
Note, there is also a problem with your face indices. Minimal correct example:
嗨,请查看此链接 python color Stonstants模块
然后创建一个变量
或在构建三角形的任何地方插入它
,然后说一个平台:
我认为它应该起作用
Hi so check out this link Python Color Constants Module
then create a variable
or insert it wherever u build the triangle
and then lets say its a platform:
it should work i think