我正在努力学习PyOpenGL,并且我理解其中的一些概念,除了连接事物的“管道”(管道)字符。例如,这是多维数据集的代码:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
verticies = (
(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,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,7),
(6,3),
(6,4),
(6,7),
(5,1),
(5,4),
(5,7)
)
def Cube():
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(verticies[vertex])
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,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)
Cube()
pygame.display.flip()
pygame.time.wait(10)
main()我不太清楚GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT是什么意思,或者DOUBLEBUF\OPENGL
我知道双重缓冲是什么,但我仍然不完全理解这个或另一个东西意味着什么。
发布于 2015-09-14 00:22:39
它们实际上只是整数常量。这是一种从用户获取输入的方便方法。管道运算符(|)是整数的位或数。例如,15 x-128=143个,即二进制数为00001111 \ 10000000 = 10001111。
下面是它的实际工作方式:
>>> from OpenGL.GL import *
>>> type(GL_COLOR_BUFFER_BIT)
OpenGL.constant.IntConstant
>>> int(GL_COLOR_BUFFER_BIT)
16384
>>> bin(GL_COLOR_BUFFER_BIT)
'0b100000000000000'
>>> int(GL_DEPTH_BUFFER_BIT)
256
>>> bin(GL_DEPTH_BUFFER_BIT)
'0b100000000'
>>> int(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
16640
>>> bin(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
'0b100000100000000'https://stackoverflow.com/questions/32555755
复制相似问题