Advertisement
Scramper

Using PyQt5 .ui with PyOpenGL python code

Oct 27th, 2017
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1. # from PyQt5.QtWidgets import *
  2. # from PyQt5.QtGui import *
  3. # from PyQt5.QtCore import *
  4. # from PyQt5.uic import *
  5. #
  6. # from OpenGL.GL import *
  7. # from OpenGL.GLU import *
  8. # from OpenGL.GLUT import *
  9. # from OpenGL.GLUT.freeglut import *
  10. import OpenGL.GL as gl
  11. import OpenGL.GLU as glu
  12. import OpenGL.GLUT as glut
  13. from PyQt5 import QtWidgets as qWidget
  14. from PyQt5 import QtGui as qGui
  15. from PyQt5 import QtCore as qCore
  16. from PyQt5 import uic
  17. import sys
  18. import os
  19.  
  20.  
  21. class mainWindow(qWidget.QMainWindow):
  22.     """Main window class."""
  23.  
  24.     def __init__(self, *args):
  25.         """Init."""
  26.         super(mainWindow, self).__init__(*args)
  27.         ui = os.path.join(os.path.dirname(__file__), 'test.ui')
  28.         uic.loadUi(ui, self)
  29.  
  30.     def setupUI(self):
  31.         print("\033[1;101m SETU6P UI \033[0m")
  32.         self.windowsHeight = self.openGLWidget.height()
  33.         self.windowsWidth = self.openGLWidget.width()
  34.  
  35.         self.openGLWidget.initializeGL()
  36.         self.openGLWidget.resizeGL(self.windowsWidth, self.windowsHeight)
  37.         self.openGLWidget.paintGL = self.paintGL
  38.         self.openGLWidget.initializeGL = self.initializeGL
  39.  
  40.     def paintGL(self):
  41.         self.loadScene()
  42.         glut.glutWireSphere(2, 13, 13)
  43.  
  44.     def initializeGL(self):
  45.         print("\033[4;30;102m INITIALIZE GL \033[0m")
  46.         gl.glEnable(gl.GL_BLEND)
  47.         gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
  48.         gl.glEnable(gl.GL_DEPTH_TEST)
  49.  
  50.     def loadScene(self):
  51.         gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
  52.         gl.glMatrixMode(gl.GL_PROJECTION)
  53.         gl.glLoadIdentity()
  54.         x, y, width, height = gl.glGetDoublev(gl.GL_VIEWPORT)
  55.         glu.gluPerspective(
  56.             45,  # field of view in degrees
  57.             width / float(height or 1),  # aspect ratio
  58.             .25,  # near clipping plane
  59.             200,  # far clipping plane
  60.         )
  61.  
  62.         gl.glMatrixMode(gl.GL_MODELVIEW)
  63.         gl.glLoadIdentity()
  64.  
  65.         glu.gluLookAt(12, 12, 12, 0, 0, 0, 0, 1, 0)
  66.  
  67.  
  68. app = qWidget.QApplication(sys.argv)
  69. window = mainWindow()
  70. window.setupUI()
  71. window.show()
  72. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement