我正在尝试使用 OpenGL 和 Pygame 创建一个 3d 魔方。但是,当我尝试在GL_QUADS
我创建的表面上绘制线条时,它们不会出现。
我试过把线放在GL_LINES
后面,GL_QUADS
但它们仍然没有显示为黑线。
有没有人有办法解决吗?另外,我将如何调整线条的粗细?
这是代码的样子:
def draw(self):
glEnable(GL_DEPTH_TEST)
glBegin(GL_LINES)
glColor3fv((0, 0, 0))
glVertex3fv((self.x - self.len, self.y + self.len, self.z - self.len))
glVertex3fv((self.x - self.len, self.y + self.len, self.z - self.len))
glColor3fv((0, 0, 0))
glVertex3fv((self.x + self.len, self.y + self.len, self.z + self.len))
glVertex3fv((self.x + self.len, self.y - self.len, self.z - self.len))
glColor3fv((0, 0, 0))
glVertex3fv((self.x - self.len, self.y + self.len, self.z - self.len))
glVertex3fv((self.x - self.len, self.y + self.len, self.z - self.len))
glColor3fv((0, 0, 0))
glVertex3fv((self.x - self.len, self.y - self.len, self.z + self.len))
glVertex3fv((self.x - self.len, self.y - self.len, self.z - self.len))
glEnd()
glBegin(GL_QUADS)
glColor3fv(colors[0])
# fix z
glVertex3fv((self.x - self.len, self.y - self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y - self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y + self.len, self.z - self.len))
glVertex3fv((self.x - self.len, self.y + self.len, self.z - self.len))
glColor3fv(colors[1])
glVertex3fv((self.x - self.len, self.y - self.len, self.z + self.len))
glVertex3fv((self.x + self.len, self.y - self.len, self.z + self.len))
glVertex3fv((self.x + self.len, self.y + self.len, self.z + self.len))
glVertex3fv((self.x - self.len, self.y + self.len, self.z + self.len))
# fix x
glColor3fv(colors[2])
glVertex3fv((self.x - self.len, self.y - self.len, self.z - self.len))
glVertex3fv((self.x - self.len, self.y + self.len, self.z - self.len))
glVertex3fv((self.x - self.len, self.y + self.len, self.z + self.len))
glVertex3fv((self.x - self.len, self.y - self.len, self.z + self.len))
glColor3fv(colors[3])
glVertex3fv((self.x + self.len, self.y - self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y + self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y + self.len, self.z + self.len))
glVertex3fv((self.x + self.len, self.y - self.len, self.z + self.len))
# fix y
glColor3fv(colors[4])
glVertex3fv((self.x - self.len, self.y - self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y - self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y - self.len, self.z + self.len))
glVertex3fv((self.x - self.len, self.y - self.len, self.z + self.len))
glColor3fv(colors[5])
glVertex3fv((self.x - self.len, self.y + self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y + self.len, self.z - self.len))
glVertex3fv((self.x + self.len, self.y + self.len, self.z + self.len))
glVertex3fv((self.x - self.len, self.y + self.len, self.z + self.len))
glEnd()