diff --git a/setup/Show.py b/setup/Show.py index 634564f..12bb88a 100644 --- a/setup/Show.py +++ b/setup/Show.py @@ -1,4 +1,5 @@ from OpenGL.GL import * +import OpenGL.GL.shaders as shaders from Buffer import ElementProperties from ViewSettings import ViewSettings import numpy as np @@ -27,9 +28,8 @@ def update(self): def create_color_shaders(self): vertex_shader = """ - #version 150 - #extension GL_ARB_explicit_attrib_location : require - #extension GL_ARB_explicit_uniform_location : require + #version %d%d0 + layout(location = 0) in vec3 position; layout(location = 1) in vec3 color; layout(location = 2) in vec2 inTexCoords; @@ -47,7 +47,7 @@ def create_color_shaders(self): """ fragment_shader = """ - #version 150 + #version %d%d0 in vec3 newColor; in vec2 outTexCoords; out vec4 outColor; @@ -57,15 +57,16 @@ def create_color_shaders(self): outColor = vec4(newColor, 1.0); } """ + + major = glGetInteger(GL_MAJOR_VERSION) + minor = glGetInteger(GL_MINOR_VERSION) # Compiling the shaders - self.shader_col = OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(vertex_shader, GL_VERTEX_SHADER), - OpenGL.GL.shaders.compileShader(fragment_shader, GL_FRAGMENT_SHADER)) + self.shader_col = shaders.compileProgram(shaders.compileShader(vertex_shader % (major, minor), GL_VERTEX_SHADER), + shaders.compileShader(fragment_shader% (major, minor), GL_FRAGMENT_SHADER)) def create_texture_shaders(self): vertex_shader = """ - #version 150 - #extension GL_ARB_explicit_attrib_location : require - #extension GL_ARB_explicit_uniform_location : require + #version %d%d0 layout(location = 0) in vec3 position; layout(location = 1) in vec3 color; layout(location = 2) in vec2 inTexCoords; @@ -82,7 +83,7 @@ def create_texture_shaders(self): """ fragment_shader = """ - #version 150 + #version %d%d0 in vec3 newColor; in vec2 outTexCoords; out vec4 outColor; @@ -93,16 +94,19 @@ def create_texture_shaders(self): } """ - + + major = glGetInteger(GL_MAJOR_VERSION) + minor = glGetInteger(GL_MINOR_VERSION) # Compiling the shaders - self.shader_tex = OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(vertex_shader, GL_VERTEX_SHADER), - OpenGL.GL.shaders.compileShader(fragment_shader, GL_FRAGMENT_SHADER)) + self.shader_tex = shaders.compileProgram(shaders.compileShader(vertex_shader % (major, minor), GL_VERTEX_SHADER), + shaders.compileShader(fragment_shader % (major, minor), GL_FRAGMENT_SHADER)) def init_shader(self,shader): glUseProgram(shader) rot_x = pyrr.Matrix44.from_x_rotation(self.view.xrot) rot_y = pyrr.Matrix44.from_y_rotation(self.view.yrot) glUniformMatrix4fv(3, 1, GL_FALSE, rot_x * rot_y) + def draw_geometries(self, geos,clear_depth_buffer=True, translation_vec=np.array([0,0,0])): # Define translation matrices for opening @@ -121,23 +125,23 @@ def draw_geometries(self, geos,clear_depth_buffer=True, translation_vec=np.array glUniformMatrix4fv(4, 1, GL_FALSE, moves[geo.n]) glDrawElements(geo.draw_type, geo.count, GL_UNSIGNED_INT, ctypes.c_void_p(4*geo.start_index)) - def resizeGL(self, width, height): - glViewport(0, 0, width, height) - glMatrixMode(gl.GL_PROJECTION) - glLoadIdentity() - aspect = width / float(height) - - # aspect = 1.267 - # oratio = aspect - # if height * oratio > width: - # height = width / oratio - # # height = w / oratio - # else: - # width = height * oratio - - # print(aspect) - gluPerspective(45.0, aspect, 1.0, 100.0) - glMatrixMode(gl.GL_MODELVIEW) + # def resizeGL(self, width, height): + # glViewport(0, 0, width, height) + # glMatrixMode(gl.GL_PROJECTION) + # glLoadIdentity() + # aspect = width / float(height) + + # # aspect = 1.267 + # # oratio = aspect + # # if height * oratio > width: + # # height = width / oratio + # # # height = w / oratio + # # else: + # # width = height * oratio + + # # print(aspect) + # gluPerspective(45.0, aspect, 1.0, 100.0) + # glMatrixMode(gl.GL_MODELVIEW) def draw_geometries_with_excluded_area(self, show_geos, screen_geos, translation_vec=np.array([0,0,0])): # Define translation matrices for opening diff --git a/setup/Tsugite_app.py b/setup/Tsugite_app.py index 1fdfcec..5520c98 100755 --- a/setup/Tsugite_app.py +++ b/setup/Tsugite_app.py @@ -6,6 +6,7 @@ import math import os +from PyQt5 import QtCore, QtGui, QtOpenGL from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * @@ -24,14 +25,20 @@ class GLWidget(QGLWidget): def __init__(self, parent=None): + fmt = QGLFormat() + fmt.setVersion(4, 1) + fmt.setProfile(QGLFormat.CoreProfile) + fmt.setSampleBuffers(True) + self.parent = parent - QGLWidget.__init__(self, parent) + # QGLWidget.__init__(self,fmt, parent) + super().__init__(fmt, parent) # self.setMinimumSize(800, 800) self.setMouseTracking(True) self.click_time = time.time() self.x = 0 self.y = 0 - + # print(self._opengl_info()) # def __init__(self, parent=None): # fmt = QGLFormat() # fmt.setVersion(2, 1) @@ -52,7 +59,7 @@ def __init__(self, parent=None): # self.x = 0 # self.y = 0 - + from _GLWidget import initializeGL # from _GLWidget import resizeGL def resizeGL(self, w, h): @@ -254,8 +261,8 @@ def sizeHint(self): class mainWindow(QMainWindow): - def __init__(self, *args): - super(mainWindow, self).__init__(*args) + def __init__(self): + super().__init__() self.scaling = self.devicePixelRatioF() loadUi('Tsugite.ui', self) diff --git a/setup/_GLWidget.py b/setup/_GLWidget.py index d36bdd1..73908b4 100644 --- a/setup/_GLWidget.py +++ b/setup/_GLWidget.py @@ -1,111 +1,121 @@ -from PyQt5.QtWidgets import * -from PyQt5.QtGui import * -from PyQt5.QtCore import * -from PyQt5.QtCore import pyqtSignal, QPoint, QSize, Qt -from PyQt5.uic import * -from PyQt5.QtOpenGL import * - -from OpenGL.GL import * -from OpenGL.GLUT import * -from OpenGL.GLU import * -from math import tan, pi -#My files -from Types import Types -from Show import Show - -def initializeGL(self): - self.qglClearColor(QColor(255, 255, 255)) - glEnable(GL_DEPTH_TEST) # enable depth testing - sax = self.parent.findChild(QComboBox, "comboSLIDE").currentIndex() - dim = self.parent.findChild(QSpinBox, "spinBoxRES").value() - ang = self.parent.findChild(QDoubleSpinBox, "spinANG").value() - dx = self.parent.findChild(QDoubleSpinBox, "spinDX").value() - dy = self.parent.findChild(QDoubleSpinBox, "spinDY").value() - dz = self.parent.findChild(QDoubleSpinBox, "spinDZ").value() - dia = self.parent.findChild(QDoubleSpinBox, "spinDIA").value() - tol = self.parent.findChild(QDoubleSpinBox, "spinTOL").value() - spe = self.parent.findChild(QSpinBox, "spinSPEED").value() - spi = self.parent.findChild(QSpinBox, "spinSPINDLE").value() - aax = self.parent.findChild(QComboBox, "comboALIGN").currentIndex() - inc = self.parent.findChild(QCheckBox, "checkINC").isChecked() - fin = self.parent.findChild(QCheckBox, "checkFIN").isChecked() - if self.parent.findChild(QRadioButton, "radioGCODE").isChecked(): ext = "gcode" - elif self.parent.findChild(QRadioButton, "radioNC").isChecked(): ext = "nc" - elif self.parent.findChild(QRadioButton, "radioSBP").isChecked(): ext = "sbp" - self.type = Types(self,fs=[[[2,0]],[[2,1]]],sax=sax,dim=dim,ang=ang, td=[dx,dy,dz], fabtol=tol, fabdia=dia, fspe=spe, fspi=spi, fabext=ext, align_ax=aax, incremental=inc, finterp=fin) - self.show = Show(self,self.type) - -def resizeGL(self, w, h): - def perspective(fovY, aspect, zNear, zFar): - fH =tan(fovY / 360. * pi) * zNear - fW = fH * aspect - glFrustum(-fW, fW, -fH, fH, zNear, zFar) - - - - # print(oratio) - # if h * oratio > w: - # self.width = w - # self.height = w / oratio - # # h = w / oratio - # else: - # self.width = w - # self.height = h - oratio = 1.267 - if h * oratio > w: - w = w - h = w / oratio - # h = w / oratio - else: - w = h * oratio - h = h - - glViewport(0, 0, w, h) - glMatrixMode(GL_PROJECTION) - glLoadIdentity() - perspective(45.0, w / h, 1, 1000) - glMatrixMode(GL_MODELVIEW) - self.width = w - self.height = h - self.wstep = int(0.5+w/5) - self.hstep = int(0.5+h/4) - - -# def resizeGL(self, width, height): -# side = min(width, height) -# glViewport((width - side) // 2, (height - side) // 2, side, side) -# #GL.glViewport(50,50,500,500) -# glMatrixMode(GL_PROJECTION) -# glLoadIdentity()# Reset The Projection Matrix -# glOrtho(-2 * (width / height), +2 * (width / height), -2, +2, 4.0, 15.0) - -# #GL.glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0) -# glMatrixMode(GL_MODELVIEW) -# # # QGLWidget.resize(self, width, height) -# self.width = width -# self.height = height -# self.wstep = int(0.5+width/5) -# self.hstep = int(0.5+height/4) -# # resize_cb = pyqtSignal(int,int) -# # self.resize_cb.emit(width,height) -# # # glViewport(0, 0, self.width(), self.height()) -# # glViewport(0, 0, width, height) -# # glMatrixMode(GL_PROJECTION) -# # glLoadIdentity() -# # # gluPerspective(70, 1.0 * width / height, 0.1, 1000.0) -# # glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0) -# # # gluLookAt(100, 100, 100, -# # # 0, 0, 0, -# # # 0, 1, 0) -# # glMatrixMode(GL_MODELVIEW) -# # # glLoadIdentity() -# # # def resizeGL(self, width, height): -# # # self.width = width -# # # self.height = height -# # # self.wstep = int(0.5+width/5) -# # # self.hstep = int(0.5+height/4) -# # # glViewport(0, 0, width, height) -# # # glMatrixMode(GL_PROJECTION) -# # # glLoadIdentity() -# # # glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0) -# # # glMatrixMode(GL_MODELVIEW) +from PyQt5.QtWidgets import * +from PyQt5.QtGui import * +from PyQt5.QtCore import * +from PyQt5.QtCore import pyqtSignal, QPoint, QSize, Qt +from PyQt5.uic import * +from PyQt5.QtOpenGL import * + +from OpenGL.GL import * +from OpenGL.GLUT import * +from OpenGL.GLU import * +from math import tan, pi +#My files +from Types import Types +from Show import Show + +def _opengl_info() -> str: + return f"""### OpenGL info ### + + Vendor: {glGetString(GL_VENDOR).decode("utf-8")} + Renderer: {glGetString(GL_RENDERER).decode("utf-8")} + OpenGL Version: {glGetString(GL_VERSION).decode("utf-8")} + GLSL Version: {glGetString(GL_SHADING_LANGUAGE_VERSION).decode("utf-8")} +""" + +def initializeGL(self): + print(_opengl_info()) + self.qglClearColor(QColor(255, 255, 255)) + glEnable(GL_DEPTH_TEST) # enable depth testing + sax = self.parent.findChild(QComboBox, "comboSLIDE").currentIndex() + dim = self.parent.findChild(QSpinBox, "spinBoxRES").value() + ang = self.parent.findChild(QDoubleSpinBox, "spinANG").value() + dx = self.parent.findChild(QDoubleSpinBox, "spinDX").value() + dy = self.parent.findChild(QDoubleSpinBox, "spinDY").value() + dz = self.parent.findChild(QDoubleSpinBox, "spinDZ").value() + dia = self.parent.findChild(QDoubleSpinBox, "spinDIA").value() + tol = self.parent.findChild(QDoubleSpinBox, "spinTOL").value() + spe = self.parent.findChild(QSpinBox, "spinSPEED").value() + spi = self.parent.findChild(QSpinBox, "spinSPINDLE").value() + aax = self.parent.findChild(QComboBox, "comboALIGN").currentIndex() + inc = self.parent.findChild(QCheckBox, "checkINC").isChecked() + fin = self.parent.findChild(QCheckBox, "checkFIN").isChecked() + if self.parent.findChild(QRadioButton, "radioGCODE").isChecked(): ext = "gcode" + elif self.parent.findChild(QRadioButton, "radioNC").isChecked(): ext = "nc" + elif self.parent.findChild(QRadioButton, "radioSBP").isChecked(): ext = "sbp" + self.type = Types(self,fs=[[[2,0]],[[2,1]]],sax=sax,dim=dim,ang=ang, td=[dx,dy,dz], fabtol=tol, fabdia=dia, fspe=spe, fspi=spi, fabext=ext, align_ax=aax, incremental=inc, finterp=fin) + self.show = Show(self,self.type) + +def resizeGL(self, w, h): + def perspective(fovY, aspect, zNear, zFar): + fH =tan(fovY / 360. * pi) * zNear + fW = fH * aspect + glFrustum(-fW, fW, -fH, fH, zNear, zFar) + + + + # print(oratio) + # if h * oratio > w: + # self.width = w + # self.height = w / oratio + # # h = w / oratio + # else: + # self.width = w + # self.height = h + oratio = 1.267 + if h * oratio > w: + w = w + h = w / oratio + # h = w / oratio + else: + w = h * oratio + h = h + + glViewport(0, 0, w, h) + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + perspective(45.0, w / h, 1, 1000) + glMatrixMode(GL_MODELVIEW) + self.width = w + self.height = h + self.wstep = int(0.5+w/5) + self.hstep = int(0.5+h/4) + + +# def resizeGL(self, width, height): +# side = min(width, height) +# glViewport((width - side) // 2, (height - side) // 2, side, side) +# #GL.glViewport(50,50,500,500) +# glMatrixMode(GL_PROJECTION) +# glLoadIdentity()# Reset The Projection Matrix +# glOrtho(-2 * (width / height), +2 * (width / height), -2, +2, 4.0, 15.0) + +# #GL.glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0) +# glMatrixMode(GL_MODELVIEW) +# # # QGLWidget.resize(self, width, height) +# self.width = width +# self.height = height +# self.wstep = int(0.5+width/5) +# self.hstep = int(0.5+height/4) +# # resize_cb = pyqtSignal(int,int) +# # self.resize_cb.emit(width,height) +# # # glViewport(0, 0, self.width(), self.height()) +# # glViewport(0, 0, width, height) +# # glMatrixMode(GL_PROJECTION) +# # glLoadIdentity() +# # # gluPerspective(70, 1.0 * width / height, 0.1, 1000.0) +# # glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0) +# # # gluLookAt(100, 100, 100, +# # # 0, 0, 0, +# # # 0, 1, 0) +# # glMatrixMode(GL_MODELVIEW) +# # # glLoadIdentity() +# # # def resizeGL(self, width, height): +# # # self.width = width +# # # self.height = height +# # # self.wstep = int(0.5+width/5) +# # # self.hstep = int(0.5+height/4) +# # # glViewport(0, 0, width, height) +# # # glMatrixMode(GL_PROJECTION) +# # # glLoadIdentity() +# # # glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0) +# # # glMatrixMode(GL_MODELVIEW)