[PyQt] Creating a projection matrix in Qt OpenGL
alan moore
me at alandmoore.com
Wed Mar 20 03:42:23 GMT 2019
I'm working on a small demo of OpenGL in PyQt using the QOpenGLWidget.
My demo works except that whenever I translate it with a negative Z, the
back side of the drawing is getting cut off. It seems like I must not
be setting the projection matrix correctly.
Below is my overridden resizeGL() method that sets up the matrix. Am I
doing this correctly?
def resizeGL(self, width, height):
super().resizeGL(width, height)
self.gl.glViewport(0, 0, self.width(), self.height())
near_plane = 1
far_plane = 200
angle = 45
aspect = self.width() / self.height()
self.projection = qtg.QMatrix4x4()
self.projection.setToIdentity()
self.projection.perspective(
angle, aspect, near_plane, far_plane)
self.gl.glMatrixMode(self.gl.GL_PROJECTION)
self.gl.glLoadIdentity()
self.gl.glLoadMatrixd(self.projection.data())
More information about the PyQt
mailing list