作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想用python制作一个openGL项目。下面的代码正在创建显示图形的窗口。
import os
import glfw
from OpenGL.GL import *
class renderwindow():
'''GLFW Renderting window class'''
def __init__(self):
#save current working directory
cwd = os.getcwd()
#initialize glfw
glfw.glfwInit()
#restore cws
os.chdir(cwd)
#version hints
glfw.glfwWindowHint()
glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE,
glfw.GLFW_OPENGL_CORE_PROFILE)
# make a window
self.width, self.height = 640, 480
self.aspect = self.width / float(self.height)
self.win = glfw.glfwCreateWindow(self.width, self.height,
b'simpleglfw')
# make the context current
glfw.glfwMakeContextCurrent(self.win)
def main(self):
glViewport(0, 0, self.width, self.height)
glEnable(GL_DEPTH_TEST)
glClearColor(0.5, 0.5, 0.5, 1.0)
Traceback (most recent call last):
File "/snap/pycharm-community/192/plugins/python-ce/helpers/pydev/pydevd.py", line 1438, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/snap/pycharm-community/192/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/surface/Final-Year-Project/FYP/Main.py", line 6, in <module>
class main():
File "/home/surface/Final-Year-Project/FYP/Main.py", line 29, in main
rw = renderwindow()
File "/home/surface/Final-Year-Project/FYP/Open_GL_project1/RenderWIndow.py", line 16, in __init__
glfw.glfwInit()
AttributeError: module 'glfw' has no attribute 'glfwInit'
Process finished with exit code 1
最佳答案
方法名不是 glfwInit
, 是 init
.这也适用于其他方法。 (window_hint
、create_window
、make_context_current
):
import os
import glfw
from OpenGL.GL import *
class renderwindow():
'''GLFW Renderting window class'''
def __init__(self):
#save current working directory
cwd = os.getcwd()
#initialize glfw
glfw.init()
#restore cws
os.chdir(cwd)
#version hints
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE)
glfw.window_hint(glfw.OPENGL_PROFILE,
glfw.OPENGL_CORE_PROFILE)
# make a window
self.width, self.height = 640, 480
self.aspect = self.width / float(self.height)
self.win = glfw.create_window(self.width, self.height,
'simpleglfw', None, None)
# make the context current
glfw.make_context_current(self.win)
def main(self):
glViewport(0, 0, self.width, self.height)
glEnable(GL_DEPTH_TEST)
glClearColor(0.5, 0.5, 0.5, 1.0)
import glfw.GLFW as glfw
:
import os
#import glfw
import glfw.GLFW as glfw
from OpenGL.GL import *
class renderwindow():
'''GLFW Renderting window class'''
def __init__(self):
#save current working directory
cwd = os.getcwd()
#initialize glfw
glfw.glfwInit()
#restore cws
os.chdir(cwd)
#version hints
glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MAJOR, 3)
glfw.glfwWindowHint(glfw.GLFW_CONTEXT_VERSION_MINOR, 3)
glfw.glfwWindowHint(glfw.GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
glfw.glfwWindowHint(glfw.GLFW_OPENGL_PROFILE,
glfw.GLFW_OPENGL_CORE_PROFILE)
# make a window
self.width, self.height = 640, 480
self.aspect = self.width / float(self.height)
self.win = glfw.glfwCreateWindow(self.width, self.height,
'simpleglfw', None, None)
# make the context current
glfw.glfwMakeContextCurrent(self.win)
def main(self):
glViewport(0, 0, self.width, self.height)
glEnable(GL_DEPTH_TEST)
glClearColor(0.5, 0.5, 0.5, 1.0)
wnd = renderwindow()
关于python - 如何解决错误: AttributeError: module 'pyglfw' has no attribute 'pyglfwInit' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61381628/
我想为 python 安装 glow,所以我运行了 pip3 install glfw 但是当我尝试在代码中导入 glfw 时,出现这样的错误 Traceback (most rece
我想用python制作一个openGL项目。下面的代码正在创建显示图形的窗口。 import os import glfw from OpenGL.GL import * class renderwi
我是一名优秀的程序员,十分优秀!