首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python/PyOpenGL:管道

Python/PyOpenGL:管道
EN

Stack Overflow用户
提问于 2015-09-14 00:09:30
回答 1查看 100关注 0票数 1

我正在努力学习PyOpenGL,并且我理解其中的一些概念,除了连接事物的“管道”(管道)字符。例如,这是多维数据集的代码:

代码语言:javascript
复制
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

我知道双重缓冲是什么,但我仍然不完全理解这个或另一个东西意味着什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-14 00:22:39

它们实际上只是整数常量。这是一种从用户获取输入的方便方法。管道运算符(|)是整数的位或数。例如,15 x-128=143个,即二进制数为00001111 \ 10000000 = 10001111。

下面是它的实际工作方式:

代码语言:javascript
复制
>>> 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'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32555755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档