【问题标题】:Error in pygame simulation "OpenGL.error.NullFunctionError"pygame模拟错误“OpenGL.error.NullFunctionError”
【发布时间】:2021-08-28 08:19:25
【问题描述】:

我正在尝试在 python 中运行这段代码,我已经有了 PyOpenGL 库和 pygame 库。这是一个显示中间轴定理的模拟。

#!/usr/bin/env python
# Intermediate Axis Theorem Simulator
# Author: Franco Barpp Gomes (https://github.com/Hyodar)

# -*- coding: utf-8 -*-

# Imported modules
# ----------------------------------------------------------------------------

import pygame.locals as pygl
import pygame

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

from utils.constants import WINDOW_SIZE
from utils.constants import NUM_FRAMES

from utils.classes.Screen import Screen
from utils.classes.World import World
from utils.classes.Tbar import Tbar

# ----------------------------------------------------------------------------
# Main
# ----------------------------------------------------------------------------


def main():

    print('[*] Creating pygame display...')
    pygame.init()
    display = pygame.display.set_mode(WINDOW_SIZE, pygl.DOUBLEBUF | pygl.OPENGL)

    world = World()
    tbar = Tbar()
    world.add_object(tbar)

    screen = Screen(display=display, tbar=tbar)

    print('[*] Initializing scene...')
    world.init_scene()

    frame = 0
    paused = False

    print('[*] Starting pygame loop...')
    while frame < NUM_FRAMES:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print('[*] Quit event detected. Stopping pygame...')
                pygame.quit()
                exit(0)
            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_SPACE:
                    paused = not paused
                    if paused:
                        screen.show_paused_message()

        if not paused:
            world.clear()
            world.render()
            screen.render()

            frame += 1

            pygame.display.flip()
            pygame.time.wait(10)

    print('[*] Simulation finished successfully')


if __name__ == '__main__':
    main()

但是,现在我得到了这个错误,

[*] Creating pygame display...
[*] Initializing scene...
2020-08-13 20:41:59.869 python3[22970:759075] GLUT Warning: glutInit being called a second time.
[*] Starting pygame loop...
Traceback (most recent call last):
  File "src/main.py", line 76, in <module>
    main()
  File "src/main.py", line 64, in main
    world.render()
  File "/Users/silviaar/python_projects/intermediate-axis-theorem-master/src/utils/classes/World.py", line 71, in render
    obj.render()
  File "/Users/silviaar/python_projects/intermediate-axis-theorem-master/src/utils/classes/Tbar.py", line 86, in render
    self.handle.render(self.cm, self.handle_relpos)
  File "/Users/silviaar/python_projects/intermediate-axis-theorem-master/src/utils/classes/Cylinder.py", line 56, in render
glutWireCylinder(self.radius, self.height, self.slices, self.stacks)
  File "/Users/silviaar/anaconda3/lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 407, in __call__
    self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutWireCylinder, check for bool(glutWireCylinder) before calli
ng

不知道怎么了 你能帮帮我吗?

【问题讨论】:

    标签: python pygame physics


    【解决方案1】:

    我正在尝试运行相同的代码,但到目前为止,我遇到了一些关于 FreeGLUT 的问题。如果您尝试像我一样在 Windows 上运行它,那么您可能会遇到与我最初遇到的相同的问题。根据我的阅读,PyOpenGL 包缺少 FreeGLUT for Windows 的一些内容。我找到的解决方法是卸载我拥有的 OpenGL 包并在此处 pip 安装这个自定义包:

    https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl

    它有你需要的所有额外的东西。另一种方法是追踪 dll 文件并将它们放置在正确的目录中,但重新安装更容易并且似乎工作正常。希望这就是您遇到的问题! 目前,当我运行它时,我收到了这个错误:

    glutWireCylinder(self.radius, self.height, self.slices, self.stacks)
    OSError: exception: access violation reading 0x0000001C
    

    我已经联系了 github 上的代码作者,他说在 Windows 上运行它显然存在问题,但它在 Linux 上运行良好。 让我知道重新安装是否有帮助,如果我让代码运行,我会告诉你!

    更新:在与代码作者交谈后,他删除了所有 GLUT 依赖项,现在它似乎运行良好。只需从 github 链接重新下载代码:

    https://github.com/Hyodar/intermediate-axis-theorem

    现在应该可以正常工作了!

    【讨论】:

    • 完美,没问题!
    猜你喜欢
    • 1970-01-01
    • 2019-07-04
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多