【问题标题】:Error with PyOpenGL and glutSolidCylinderPyOpenGL 和 glutSolidCylinder 出错
【发布时间】:2013-09-14 13:37:35
【问题描述】:

我正在尝试使用 PyOpenGL(以及 PyODE)绘制一个实心圆柱体,但是我遇到了以下错误:

OpenGL.error.NullFunctionError: Attempt to call an undefined function glutSolidCylinder, check for bool(glutSolidCylinder) before calling

我有以下三个导入,并且一直在使用其他 glut* 调用(glutSolidSphere、glutSolidCube 等)没有问题,但是这个给我带来了问题。

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
...
glutSolidCylinder(RADIUS, LENGTH, SLICES, STACKS)

我使用的是 Python 2.7,当我使用 print(bool(glutSolidCylinder)) 进行测试时,我收到了 False

我也使用 Pip 来安装 PyOpenGL。

【问题讨论】:

    标签: python-2.7 pyopengl


    【解决方案1】:

    最初的 GLUT 实现没有柱面函数,但 freeglut 有 (source),(然后,Python 2.7.1、PyOpenGL 3.0.1 和 FreeGLUT 2.6.0 一起在 Ubuntu 12.04 上运行良好)。

    不过,您也可以在 Python 中使用 GLU 函数制作圆柱体:

    quadratic = gluNewQuadric()
    gluCylinder(quadratic, BASE, TOP, HEIGHT, SLICES, STACKS)      # to draw the lateral parts of the cylinder;
    gluDisk(quadratic, INNER_RADIUS, OUTER_RADIUS, SLICES, LOOPS)  # call this two times in the appropriate environment to draw the top and bottom part of the cylinder with INNER_RADIUS=0.
    

    【讨论】:

    • 这就是我最终做的事情,但是我有点困惑,因为 PyOpenGL documentation clearly states 有一个 glutSolidCylinder 方法,但是当你尝试调用它时它并不存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 2012-03-06
    • 2020-08-12
    • 2011-01-21
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多