Nikhil Marathe avatar Nikhil Marathe committed abc16c9

Replace PIL with pygame for texture loading.

Comments (0)

Files changed (2)

src/fileadelphia/building.py

 import math
-import Image
+import pygame
 import os
 import random
 from OpenGL.GL import *
 def CreateTexture(imagename, number):
     global textures
 
-    image = Image.open(imagename)
-    ix = image.size[0]
-    iy = image.size[1]
-    image = image.tostring("raw", "RGBX", 0, -1)
+    image = pygame.image.load(imagename)
+    iw = image.get_width()
+    ih = image.get_height()
+    image_surface = pygame.image.tostring(image, "RGBA", 1)
 
     glBindTexture(GL_TEXTURE_2D, int(textures[number]))
 
     glPixelStorei(GL_UNPACK_ALIGNMENT,1)
-    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
+    glTexImage2D(GL_TEXTURE_2D, 0, 3, iw, ih, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_surface)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)

src/fileadelphia/city.py

 import pygame
 import logging
 import sys
-import Image 
 
 from fileadelphia.const import VIEW_WIDTH, VIEW_HEIGHT
 from fileadelphia.states import State, DirectoryInfoState, PermissionDeniedState, FileInfoState
 def CreateTexture(imagename, number):
     global textures
 
-    image = Image.open(imagename)
-    ix = image.size[0]
-    iy = image.size[1]
-    image = image.tostring("raw", "RGBX", 0, -1)
+    image = pygame.image.load(imagename)
+    iw = image.get_width()
+    ih = image.get_height()
+    image_surface = pygame.image.tostring(image, "RGBA", 1)
 
     glBindTexture(GL_TEXTURE_2D, int(textures[number]))
 
     glPixelStorei(GL_UNPACK_ALIGNMENT,1)
-    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
+    glTexImage2D(GL_TEXTURE_2D, 0, 3, iw, ih, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_surface)
     #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
     #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.