Commits

Nikhil Marathe  committed abc16c9

Replace PIL with pygame for texture loading.

  • Participants
  • Parent commits 2253721

Comments (0)

Files changed (2)

File 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)

File 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)