0
我已經設置了一個用作opengl查看器的qt小部件。我的目標是將其用作紋理查看器和模型查看器。這就是爲什麼我創建了兩個不同的程序,並附加了不同的着色器以滿足我的需求。DrawElements崩潰Qt應用程序
我將所有對象存儲在自制的自定義類中,該類還存儲正確的對象程序ID。
在QGLWidget的paintGL函數中,我正在做所有需要完成的工作來繪製場景。
問題是,雖然模型的工作,當我試圖簡單地切換程序,並繪製一個簡單的四,窗口崩潰,並在控制檯發生了什麼我沒有錯誤。通過添加打印語句,我發現gldrawElements函數正在導致崩潰,但我找不到原因。
def paintGL(self):
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
for ob in self.objects:
activeBuffers = []
# GL.glLinkProgram(ob.program)
GL.glLinkProgram(ob.program)
GL.glUseProgram(ob.program)
# print ob.vBuffer, ob.uvBuffer, ob.nBuffer, ob.iBuffer
if ob.program == self.programs[0]:
# Update Panning
loc = GL.glGetUniformLocation(ob.program, "panX")
GL.glUniform1f(loc, self.panX)
loc = GL.glGetUniformLocation(ob.program, "panY")
GL.glUniform1f(loc, self.panY)
# Update Scale in Shader
loc = GL.glGetUniformLocation(ob.program, "scale")
GL.glUniform1f(loc, self.scale)
# Update Theta in Shader
loc = GL.glGetUniformLocation(ob.program, "theta")
GL.glUniform3fv(loc, 1, self.theta)
# Bind Vertex VBO
ob.vBuffer.bind()
vpos = GL.glGetAttribLocation(ob.program, "vPosition")
GL.glVertexAttribPointer(
vpos, 3, GL.GL_FLOAT, GL.GL_FALSE, 0, None)
GL.glEnableVertexAttribArray(vpos)
if ob.uvBuffer:
# Bind UVs
ob.uvBuffer.bind()
uvpos = GL.glGetAttribLocation(ob.program, "uvPosition")
print ob.program, uvpos
if not uvpos == -1:
GL.glVertexAttribPointer(uvpos, 2, GL.GL_FLOAT, GL.GL_FALSE, 0, None)
GL.glEnableVertexAttribArray(uvpos)
activeBuffers.append(ob.uvBuffer)
else:
ob.uvBuffer.unbind()
if ob.nBuffer:
# Bind Normals
ob.nBuffer.bind()
npos = GL.glGetAttribLocation(ob.program, "nPosition")
GL.glVertexAttribPointer(npos, 3, GL.GL_FLOAT, GL.GL_FALSE, 0, None)
GL.glEnableVertexAttribArray(npos)
activeBuffers.append(ob.nBuffer)
# Bind Indices VBO
ob.iBuffer.bind()
activeBuffers.append(ob.iBuffer)
# if ob.program == self.programs[1]:
# print 'Continuing'
# continue
GL.glDrawElements(
GL.GL_TRIANGLES, ob.iLen, GL.GL_UNSIGNED_INT, None)
# Unbind everything
for buf in activeBuffers:
buf.unbind()
我創建提前像
def makeTextureQuad(self):
ob = globject()
ob.vBuffer = np.array(quadverts, dtype=np.float32)
ob.vBuffer = glvbo.VBO(ob.vBuffer)
ob.vLen = len(quadverts)
ob.iBuffer = np.array(quadfaces, dtype=np.int32)
ob.iBuffer = glvbo.VBO(ob.iBuffer, target=GL.GL_ELEMENT_ARRAY_BUFFER)
ob.iLen = len(quadfaces) * 3
ob.uvBuffer = np.array(quaduvs, dtype=np.float32)
ob.uvBuffer = glvbo.VBO(ob.uvBuffer)
# ob.nBuffer = np.array(quadnorms, dtype=np.float32)
# ob.nBuffer = glvbo.VBO(ob.nBuffer)
ob.program = self.programs[1]
return ob
感謝的對象