Author: ArcRiley
Date: 2007-07-07 04:18:41 -0400 (Sat, 07 Jul 2007)
New Revision: 397
Modified:
trunk/pysoy/include/gl.pxd
trunk/pysoy/src/bodies._bodies/Mesh.pxi
trunk/pysoy/src/materials/Material.pxi
trunk/pysoy/src/materials/soy.materials.pxd
trunk/pysoy/src/textures/Image.pxi
trunk/pysoy/src/textures/Texture.pxi
trunk/pysoy/src/textures/Video.pxi
trunk/pysoy/src/textures/soy.textures.pxd
trunk/pysoy/src/widgets/Canvas.pxi
trunk/pysoy/tests/vid_canvas.py
Log:
Ticket #272, Video is now being transformed, Image is done the same way,
introduced the _unbind() function and switched Material to use _bind/_unbind
Modified: trunk/pysoy/include/gl.pxd
===================================================================
--- trunk/pysoy/include/gl.pxd 2007-07-07 06:54:18 UTC (rev 396)
+++ trunk/pysoy/include/gl.pxd 2007-07-07 08:18:41 UTC (rev 397)
@@ -1002,9 +1002,10 @@
cdef void glPushMatrix()
cdef void glPopMatrix()
cdef void glLoadIdentity()
- cdef void glLoadMatrixf( GLfloat * m )
- cdef void glMultMatrixf( GLfloat * m )
- cdef void glTranslatef( GLfloat, GLfloat, GLfloat z )
+ cdef void glLoadMatrixf( GLfloat* )
+ cdef void glMultMatrixf( GLfloat* )
+ cdef void glScalef( GLfloat, GLfloat, GLfloat )
+ cdef void glTranslatef( GLfloat, GLfloat, GLfloat )
# Legacy Functions
cdef void glBegin( GLenum )
Modified: trunk/pysoy/src/bodies._bodies/Mesh.pxi
===================================================================
--- trunk/pysoy/src/bodies._bodies/Mesh.pxi 2007-07-07 06:54:18 UTC (rev
396)
+++ trunk/pysoy/src/bodies._bodies/Mesh.pxi 2007-07-07 08:18:41 UTC (rev
397)
@@ -118,10 +118,11 @@
gl.glNormalPointer ( gl.GL_FLOAT, 36, &self._verts[0].nx)
gl.glVertexPointer (3, gl.GL_FLOAT, 36, &self._verts[0].px)
for i from 0 <= i < self._nmate :
- (<soy.materials.Material> self._mates[i].mat)._render()
+ (<soy.materials.Material> self._mates[i].mat)._bind()
gl.glDrawElements (gl.GL_TRIANGLES, self._mates[i].length*3,
gl.GL_UNSIGNED_SHORT,
self._faces + self._mates[i].offset)
+ (<soy.materials.Material> self._mates[i].mat)._unbind()
cdef void _renderVBO(self) :
@@ -138,10 +139,11 @@
gl.glNormalPointer ( gl.GL_FLOAT, 36, <float*> 12)
gl.glVertexPointer (3, gl.GL_FLOAT, 36, <float*> 0)
for i from 0 <= i < self._nmate :
- (<soy.materials.Material> self._mates[i].mat)._render()
+ (<soy.materials.Material> self._mates[i].mat)._bind()
gl.glDrawElements (gl.GL_TRIANGLES, self._mates[i].length*3,
gl.GL_UNSIGNED_SHORT,
(<Face *> 0) + self._mates[i].offset)
+ (<soy.materials.Material> self._mates[i].mat)._unbind()
cdef void _createVBO(self) :
Modified: trunk/pysoy/src/materials/Material.pxi
===================================================================
--- trunk/pysoy/src/materials/Material.pxi 2007-07-07 06:54:18 UTC (rev
396)
+++ trunk/pysoy/src/materials/Material.pxi 2007-07-07 08:18:41 UTC (rev
397)
@@ -47,7 +47,7 @@
return '<Material>'
- cdef void _render(self) :
+ cdef void _bind(self) :
cdef float _white[4]
_white[0] = 1.0
_white[1] = 1.0
@@ -74,7 +74,11 @@
gl.glDisable(gl.GL_TEXTURE_2D)
gl.glDisable(gl.GL_TEXTURE_3D)
+ cdef void _unbind(self) :
+ if self._color :
+ (<soy.textures.Texture> self._color)._unbind()
+
property color :
def __get__(self) :
return self._color
Modified: trunk/pysoy/src/materials/soy.materials.pxd
===================================================================
--- trunk/pysoy/src/materials/soy.materials.pxd 2007-07-07 06:54:18 UTC (rev
396)
+++ trunk/pysoy/src/materials/soy.materials.pxd 2007-07-07 08:18:41 UTC (rev
397)
@@ -30,4 +30,5 @@
cdef float _shininess
cdef soy.colors.Color _specular
# C Functions
- cdef void _render(self)
+ cdef void _bind(self)
+ cdef void _unbind(self)
Modified: trunk/pysoy/src/textures/Image.pxi
===================================================================
--- trunk/pysoy/src/textures/Image.pxi 2007-07-07 06:54:18 UTC (rev 396)
+++ trunk/pysoy/src/textures/Image.pxi 2007-07-07 08:18:41 UTC (rev 397)
@@ -23,7 +23,7 @@
This loads a 2D image (from PIL) as a texture
'''
def __new__(self, img, *args, **keywords) :
- cdef int b, c, lx, ly
+ cdef int b, c, x, y, ix, iy, tx, ty
cdef object d, idata
modes = {'L':1, 'LA':2, 'RGB':3, 'RGBA':4}
idata = img.transpose(1).getdata()
@@ -35,19 +35,21 @@
# 1D Texture
if img.size[1] != 1 :
idata = idata.rotate(90) # Make the data horizontal
- lx = self._squareup(len(idata))
- ly = 1
- if lx != len(idata) :
- idata = idata.resize((lx, 1))
+ ix = len(idata)
+ iy = 1
else :
# 2D Texture
- lx = self._squareup(img.size[0])
- ly = self._squareup(img.size[1])
- if lx != img.size[0] or ly != img.size[1] :
- idata = idata.resize((lx, ly))
- self._aspect = float(img.size[0]) / float(img.size[1])
- self._resize(modes[img.mode], lx, ly, 1)
- for b from 0 <= b < lx*ly :
- d = idata[b]
- for c from 0 <= c < self._chans :
- self._texels[(b*self._chans)+c] = d[c]
+ ix = img.size[0]
+ iy = img.size[1]
+ tx = self._squareup(ix)
+ ty = self._squareup(iy)
+ self._scaleX = <float> ix / <float> tx
+ self._scaleY = <float> iy / <float> ty
+ if iy > 1 :
+ self._aspect = float(ix) / float(iy)
+ self._resize(modes[img.mode], tx, ty, 1)
+ for y from 0 <= y < iy :
+ for x from 0 <= x < ix :
+ d = idata[(y*ix)+x]
+ for c from 0 <= c < self._chans :
+ self._texels[(((y*tx)+x)*self._chans)+c] = d[c]
Modified: trunk/pysoy/src/textures/Texture.pxi
===================================================================
--- trunk/pysoy/src/textures/Texture.pxi 2007-07-07 06:54:18 UTC (rev
396)
+++ trunk/pysoy/src/textures/Texture.pxi 2007-07-07 08:18:41 UTC (rev
397)
@@ -70,15 +70,9 @@
cdef void _bind(self) :
if self._textureTarget == gl.GL_TEXTURE_1D :
gl.glEnable(gl.GL_TEXTURE_1D)
- gl.glDisable(gl.GL_TEXTURE_2D)
- gl.glDisable(gl.GL_TEXTURE_3D)
elif self._textureTarget == gl.GL_TEXTURE_2D :
- gl.glDisable(gl.GL_TEXTURE_1D)
gl.glEnable(gl.GL_TEXTURE_2D)
- gl.glDisable(gl.GL_TEXTURE_3D)
elif self._textureTarget == gl.GL_TEXTURE_3D :
- gl.glDisable(gl.GL_TEXTURE_1D)
- gl.glDisable(gl.GL_TEXTURE_2D)
gl.glEnable(gl.GL_TEXTURE_3D)
else :
return
@@ -114,6 +108,9 @@
self._update = 0
else :
gl.glBindTexture(self._textureTarget, self._textureID)
+ if self._scaleX :
+ gl.glMatrixMode(gl.GL_TEXTURE)
+ gl.glScalef(self._scaleX, self._scaleY, self._scaleZ)
#cdef int max_size
#gl.glGetIntegerv(gl.GL_MAX_TEXTURE_SIZE, &max_size)
@@ -121,6 +118,16 @@
# raise ValueError('Image size exceeds max texture size, which is %d
pixels for each side'%max_size)
+ cdef void _unbind(self) :
+ if self._textureTarget == gl.GL_TEXTURE_1D :
+ gl.glDisable(gl.GL_TEXTURE_1D)
+ elif self._textureTarget == gl.GL_TEXTURE_2D :
+ gl.glDisable(gl.GL_TEXTURE_2D)
+ elif self._textureTarget == gl.GL_TEXTURE_3D :
+ gl.glDisable(gl.GL_TEXTURE_3D)
+ gl.glLoadIdentity()
+
+
cdef void _resize(self, int c, int x, int y, int z) :
cdef long int _size
_size = c*x*y*z
Modified: trunk/pysoy/src/textures/Video.pxi
===================================================================
--- trunk/pysoy/src/textures/Video.pxi 2007-07-07 06:54:18 UTC (rev 396)
+++ trunk/pysoy/src/textures/Video.pxi 2007-07-07 08:18:41 UTC (rev 397)
@@ -60,6 +60,8 @@
if ogg.ogg_page_pageno(_page) == 0 :
self._resize(1, self._squareup(self._info.frame_width),
self._squareup(self._info.frame_height), 1)
+ self._scaleX = <float> self._info.frame_width / <float> self._width
+ self._scaleY = <float> self._info.frame_height / <float> self._height
self._aspect = ( <float> self._info.frame_width / \
<float> self._info.frame_height ) * \
( <float> self._info.aspect_numerator / \
@@ -84,4 +86,3 @@
cdef ogg.ogg_page *_page
_page = <ogg.ogg_page *> data
return 1
-
Modified: trunk/pysoy/src/textures/soy.textures.pxd
===================================================================
--- trunk/pysoy/src/textures/soy.textures.pxd 2007-07-07 06:54:18 UTC (rev
396)
+++ trunk/pysoy/src/textures/soy.textures.pxd 2007-07-07 08:18:41 UTC (rev
397)
@@ -31,6 +31,9 @@
cdef gl.GLsizei _width
cdef gl.GLsizei _height
cdef gl.GLsizei _depth
+ cdef gl.GLfloat _scaleX
+ cdef gl.GLfloat _scaleY
+ cdef gl.GLfloat _scaleZ
cdef float _aspect
cdef int _update
cdef gl.GLubyte *_texels
@@ -41,6 +44,7 @@
#
# C functions
cdef void _bind(self)
+ cdef void _unbind(self)
cdef void _resize(self, int, int, int, int)
cdef int _squareup(self, int)
Modified: trunk/pysoy/src/widgets/Canvas.pxi
===================================================================
--- trunk/pysoy/src/widgets/Canvas.pxi 2007-07-07 06:54:18 UTC (rev 396)
+++ trunk/pysoy/src/widgets/Canvas.pxi 2007-07-07 08:18:41 UTC (rev 397)
@@ -76,10 +76,7 @@
gl.glVertexPointer (3, gl.GL_FLOAT, 36, &self._verts[0].px)
gl.glNormalPointer ( gl.GL_FLOAT, 36, &self._verts[0].nx)
gl.glTexCoordPointer(3, gl.GL_FLOAT, 36, &self._verts[0].tx)
- gl.glDisable(gl.GL_TEXTURE_1D)
- gl.glEnable (gl.GL_TEXTURE_2D)
- gl.glDisable(gl.GL_TEXTURE_3D)
(<soy.textures.Texture> self._texture)._bind()
gl.glDrawElements (gl.GL_TRIANGLES, 6, gl.GL_UNSIGNED_SHORT,
<unsigned short *> self._faces)
- gl.glDisable (gl.GL_TEXTURE_2D)
+ (<soy.textures.Texture> self._texture)._unbind()
Modified: trunk/pysoy/tests/vid_canvas.py
===================================================================
--- trunk/pysoy/tests/vid_canvas.py 2007-07-07 06:54:18 UTC (rev 396)
+++ trunk/pysoy/tests/vid_canvas.py 2007-07-07 08:18:41 UTC (rev 397)
@@ -8,7 +8,6 @@
scr = soy.Screen()
win = soy.Window(scr, 'Video Canvas')
-win.background.hex = '#fff'
can = soy.widgets.Canvas(win, texture=vid)
if __name__ == '__main__' :
_______________________________________________
PySoy-SVN mailing list
[email protected]
http://www.pysoy.org/mailman/listinfo/pysoy-svn