-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grass.py
45 lines (37 loc) · 1.47 KB
/
Grass.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
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import Image
class Grass:
#create a number of grass objects either for a map (in
#which case, send it the areas it can go in) or just
#in general. Probably tie the render
def __init__(self):
pass
def create_grass_list(self):
item = glGenLists(1)
ids = self.load_texture('l-system.png')
glNewList(item, GL_COMPILE)
self.applyTexture(ids)
glColor4f(1,1,1,0)
glBegin(GL_QUADS)
glTexCoord2f(1, 0) ; glVertex(0,0,0)
glTexCoord2f(1, 1) ; glVertex(0,10,0)
glTexCoord2f(0, 1) ; glVertex(10,10,0)
glTexCoord2f(0, 0) ; glVertex(10,0,0)
glEnd()
glEndList()
return item
def load_texture(self, filename):
glGenTextures(1, 1)
glBindTexture(GL_TEXTURE_2D, 1)
self.image = Image.open(filename)
glTexImage2D(GL_TEXTURE_2D, 0, 3, self.image.size[0], self.image.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, self.image.tostring("raw","RGBA",0,-1))
return 1
def applyTexture(self, name):
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, name)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)