-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSkybox.py
121 lines (101 loc) · 2.6 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
113
114
115
116
117
118
119
120
121
import OpenGL
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
from Utility import *
from Texture import *
import os
import re
class Skybox:
def __init__(self,name,ext = 'tga'):
path = os.path.join(name,'')
name = re.split('[/|\\\\]',path)[-2]
self.texture = {}
for key,nm in zip(['FRONT','BACK','LEFT','RIGHT','UP','DOWN'],['ft','bk','lf','rt','up','dn']):
sf = pygame.image.load(path+name+'_'+nm+'.'+ext)
self.texture[key] = createTexture(sf)[0]
x = 0
y = 0
z = 0
width = 2048
height = 2048
length = 2048
x = x - width / 2
y = y - height / 2
z = z - length / 2
self.list = glGenLists(1)
glNewList(self.list,GL_COMPILE)
glColor3f(255,255,255)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, self.texture["FRONT"])
glBegin(GL_QUADS)
glTexCoord2f(1, 0)
glVertex3f(x, y, z+length)
glTexCoord2f(1, 1)
glVertex3f(x, y+height, z+length)
glTexCoord2f(0, 1)
glVertex3f(x+width, y+height, z+length)
glTexCoord2f(0, 0)
glVertex3f(x+width, y, z+length)
glEnd()
glBindTexture(GL_TEXTURE_2D, self.texture["BACK"])
glBegin(GL_QUADS)
glTexCoord2f(1, 0)
glVertex3f(x+width, y, z)
glTexCoord2f(1, 1)
glVertex3f(x+width, y+height, z)
glTexCoord2f(0, 1)
glVertex3f(x, y+height, z)
glTexCoord2f(0, 0)
glVertex3f(x, y, z)
glEnd()
glBindTexture(GL_TEXTURE_2D, self.texture["LEFT"])
glBegin(GL_QUADS)
glTexCoord2f(1, 1)
glVertex3f(x, y+height, z)
glTexCoord2f(0, 1)
glVertex3f(x, y+height, z+length)
glTexCoord2f(0, 0)
glVertex3f(x, y, z+length)
glTexCoord2f(1, 0)
glVertex3f(x, y, z)
glEnd()
glBindTexture(GL_TEXTURE_2D, self.texture["RIGHT"])
glBegin(GL_QUADS)
glTexCoord2f(0, 0)
glVertex3f(x+width, y, z)
glTexCoord2f(1, 0)
glVertex3f(x+width, y, z+length)
glTexCoord2f(1, 1)
glVertex3f(x+width, y+height, z+length)
glTexCoord2f(0, 1)
glVertex3f(x+width, y+height, z)
glEnd()
glBindTexture(GL_TEXTURE_2D, self.texture["UP"])
glBegin(GL_QUADS)
glTexCoord2f(0, 0)
glVertex3f(x+width, y+height, z)
glTexCoord2f(1, 0)
glVertex3f(x+width, y+height, z+length)
glTexCoord2f(1, 1)
glVertex3f(x, y+height, z+length)
glTexCoord2f(0, 1)
glVertex3f(x, y+height, z)
glEnd()
glBindTexture(GL_TEXTURE_2D, self.texture["DOWN"])
glBegin(GL_QUADS)
glTexCoord2f(0, 0)
glVertex3f(x, y, z)
glTexCoord2f(1, 0)
glVertex3f(x, y, z+length)
glTexCoord2f(1, 1)
glVertex3f(x+width, y, z+length)
glTexCoord2f(0, 1)
glVertex3f(x+width, y, z)
glEnd()
glBindTexture(GL_TEXTURE_2D,0)
glDisable(GL_TEXTURE_2D)
glEndList()
def render(self):
glCallList(self.list)