Author: DavidCzech
Date: 2008-09-10 15:02:17 -0400 (Wed, 10 Sep 2008)
New Revision: 1358

Modified:
   trunk/pysoy/examples/pysoy_primer.py
   trunk/pysoy/include/soy.models.pxd
   trunk/pysoy/src/models/Axis.pym
Log:
* No Ticket : Changing Axis to VBO


Modified: trunk/pysoy/examples/pysoy_primer.py
===================================================================
--- trunk/pysoy/examples/pysoy_primer.py        2008-09-08 23:45:36 UTC (rev 
1357)
+++ trunk/pysoy/examples/pysoy_primer.py        2008-09-10 19:02:17 UTC (rev 
1358)
@@ -15,7 +15,7 @@
 cube = soy.shapes.Box(1, 1, 1) # Step 1: Shape
 mat = soy.materials.Material() # Step 2: Material
 mat.shininess = 5 # (Optional) Looks nicer (modifies the applied specular 
lighting; play with this setting to see how it affects appearance)
-body = soy.bodies.Body(scene=sce, model=soy.models.Shape(mat), shape=cube) # 
Step 3: Body
+body = soy.bodies.Body(scene=sce, model=soy.models.Axis(), shape=cube) # Step 
3: Body
 
 # Put a light and camera into the initialized screen
 light = soy.bodies.Light(sce)
@@ -31,4 +31,4 @@
 
 #  Main loop: each run through this loop keeps the window open and rotates the 
cube
 while True:
-    sleep(.1)
\ No newline at end of file
+    sleep(.1)

Modified: trunk/pysoy/include/soy.models.pxd
===================================================================
--- trunk/pysoy/include/soy.models.pxd  2008-09-08 23:45:36 UTC (rev 1357)
+++ trunk/pysoy/include/soy.models.pxd  2008-09-10 19:02:17 UTC (rev 1358)
@@ -98,3 +98,13 @@
   # WindowLoop functions
   cdef void                         _renderSurf    ( self )
   cdef void                         _renderBottom  ( self )
+
+cdef class Axis (Model) :
+  cdef gl.GLuint                    _vertexBuffer# VBO ids
+  cdef gl.GLuint                    _elementBuffer
+  cdef float                        _axis[12] # contains both vertex and color 
data
+  cdef char                         _elements[2] # contains infomation to 
render the above vertex data in order
+  cdef void                         _createBuffer  ( self )
+  
+
+

