Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用PyOpenGL和PyQt5转换对象时出错_Python_Python 3.x_Opengl_Pyqt5_Pyopengl - Fatal编程技术网

Python 使用PyOpenGL和PyQt5转换对象时出错

Python 使用PyOpenGL和PyQt5转换对象时出错,python,python-3.x,opengl,pyqt5,pyopengl,Python,Python 3.x,Opengl,Pyqt5,Pyopengl,我正在尝试使用矢量着色器变换对象。但glUniformMatrixfv在执行时会引发错误 vertex_shader = shaders.compileShader( """ #version 330 layout (location = 0) in vec3 pos; layout (location = 1) in vec3 color;

我正在尝试使用矢量着色器变换对象。但glUniformMatrixfv在执行时会引发错误

vertex_shader = shaders.compileShader(
                """
                #version 330
                layout (location = 0) in vec3 pos;
                layout (location = 1) in vec3 color;
                uniform mat4 movement;
                out vec4 f_color;
                void main() 
                { 
                    gl_Position = movement * vec4(pos, 1.0);
                    f_color = vec4(color, 1.0);
                }
                """
                , GL_VERTEX_SHADER)


fragment_shader = shaders.compileShader(
                """
                #version 330
                in vec4 f_color;
                out vec4 gl_FragColor;
                void main() 
                {
                    gl_FragColor = f_color;
                }
                """
                , GL_FRAGMENT_SHADER
                )
使用这些着色器的程序代码为:

def draw_object(self):
    self.vao = glGenVertexArrays(1)
    glBindVertexArray(self.vao)

    self.vbo_buffer = np.array([
        -0.4, 0.2, 0.0, 0.0, 1.0, 0.0,
        -0.8, -0.2, 0.0, 1.0, 1.0, 0.0,
        0.0, -0.2, 0.0, 0.0, 1.0, 1.0,
        0.2, -0.4, 0.0, 1.0, 0.0, 0.0,
        0.8, -0.4, 0.0, 0.0, 0.0, 1.0,
        0.8, 0.4, 0.0, 0.0, 1.0, 1.0,
        0.2, -0.4, 0.0, 1.0, 0.0, 0.0,
        0.8, 0.4, 0.0, 0.0, 0.0, 1.0,
        0.2, 0.4, 0.0, 0.0, 1.0, 0.0
    ], dtype=np.float32)

    self.vbo = glGenBuffers(1)
    glBindBuffer(GL_ARRAY_BUFFER, self.vbo)
    glBufferData(GL_ARRAY_BUFFER, self.vbo_buffer.nbytes, self.vbo_buffer, GL_DYNAMIC_DRAW)

    self.vertex_position = glGetAttribLocation(self.shader, bytestr('pos'))
    glVertexAttribPointer(self.vertex_position, 3, GL_FLOAT, GL_FALSE, 24, None)
    glEnableVertexAttribArray(self.vertex_position)

    self.vertex_color = glGetAttribLocation(self.shader, bytestr('color'))
    glVertexAttribPointer(self.vertex_color, 3, GL_FLOAT, GL_FALSE, 24, ctypes.c_void_p(12))
    glEnableVertexAttribArray(self.vertex_color)

    self.movement = glGetUniformLocation(self.shader, 'movement')
    glUniformMatrix4fv(self.movement, 1, GL_FALSE, glm.value_ptr(self.svp_matrix))

    glBindBuffer(GL_ARRAY_BUFFER, 0)
    glBindVertexArray(0)


def calculate_mvp(self):
    self.projection_matrix = glm.perspective(glm.radians(self.fieldOfView), self.glWinWidth / self.glWinHeight, 
                             self.nearPlane, self.farPlane)
    self.view_matrix = glm.rotate(glm.mat4(1.0), float(self.xRot), glm.vec3(1.0, 0.0, 0.0)) * \
                       glm.rotate(glm.mat4(1.0), float(self.yRot), glm.vec3(0.0, 1.0, 0.0)) * \
                       glm.rotate(glm.mat4(1.0), float(self.zRot), glm.vec3(0.0, 0.0, 1.0)) * \
                       glm.translate(glm.mat4(1.0), glm.vec3(self.xTranslate, self.yTranslate, self.zTranslate))
    self.scale_matrix = glm.scale(glm.mat4(1.0), glm.vec3(self.scale_factor))

    self.svp_matrix = self.projection_matrix * self.view_matrix * self.scale_matrix


def paintGL(self):
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glUseProgram(self.shader)
    try:
        glBindVertexArray(self.vao)
        glDrawArrays(GL_TRIANGLES, 0, 9) 
    finally:
        glBindVertexArray(0)
        glUseProgram(0)
        glFlush()
我得到的错误是:

文件“C:\Program Files\Python37\lib\site packages\OpenGL\platform\baseplatform.py”,第415行,在 __召唤__

返回self(*args,**已命名)

OpenGL\u accelerate.errorchecker.\u errorchecker.glCheckError中第58行的文件“src\errorchecker.pyx” OpenGL.error.GLError:GLError(

err=1282,
description=b“无效操作”,
基本操作=glUniformMatrix4fv,
pyArgs=(
0,
1.
GL_FALSE,
,
),
汽车=(
0,
1.
GL_FALSE,
,
),
cArguments=(
0,
1.
GL_FALSE,
,
)
)

如果你知道如何解决这个问题,请在下面分享。谢谢

在当前安装的默认统一块程序中设置统一变量的值。
这意味着在设置变量之前,必须先安装程序。如果没有当前程序对象,则生成
GL\u INVALID\u操作
错误

在glUniformMatrix4fv之前安装程序:

self.movement=glGetUniformLocation(self.shader,“movement”)
glUseProgram(self.shader)
glUniformMatrix4fv(自移动,1,GL_假,glm.value_ptr(自svp_矩阵))
   err = 1282,
   description = b'invalid operation',
   baseOperation = glUniformMatrix4fv,
   pyArgs = (
           0,
           1,
           GL_FALSE,
           <OpenGL.GLU.tess.LP_c_float object at 0x0000013A37B1B4C8>,
   ),
   cArgs = (
           0,
           1,
           GL_FALSE,
           <OpenGL.GLU.tess.LP_c_float object at 0x0000013A37B1B4C8>,
   ),
   cArguments = (
           0,
           1,
           GL_FALSE,
           <OpenGL.GLU.tess.LP_c_float object at 0x0000013A37B1B4C8>,
   )