Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyqt-opengl-drawing-simple-scenes

import sys
from OpenGL.GL import *
from OpenGL.GLU import *
from PyQt5 import QtGui
from PyQt5.QtOpenGL import *
from PyQt5 import QtCore, QtWidgets, QtOpenGL


class Ui_MainWindow(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(Ui_MainWindow, self).__init__()
        self.widget = glWidget()
        self.button = QtWidgets.QPushButton('Test', self)
        mainLayout = QtWidgets.QHBoxLayout()
        mainLayout.addWidget(self.widget)
        mainLayout.addWidget(self.button)
        self.setLayout(mainLayout)


class glWidget(QGLWidget):
    def __init__(self, parent=None):
        QGLWidget.__init__(self, parent)
        self.setMinimumSize(640, 480)

    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        glTranslatef(-2.5, 0.5, -6.0)
        glColor3f( 1.0, 1.5, 0.0 );
        glPolygonMode(GL_FRONT, GL_FILL);
        glBegin(GL_TRIANGLES)
        glVertex3f(2.0,-1.2,0.0)
        glVertex3f(2.6,0.0,0.0)
        glVertex3f(2.9,-1.2,0.0)
        glEnd()
        glFlush()

    def initializeGL(self):
        glClearDepth(1.0)              
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glShadeModel(GL_SMOOTH)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()                    
        gluPerspective(45.0,1.33,0.1, 100.0) 
        glMatrixMode(GL_MODELVIEW)


if __name__ == '__main__':    
    app = QtWidgets.QApplication(sys.argv)    
    Form = QtWidgets.QMainWindow()
    ui = Ui_MainWindow(Form)    
    ui.show()    
    sys.exit(app.exec_())
Comment

PREVIOUS NEXT
Code Example
Python :: Modifying a set in Python 
Python :: Python Deleting Attributes and Objects 
Python :: REST APIs with Flask and Python free download 
Python :: Python match.start(), match.end() 
Python :: get external ip address python 
Python :: python read and write lines in file 
Python :: tornado cookies authorization 
Python :: Get hours, minutes, seconds, and microseconds using time class 
Python :: region python 
Python :: pip package dynamic setup.py example 
Python :: python dateien auflisten 
Python :: python keep program running after crash 
Python :: assemblyai 
Python :: why do we write f before double quotes in print statement in python 
Python :: sample regression algorithm using pipeline with hyperparameter tuning 
Python :: threshold image segmentation code python 
Python :: bagging algorithm 
Python :: HIDING AND ENCRYPTING PASSWORDS IN PYTHON USING MASKPASS MODULE 
Python :: django admin difference between superuser and staff 
Python :: restart kernel python 
Python :: subsetting a column and giving it a value using numpy 
Python :: Mapping using dictionary 
Python :: filetype: env "DB_PASSWORD" 
Python :: matrix of matrices python grepper 
Python :: the 100th iteration in python next() 
Python :: python print list in dictionary 
Python :: (function(a_,%20b_)%20%7B%20with%20(a_)%20with%20(b_)%20return%20summary%20%7D) 
Python :: python: subset top 5 values in a column 
Python :: reportlab drawimage issues with png transparency background 
Python :: add fully connected layers at encoder of autoencoder 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =