1 | from gui.visual.loader import Loader
|
---|
2 | from gui.visual.camera import Camera
|
---|
3 | from gui.visual.skyboxShader import SkyboxShader
|
---|
4 | import glm
|
---|
5 | import OpenGL.GL as gl
|
---|
6 |
|
---|
7 | class SkyboxRenderer:
|
---|
8 | def __init__(self, loader: Loader, projectionMatrix) -> None:
|
---|
9 | self.shader = SkyboxShader()
|
---|
10 | vertices, text = self.createCube()
|
---|
11 | self.skycube = loader.loadToVao3(vertices, text, int(len(vertices)/3))
|
---|
12 | self.texture = loader.loadCubemap([
|
---|
13 | "gui/res/img/field3.png",
|
---|
14 | "gui/res/img/field5.png",
|
---|
15 | "gui/res/img/field4.png",
|
---|
16 | "gui/res/img/field2.png",
|
---|
17 | "gui/res/img/field1.png",
|
---|
18 | "gui/res/img/field6.png",
|
---|
19 | ])
|
---|
20 | self.shader.start()
|
---|
21 | self.loadProjectionMatrix(projectionMatrix)
|
---|
22 | self.shader.stop()
|
---|
23 |
|
---|
24 | def loadProjectionMatrix(self, projectionMatrix):
|
---|
25 | self.shader.loadProjectionMatrix(projectionMatrix)
|
---|
26 |
|
---|
27 | def render(self, camera: Camera):
|
---|
28 | gl.glDepthFunc(gl.GL_LEQUAL)
|
---|
29 | self.shader.start()
|
---|
30 | self.shader.loadViewMatrix(camera)
|
---|
31 | gl.glBindVertexArray(self.skycube.vaoID)
|
---|
32 | gl.glEnableVertexAttribArray(0)
|
---|
33 | gl.glEnableVertexAttribArray(1)
|
---|
34 | self.bindTextures()
|
---|
35 | gl.glDrawArrays(gl.GL_TRIANGLES, 0, self.skycube.vertexCount)
|
---|
36 | gl.glDisableVertexAttribArray(0)
|
---|
37 | gl.glDisableVertexAttribArray(1)
|
---|
38 | gl.glBindVertexArray(0)
|
---|
39 | self.shader.stop()
|
---|
40 | gl.glDepthFunc(gl.GL_LESS)
|
---|
41 |
|
---|
42 | def bindTextures(self):
|
---|
43 | gl.glActiveTexture(gl.GL_TEXTURE0)
|
---|
44 | gl.glBindTexture(gl.GL_TEXTURE_CUBE_MAP, self.texture)
|
---|
45 |
|
---|
46 | def createCube(self):
|
---|
47 | skyboxVertices = [
|
---|
48 | -1.0, -1.0, 1.0,
|
---|
49 | -1.0, -1.0, -1.0,
|
---|
50 | 1.0, -1.0, -1.0,
|
---|
51 | 1.0, -1.0, -1.0,
|
---|
52 | 1.0, -1.0, 1.0,
|
---|
53 | -1.0, -1.0, 1.0,
|
---|
54 |
|
---|
55 | -1.0, 1.0, -1.0,
|
---|
56 | -1.0, -1.0, -1.0,
|
---|
57 | -1.0, -1.0, 1.0,
|
---|
58 | -1.0, -1.0, 1.0,
|
---|
59 | -1.0, 1.0, 1.0,
|
---|
60 | -1.0, 1.0, -1.0,
|
---|
61 |
|
---|
62 | 1.0, -1.0, -1.0,
|
---|
63 | 1.0, 1.0, -1.0,
|
---|
64 | 1.0, 1.0, 1.0,
|
---|
65 | 1.0, 1.0, 1.0,
|
---|
66 | 1.0, -1.0, 1.0,
|
---|
67 | 1.0, -1.0, -1.0,
|
---|
68 |
|
---|
69 | -1.0, 1.0, -1.0,
|
---|
70 | -1.0, 1.0, 1.0,
|
---|
71 | 1.0, 1.0, 1.0,
|
---|
72 | 1.0, 1.0, 1.0,
|
---|
73 | 1.0, 1.0, -1.0,
|
---|
74 | -1.0, 1.0, -1.0,
|
---|
75 |
|
---|
76 | -1.0, -1.0, 1.0,
|
---|
77 | 1.0, -1.0, 1.0,
|
---|
78 | 1.0, 1.0, 1.0,
|
---|
79 | 1.0, 1.0, 1.0,
|
---|
80 | -1.0, 1.0, 1.0,
|
---|
81 | -1.0, -1.0, 1.0,
|
---|
82 |
|
---|
83 | -1.0, -1.0, -1.0,
|
---|
84 | -1.0, 1.0, -1.0,
|
---|
85 | 1.0, -1.0, -1.0,
|
---|
86 | 1.0, -1.0, -1.0,
|
---|
87 | -1.0, 1.0, -1.0,
|
---|
88 | 1.0, 1.0, -1.0]
|
---|
89 |
|
---|
90 | return skyboxVertices, skyboxVertices |
---|