40 lines
937 B
Python
40 lines
937 B
Python
from PyQt5.QtCore import QTimer
|
|
from PyQt5.QtWidgets import QOpenGLWidget
|
|
from OpenGL.GL import *
|
|
from OpenGL.GLU import *
|
|
from editortool.map.selectbox import drawSelectBox
|
|
from editortool.map.camera import Camera
|
|
from editortool.map.grid import Grid
|
|
|
|
class GLWidget(QOpenGLWidget):
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self.timer = QTimer(self)
|
|
self.timer.timeout.connect(self.update)
|
|
self.timer.start(16) # ~60 FPS
|
|
self.camera = Camera()
|
|
self.grid = Grid()
|
|
|
|
def initializeGL(self):
|
|
glClearColor(0.392, 0.584, 0.929, 1.0)
|
|
glEnable(GL_DEPTH_TEST)
|
|
|
|
def resizeGL(self, w, h):
|
|
pass
|
|
|
|
def paintGL(self):
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
glLoadIdentity()
|
|
|
|
w = self.width()
|
|
h = self.height()
|
|
if h <= 0:
|
|
h = 1
|
|
if w <= 0:
|
|
w = 1
|
|
|
|
glViewport(0, 0, w, h)
|
|
self.camera.setup(w, h)
|
|
|
|
self.grid.draw()
|
|
drawSelectBox() |