MCPcopy Create free account
hub / github.com/Blakkis/PyGLMaze / __createTexture

Method __createTexture

pymaze/textures.py:15–45  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

13
14
15 def __createTexture(self, path):
16 # Load texture and convert to format OpenGL can use
17 surface = pygame.image.load(path).convert()
18 surface_data = pygame.image.tostring(surface, "RGB", 1)
19
20 width = surface.get_width()
21 height = surface.get_height()
22
23 # Create and bind texture (Following settings apply to the currently binded texture)
24 texture_id = glGenTextures(1)
25 glBindTexture(GL_TEXTURE_2D, texture_id)
26 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, surface_data)
27
28 # GL_REPEAT makes texture repeatable (aka. seamless*)
29 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
30 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
31
32 # There are dozen options for texture filtering (Setting things to GL_NEAREST makes textures look crispy)
33 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
34 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
35
36 # Generate mipmaps (Reduces load on texture sampling with distant objects)
37 glGenerateMipmap(GL_TEXTURE_2D)
38
39 # TODO: Should query the max level first
40 # Make textures look smooth on different angles/distance
41 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 16)
42
43 glBindTexture(GL_TEXTURE_2D, 0)
44
45 return texture_id
46
47
48 def getTexture(self):

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected