简体   繁体   English

运行pyglet时出现NameError

[英]NameError when running pyglet

I'm trying to do my uni project and I'm using pyglet for the task . 我正在尝试做我的uni项目,并且正在使用pyglet来完成任务。 This is part of the code that makes me a problem. 这是使我有问题的代码的一部分。

from pyglet.gl import *
from pyglet.window import key
from pyglet.window import mouse


window=pyglet.window.Window(resizable=True)

@window.event
def on_draw():

    glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE)
    glutInitWindowSize (width, height)
    glutInitWindowPosition (100, 100)


    glClearColor( 1.0, 1.0, 1.0, 1.0)
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    myObject ()
    glutSwapBuffers() 

When i searched for functions glutInitDisplayMode , glutInitWindowSize and glutInitWindowPosition it only shows pyOpenGL threads, so do they exist for pyglet or im just defining them wrong? 当我搜索函数glutInitDisplayModeglutInitWindowSizeglutInitWindowPosition它仅显示pyOpenGL线程,那么它们是否存在于pyglet或只是将它们定义为错误?

Terminal Output: 终端输出:

glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE)

NameError: global name 'glutInitDisplayMode' is not defined NameError:全局名称'glutInitDisplayMode'未定义

and same is for other two 其他两个也是一样

So, glutInitDisplayMode is a GL function but as far as I know, it's not made avilable by Pyglet because it's not really needed. 因此, glutInitDisplayMode是GL函数,但据我所知,Pyglet并没有使它可用,因为它并不是真正需要的。

Now, these are some what speculations and correct me if I'm wrong. 现在,这些是一些猜测,如果我错了,可以纠正我。
But calling the following will set up the context for you: 但是调用以下内容将为您设置上下文:

pyglet.window.Window(...)

There for all these are unnecessary: 所有这些都是不必要的:

glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE)
glutInitWindowSize (width, height)
glutInitWindowPosition (100, 100)

Instead what you want to do is: 相反,您要做的是:

window = pyglet.window.Window(width=800, height=600)
window.set_location(100, 100)

There's also the option to create a specific config and context and inject: 还可以选择创建特定的配置和上下文并注入:

config = pyglet.gl.Config(double_buffer=True)
context = context = config.create_context(shared_context)
window = pyglet.window.Window(config=config, context=context)

Hope this clarify anything for you. 希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM