commit:6d77e2a090777b7d77058e6d84cfca3a625ab9d1
author:Chip Black
committer:Chip Black
date:Tue Jul 22 15:25:37 2008 -0500
parents:36ec354a092ca1c7e560265b2837c38010bde6a1
Texturing and minor GL fixes

Removed Numeric texture reshaping bits in TexMan in favor of
pygame.image.tostring, which has the added benefit of making the texture
properly oriented.  Changed accompanying texture coordinates in Collage
and Sprite to work for the now right-side-up textures. The default for
config.square_textures is now False.

Unrelatedly, added a glViewport() call in Engine.init() because my
savage wouldn't display anything without it.
diff --git a/Richter/Collage.py b/Richter/Collage.py
line changes: +1/-1
index b01d538..998f160
--- a/Richter/Collage.py
+++ b/Richter/Collage.py
@@ -63,7 +63,7 @@ class Collage:
 					(x,y+ctexsize[1],0)
 				]
 				texcoordarray += [
-					(1.0,0.0),(1.0,1.0),(0.0,1.0),(0.0,0.0)
+					(0.0,0.0),(1.0,0.0),(1.0,1.0),(0.0,1.0)
 				]
 				nvertices += 4
 		f.close()

diff --git a/Richter/Engine.py b/Richter/Engine.py
line changes: +2/-2
index e2b2f17..c95aeaa
--- a/Richter/Engine.py
+++ b/Richter/Engine.py
@@ -3,7 +3,6 @@ import imp
 import pygame
 from pygame.locals import *
 from Sprite import Sprite
-from Numeric import array,reshape
 
 try:
     from OpenGL.GL import *
@@ -22,7 +21,7 @@ def init(resolution=(640,480)):
 		sres = [int(n * config.scalefactor) for n in resolution]
 	except AttributeError:
 		sres = resolution
-	flags = OPENGL|DOUBLEBUF|HWSURFACE
+	flags = OPENGL|DOUBLEBUF
 	try:
 		if config.fullscreen:
 			flags |= FULLSCREEN
@@ -30,6 +29,7 @@ def init(resolution=(640,480)):
 		pass
 	pygame.display.set_mode(sres, flags)
 
+	glViewport(0, 0, sres[0], sres[1])
 	# Set up the camera
 	glLoadIdentity()
 	glMatrixMode(GL_PROJECTION)

diff --git a/Richter/Sprite.py b/Richter/Sprite.py
line changes: +4/-4
index b66adcf..e43b099
--- a/Richter/Sprite.py
+++ b/Richter/Sprite.py
@@ -80,19 +80,19 @@ class Sprite:
 		,'f')
 		if self.flip and self.mirror:
 			texcoordarray = array(
-				((0.0,0.0),(0.0,1.0),(1.0,1.0),(1.0,0.0))
+				((1.0,1.0),(0.0,1.0),(0.0,0.0),(1.0,0.0))
 			,'f')
 		elif self.flip:
 			texcoordarray = array(
-				((0.0,1.0),(0.0,0.0),(1.0,0.0),(1.0,1.0))
+				((0.0,1.0),(1.0,1.0),(1.0,0.0),(0.0,0.0))
 			,'f')
 		elif self.mirror:
 			texcoordarray = array(
-				((1.0,1.0),(1.0,0.0),(0.0,0.0),(0.0,1.0))
+				((1.0,0.0),(0.0,0.0),(0.0,1.0),(1.0,1.0))
 			,'f')
 		else:
 			texcoordarray = array(
-				((1.0,0.0),(1.0,1.0),(0.0,1.0),(0.0,0.0))
+				((0.0,0.0),(1.0,0.0),(1.0,1.0),(0.0,1.0))
 			,'f')
 		index = array((0,1,2,3),'i')
 		for i in range(0,len(self.frames)):

diff --git a/Richter/TexMan.py b/Richter/TexMan.py
line changes: +3/-7
index c8488c1..54d02b5
--- a/Richter/TexMan.py
+++ b/Richter/TexMan.py
@@ -2,7 +2,6 @@ from OpenGL.GL import *
 from OpenGL.GLU import *
 import pygame
 from pygame.locals import *
-from Numeric import array,reshape,concatenate
 
 from util import *
 import config
@@ -25,16 +24,13 @@ def load(file):
         newImage.fill((255,255,255,0))
         newImage.blit(image, (0, th - h))	# We want this in the lower corner
 
-        # Freaking pygame making us do this by hand...
-        colors = pygame.surfarray.pixels3d(newImage)
-        alphas = pygame.surfarray.pixels_alpha(newImage)
-        alphas = reshape(alphas, (tw,th,1))
-        pixels = concatenate((colors,alphas),2)
+	pixels = pygame.image.tostring(newImage, "RGBA", True)
 
         # Create Texture
         texture = glGenTextures(1)
 	glBindTexture(GL_TEXTURE_2D, texture)
-	glTexImage2Dub(GL_TEXTURE_2D, 0, GL_RGBA8, 0, GL_RGBA, pixels)
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
+			GL_UNSIGNED_BYTE, pixels)
 	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
 	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

diff --git a/Richter/config.py b/Richter/config.py
line changes: +2/-2
index e0516b6..c1cf1c5
--- a/Richter/config.py
+++ b/Richter/config.py
@@ -1,5 +1,5 @@
 # If your card has trouble with non-square textures (my TNT seems to), set this
 # to true to make all textures square
-square_textures = True
-#scalefactor = 2
+square_textures = False
+#scalefactor = 1.0
 #fullscreen = True