-
Notifications
You must be signed in to change notification settings - Fork 1
/
skybox.py
112 lines (99 loc) · 3.73 KB
/
skybox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from wrapper import *
class Skybox:
FOG_GREY=0.8
def __init__(self):
textureDir = 'data/textures/'
print imageLoad(textureDir + 'top.bmp')
self.top = imageLoad(textureDir + 'top.bmp').get_texture()
self.left = imageLoad(textureDir + 'lt.bmp').get_texture()
self.right = imageLoad(textureDir + 'rt.bmp').get_texture()
self.back = imageLoad(textureDir + 'bk.bmp').get_texture()
self.front = imageLoad(textureDir + 'ft.bmp').get_texture()
print self.top.tex_coords
def setTexParams(self):
glTexParameteri(self.top.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(self.top.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameteri(self.top.target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)
glTexParameteri(self.top.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(self.top.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
def draw(self, view):
glPushMatrix()
glDisable( GL_DEPTH_TEST)
glDisable(GL_FOG)
glDisable( GL_LIGHTING)
glDisable(GL_CULL_FACE)
cloudsize=100.0
offset=0.01
texOffset = 0.624
pos = view.getCamera().getCameraVectors()[1]
glTranslatef( pos.x, 5.0+pos.y, pos.z)
glColor3f(Skybox.FOG_GREY ,Skybox.FOG_GREY ,Skybox.FOG_GREY)
glEnable(self.top.target) # typically target is GL_TEXTURE_2D
#top
glBindTexture(self.top.target, self.top.id)
self.setTexParams()
glBegin(GL_QUADS)
glTexCoord2f( 0.0, texOffset )
glVertex3f( cloudsize, cloudsize-offset, cloudsize )
glTexCoord2f( texOffset, texOffset )
glVertex3f( -cloudsize, cloudsize-offset , cloudsize )
glTexCoord2f( texOffset, 0.0 )
glVertex3f( -cloudsize, cloudsize-offset , -cloudsize )
glTexCoord2f( 0.0, 0.0 )
glVertex3f( cloudsize, cloudsize-offset , -cloudsize )
glEnd()
#front
glBindTexture(self.front.target, self.front.id)
self.setTexParams()
glBegin(GL_QUADS)
glTexCoord2f( 0.0, texOffset )
glVertex3f( cloudsize, cloudsize , cloudsize )
glTexCoord2f( texOffset, texOffset )
glVertex3f( -cloudsize, cloudsize , cloudsize )
glTexCoord2f( texOffset, 0.0 )
glVertex3f( -cloudsize, -cloudsize , cloudsize )
glTexCoord2f( 0.0, 0.0 )
glVertex3f( cloudsize, -cloudsize , cloudsize)
glEnd()
#right
glBindTexture(self.right.target, self.right.id)
self.setTexParams()
glBegin(GL_QUADS)
glTexCoord2f( 0.0, texOffset )
glVertex3f( -cloudsize, cloudsize , cloudsize )
glTexCoord2f( texOffset, texOffset )
glVertex3f( -cloudsize, cloudsize , -cloudsize )
glTexCoord2f( texOffset, 0.0 )
glVertex3f( -cloudsize, -cloudsize , -cloudsize )
glTexCoord2f( 0.0, 0.0 )
glVertex3f( -cloudsize, -cloudsize ,cloudsize )
glEnd()
#left
glBindTexture(self.left.target, self.left.id)
self.setTexParams()
glBegin(GL_QUADS)
glTexCoord2f( 0.0, texOffset )
glVertex3f( cloudsize, cloudsize , -cloudsize )
glTexCoord2f( texOffset, texOffset )
glVertex3f( cloudsize, cloudsize , cloudsize )
glTexCoord2f( texOffset, 0.0 )
glVertex3f( cloudsize, -cloudsize ,cloudsize )
glTexCoord2f( 0.0, 0.0 )
glVertex3f( cloudsize, -cloudsize ,-cloudsize )
glEnd()
#back
glBindTexture(self.back.target, self.back.id)
self.setTexParams()
glBegin(GL_QUADS)
glTexCoord2f( 0.0, texOffset )
glVertex3f( -cloudsize, cloudsize , -cloudsize )
glTexCoord2f( texOffset, texOffset )
glVertex3f( cloudsize, cloudsize , -cloudsize )
glTexCoord2f( texOffset, 0.0 )
glVertex3f( cloudsize, -cloudsize , -cloudsize )
glTexCoord2f( 0.0, 0.0 )
glVertex3f( -cloudsize, -cloudsize , -cloudsize )
glEnd()
glDisable(self.top.target)
glEnable( GL_DEPTH_TEST)
glPopMatrix()