Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shaderVersion #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions setup/Show.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 12 additions & 5 deletions setup/Tsugite_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
Loading