Cube rotation with pyopengl and pyqt

by: nephilim_boy, 9 years ago

Last edited: 9 years ago

hi all :)
I'm very new to python. I have a problem with my code, it's a very simple rotating cube. I don't have any problem with this cube code with pygame screen but when I use it with pyqt (or Qt designer widgets), it runs but it shows nothing!!!

I'll be if glad someone could help me with it.tnx in advance

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL import *
from PyQt5.QtOpenGL import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
import sys,time
class MainWindow(QGLWidget):
    def __init__(self):
        super(MainWindow, self).__init__()

        self.widget = glWidget(self)
        mainLayout = QVBoxLayout()
        mainLayout.addWidget(self.widget)
        self.setLayout(mainLayout)

class glWidget(QGLWidget):

    def __init__(self, parent):
        QGLWidget.__init__(self, parent)

        #self.setMinimumSize(400, 400)

        self.verticies = (
            (1,-1,-1),
            (1,1,-1),
            (-1,1,-1),
            (-1,-1,-1),
            (1,-1,1),
            (1,1,1),
            (-1,-1,1),
            (-1,1,1))
        self.edges = (
            (0,1),
            (0,3),
            (0,4),
            (2,1),
            (2,3),
            (2,7),
            (6,3),
            (6,4),
            (6,7),
            (5,1),
            (5,4),
            (5,7))

    def paintGL(self):
        while True:
            #glRotatef(1,3,1,1)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glBegin(GL_LINE)
            for self.edge in self.edges:
                for self.vertex in self.edge:
                    glVertex3fv(self.verticies[self.vertex])
            glEnd()
            glFlush()
            time.sleep(1)      

    def resizeGL(self, w, h):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(-50, 50, -50, 50, -50.0, 50.0)
        glViewport(0, 0, w, h)

    def initializeGL(self):

        #glClearColor(0.0, 0.0, 0.0, 1.0)
        gluPerspective(45,800/600,0.1,50.0)
        glTranslatef(0.0,0.0,-5)
        glRotatef(0,0,0,0)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.exec_()




You must be logged in to post. Please login or register an account.



Edited to include code tags to make it easier to read.

As for the question, no idea, never tried to embed opengl with PyQt. Might be a worthy question to reddit.com/r/learnpython

-Harrison 9 years ago

You must be logged in to post. Please login or register an account.