Modified: trunk/pysoy/src/models/Axis.pym
===================================================================
--- trunk/pysoy/src/models/Axis.pym     2008-09-08 23:45:36 UTC (rev 1357)
+++ trunk/pysoy/src/models/Axis.pym     2008-09-10 19:02:17 UTC (rev 1358)
@@ -23,8 +23,36 @@
     This L{models class<soy.models>} renders a "XYZ axis" oriented to each 
     body it's attached to.  This is useful for debugging.
   '''
+  def __cinit__( self ) :
+    #self._axis = <gl.GLfloat *> ( 0,0,0,      1,0,0, # format XYZRGB
+    #              1,0,0,      1,0,0 )
+    #              # 1.,0.3,0.   1,0,0
+    self._axis[0] =  0
+    self._axis[1] = 0
+    self._axis[2] = 0
+    self._axis[3] = 1
+    self._axis[4] = 0
+    self._axis[5] = 0
+    self._axis[6] = 1
+    self._axis[7] = 0
+    self._axis[8] = 0
+    self._axis[9] = 1
+    self._axis[10] = 0
+    self._axis[11] = 0
+    self._elements[0] = <char>0
+    self._elements[1] = <char>1
+    self._vertexBuffer  = 0
+    self._elementBuffer = 0
+    # Generate Buffers
+
+  cdef void _createBuffer(self) :
+    gl.glGenBuffersARB(1, <gl.GLuint*> &self._vertexBuffer);
+    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertexBuffer);
+    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB,sizeof(self._axis) , self._axis, 
gl.GL_STATIC_DRAW_ARB);
+    gl.glGenBuffersARB(1, <gl.GLuint*> &self._elementBuffer);
+    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elementBuffer);
+    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(self._elements), 
self._elements, gl.GL_STATIC_DRAW_ARB);
 
-
   ############################################################################
   #
   # WindowLoop Functions
@@ -33,70 +61,26 @@
   cdef void _render(self, soy.bodies.Body _body) :
     #
     # This should be upgraded to use VBO.  Test for buffer ID here.
-    #
-    gl.glPushMatrix()
+    #
+    if self._vertexBuffer :
+      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, <gl.GLuint> 
self._vertexBuffer) # Bind to buffer for rendering below
+      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementBuffer) 
+    else:
+      self._createBuffer()
+    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+    gl.glDisableClientState(gl.GL_NORMAL_ARRAY);
+    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color 
arrays
+    gl.glVertexPointer(3, gl.GL_FLOAT, 0,<gl.GLvoid *> 0);
+    gl.glColorPointer(3,gl.GL_FLOAT,3*sizeof(float),<gl.GLvoid *>0);
+    #gl.glPushMatrix()
     gl.glDisable(gl.GL_CULL_FACE)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_LIGHTING)
-    gl.glColor3f(1.,0.,0.)
-    gl.glBegin(gl.GL_LINES)
-    gl.glColor3f(1.,0.,0.)
-    gl.glVertex3f(0.,0.,0.)
-    gl.glVertex3f(1.,0.,0.)
-    gl.glVertex3f(1.,0.,0.)
-    gl.glVertex3f(1.,0.3,0.)
-    gl.glVertex3f(1.,0.3,0.)
-    gl.glVertex3f(1.3,0,0.)
-    gl.glVertex3f(1.3,0,0.)
-    gl.glVertex3f(1,-0.3,0.)
-    gl.glVertex3f(1,-0.3,0.)
-    gl.glVertex3f(1,0,0.)
-    gl.glColor3f(0.,1.,0.)
-    gl.glVertex3f(0.,0.,0.)
-    gl.glVertex3f(0.,1.,0.)
-    gl.glVertex3f(0.,1.,0.)
-    gl.glVertex3f(0.3,1.,0.)
-    gl.glVertex3f(0.3,1.,0.)
-    gl.glVertex3f(0.0,1.3,0.)
-    gl.glVertex3f(0.0,1.3,0.)
-    gl.glVertex3f(-0.3,1.0,0.)
-    gl.glVertex3f(-0.3,1.0,0.)
-    gl.glVertex3f(0.,1.0,0.)
-    gl.glColor3f(0.,0.,1.)
-    gl.glVertex3f(0.,0.,0.)
-    gl.glVertex3f(0.,0.,1.)
-    gl.glVertex3f(0.,0.,1.)
-    gl.glVertex3f(0.3,0.,1.)
-    gl.glVertex3f(0.3,0.,1.)
-    gl.glVertex3f(0.0,0.,1.3)
-    gl.glVertex3f(0.0,0.,1.3)
-    gl.glVertex3f(-0.3,0.,1.0)
-    gl.glVertex3f(-0.3,0.,1.0)
-    gl.glVertex3f(0.0,0.,1.0) 
-    gl.glEnd()
-    gl.glBegin(gl.GL_LINE_STRIP)
-    gl.glColor3f(0.,0.,1.)
-    gl.glVertex3f(-0.2,0,1.35)#
-    gl.glVertex3f(0.2,0.,1.35)
-    gl.glVertex3f(-0.2,0.,1.75) # Z TAG
-    gl.glVertex3f(0.2,0.,1.75) #
-    gl.glEnd()
-    gl.glBegin(gl.GL_LINE_STRIP)
-    gl.glColor3f(0.,1.,0)
-    gl.glVertex3f(0.0,1.35,0)#
-    gl.glVertex3f(0.0,1.5,0) # Y TAG
-    gl.glVertex3f(0.2,1.7,0) #
-    gl.glVertex3f(0.0,1.5,0)
-    gl.glVertex3f(-0.2,1.7,0)
-    gl.glEnd()
-    gl.glBegin(gl.GL_LINES)
-    gl.glColor3f(1.,0.,0.)
-    gl.glVertex3f(1.35,0.2,0)#
-    gl.glVertex3f(1.75,-0.2,0) # X TAG
-    gl.glVertex3f(1.35,-0.2,0) #
-    gl.glVertex3f(1.75,0.2,0)
-    gl.glEnd()
+    gl.glDrawElements(gl.GL_LINES,1,gl.GL_UNSIGNED_BYTE,<gl.GLvoid *>0)
     gl.glEnable(gl.GL_LIGHTING)
     gl.glEnable(gl.GL_DEPTH_TEST)
     gl.glEnable(gl.GL_CULL_FACE) 
-    gl.glPopMatrix()
+    #gl.glPopMatrix()
+    gl.glDisableClientState(gl.GL_COLOR_ARRAY);
+    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
+    gl.glEnableClientState(gl.GL_NORMAL_ARRAY);

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to