source: framspy/gui/visual/staticShader.py @ 1326

Last change on this file since 1326 was 1198, checked in by Maciej Komosinski, 22 months ago

Added simple Python GUI for Framsticks library/server

File size: 1.9 KB
Line 
1from gui.visual.shaderProgram import ShaderProgram
2from gui.visual.camera import Camera
3import OpenGL.GL as gl
4import glm
5
6class StaticShader(ShaderProgram):
7    def __init__(self) -> None:
8        super().__init__("visual/shaders/vertexShader.glsl", "visual/shaders/fragmentShader.glsl")
9
10        self.location_transformationMatrix = 0
11        self.location_projectionMatrix = 0
12        self.location_viewMatrix = 0
13        self.location_modelTexture = 0
14
15        self.bindAttributes()
16        gl.glLinkProgram(self.programID)
17        gl.glValidateProgram(self.programID)
18        self.getAllUniformLocations()
19
20    def loadProjectionMatrix(self, projection):
21        self.loadMatrix4(self.location_projectionMatrix, projection)
22
23    def loadViewMatrix(self, camera: Camera):
24        viewMatrix = glm.lookAt(camera.position, camera.player.position, glm.vec3(0, 0, 1))
25        self.loadMatrix4(self.location_viewMatrix, viewMatrix)
26
27    def loadTransformationMatrix(self, matrix):
28        self.loadMatrix4(self.location_transformationMatrix, matrix)
29
30    def loadColor(self, color: glm.vec3):
31        self.loadVector3(self.loaction_color, color)
32
33    def loadTextureOn(self, textureOn: bool):
34        self.loadFloat(self.location_textureOn, 1.0 if textureOn else 0.0)
35
36    def bindAttributes(self):
37        self.bindAttribute(0, "position")
38        self.bindAttribute(1, "textureCoordinates")
39        self.bindAttribute(2, "normal")
40
41    def getAllUniformLocations(self):
42        self.location_transformationMatrix = self.getUniformLocation("transformationMatrix")
43        self.location_projectionMatrix = self.getUniformLocation("projectionMatrix")
44        self.location_viewMatrix = self.getUniformLocation("viewMatrix")
45        self.location_modelTexture = self.getUniformLocation("modelTexture")
46        self.loaction_color = self.getUniformLocation("color")
47        self.location_textureOn = self.getUniformLocation("textureOn")
Note: See TracBrowser for help on using the repository browser.