我已经开始使用Python编写一个人体 - OpenGL来学习库,但是当我使用glColor3fv((1.000, 0.498, 0.314))
时,它只填充表面的一部分而不是全部表面。
我所有的进口商品:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
我在这里上了一堂课:
class body():
def __init__(self):
self.vertices = (
(0.05, -0.15, -0.25),
(0.05, 0.05, -0.25),
(0.05, 0.15, -0.15),
(0.05, 0.15, 0.15),
(0.05, 0.05, 0.25),
(0.05, -0.15, 0.25),
(0.05, -0.25, 0.15),
(0.05, -0.25, -0.15),
(-0.05, -0.15, -0.25),
(-0.05, 0.05, -0.25),
(-0.05, 0.15, -0.15),
(-0.05, 0.15, 0.15),
(-0.05, 0.05, 0.25),
(-0.05, -0.15, 0.25),
(-0.05, -0.25, 0.15),
(-0.05, -0.25, -0.15)
)
self.edges = (
(0, 1),
(0, 8),
(1, 2),
(1, 9),
(2, 3),
(2, 10),
(3, 4),
(3, 11),
(4, 5),
(4, 12),
(5, 6),
(5, 13),
(6, 7),
(6, 14),
(7, 0),
(7, 15),
(8, 9),
(9, 10),
(10, 11),
(11, 12),
(12, 13),
(13, 14),
(14, 15),
(15, 8),
)
self.surfaces = (
(0, 1, 8, 9),
(1, 2, 9, 10),
(2, 3, 10, 11),
(3, 4, 11, 12),
(4, 5, 12, 13),
(5, 6, 13, 14),
(6, 7, 14, 15),
(7, 0, 15, 8),
(0, 1, 2, 3, 4, 5, 6, 7),
(8, 9, 10, 11, 12, 13, 14, 15)
)
我的课目前只有一个功能:
def create_part(self):
glBegin(GL_LINES)
for edge in self.edges:
for vertex in edge:
glVertex3fv(self.vertices[vertex])
glEnd()
glBegin(GL_QUADS)
for surface in self.surfaces:
for vertex in surface:
glColor3fv((1.000, 0.498, 0.314))
glVertex3fv(self.vertices[vertex])
glEnd()
最后在屏幕上看到对象:
""" TEST"""
x_object = body().create_part
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, 0.0, -5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glRotatef(1, 10, 3, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
x_object()
pygame.display.flip()
pygame.time.wait(10)
main()
问题应该是create_part()
函数,但我无法理解为什么