4 from OpenGL.GL import *
5 from OpenGL.GLU import *
9 pygame.display.set_mode((w,h), pygame.OPENGL|pygame.DOUBLEBUF|pygame.FULLSCREEN)
10 # pygame.display.set_mode((w,h),pygame.OPENGL|pygame.DOUBLEBUF)
12 glClearColor(0.0, 0.0, 0.0, 1.0)
13 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
15 glMatrixMode(GL_PROJECTION);
17 gluOrtho2D(0, w, 0, h);
18 glMatrixMode(GL_MODELVIEW);
21 glEnable(GL_TEXTURE_2D)
23 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
26 def load_image(image):
27 textureSurface = pygame.image.load(image)
29 textureData = pygame.image.tostring(textureSurface, "RGBA", 1)
31 width = textureSurface.get_width()
32 height = textureSurface.get_height()
34 texture = glGenTextures(1)
35 glBindTexture(GL_TEXTURE_2D, texture)
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
38 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData )
40 return texture, width, height
43 def delTexture(texture):
44 glDeleteTextures(texture)
47 def createTexDL(texture, width, height):
48 newList = glGenLists(1)
49 glNewList(newList,GL_COMPILE);
50 glBindTexture(GL_TEXTURE_2D, texture)
52 glTexCoord2f(0, 0); glVertex2f(0, 0) # Bottom Left Of The Texture and Quad
53 glTexCoord2f(0, 1); glVertex2f(0, height) # Top Left Of The Texture and Quad
54 glTexCoord2f(1, 1); glVertex2f( width, height) # Top Right Of The Texture and Quad
55 glTexCoord2f(1, 0); glVertex2f(width, 0) # Bottom Right Of The Texture and Quad
61 def create_texture(image):
62 textureSurface = pygame.image.load(image)
64 textureData = pygame.image.tostring(textureSurface, "RGBA", 1)
66 width = textureSurface.get_width()
67 height = textureSurface.get_height()
69 texture = glGenTextures(1)
70 glBindTexture(GL_TEXTURE_2D, texture)
71 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
73 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData )
75 newList = glGenLists(1)
76 glNewList(newList,GL_COMPILE);
77 glBindTexture(GL_TEXTURE_2D, texture)
79 glTexCoord2f(0, 0); glVertex2f(0, 0) # Bottom Left Of The Texture and Quad
80 glTexCoord2f(0, 1); glVertex2f(0, height) # Top Left Of The Texture and Quad
81 glTexCoord2f(1, 1); glVertex2f( width, height) # Top Right Of The Texture and Quad
82 glTexCoord2f(1, 0); glVertex2f(width, 0) # Bottom Right Of The Texture and Quad
91 glDeleteLists(list, 1)