Changeset 1358

Show
Ignore:
Timestamp:
09/10/08 15:02:17 (3 months ago)
Author:
DavidCzech
Message:

* No Ticket : Changing Axis to VBO

Location:
trunk/pysoy
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/pysoy/examples/pysoy_primer.py

    r1182 r1358  
    1616mat = soy.materials.Material() # Step 2: Material 
    1717mat.shininess = 5 # (Optional) Looks nicer (modifies the applied specular lighting; play with this setting to see how it affects appearance) 
    18 body = soy.bodies.Body(scene=sce, model=soy.models.Shape(mat), shape=cube) # Step 3: Body 
     18body = soy.bodies.Body(scene=sce, model=soy.models.Axis(), shape=cube) # Step 3: Body 
    1919 
    2020# Put a light and camera into the initialized screen 
  • trunk/pysoy/include/soy.models.pxd

    r1272 r1358  
    9999  cdef void                         _renderSurf    ( self ) 
    100100  cdef void                         _renderBottom  ( self ) 
     101 
     102cdef class Axis (Model) : 
     103  cdef gl.GLuint                    _vertexBuffer# VBO ids 
     104  cdef gl.GLuint                    _elementBuffer 
     105  cdef float                        _axis[12] # contains both vertex and color data 
     106  cdef char                         _elements[2] # contains infomation to render the above vertex data in order 
     107  cdef void                         _createBuffer  ( self ) 
     108   
     109 
     110 
  • trunk/pysoy/src/models/Axis.pym

    r1355 r1358  
    2424    body it's attached to.  This is useful for debugging. 
    2525  ''' 
     26  def __cinit__( self ) : 
     27    #self._axis = <gl.GLfloat *> ( 0,0,0,      1,0,0, # format XYZRGB 
     28    #              1,0,0,      1,0,0 ) 
     29    #              # 1.,0.3,0.   1,0,0 
     30    self._axis[0] =  0 
     31    self._axis[1] = 0 
     32    self._axis[2] = 0 
     33    self._axis[3] = 1 
     34    self._axis[4] = 0 
     35    self._axis[5] = 0 
     36    self._axis[6] = 1 
     37    self._axis[7] = 0 
     38    self._axis[8] = 0 
     39    self._axis[9] = 1 
     40    self._axis[10] = 0 
     41    self._axis[11] = 0 
     42    self._elements[0] = <char>0 
     43    self._elements[1] = <char>1 
     44    self._vertexBuffer  = 0 
     45    self._elementBuffer = 0 
     46    # Generate Buffers 
    2647 
     48  cdef void _createBuffer(self) : 
     49    gl.glGenBuffersARB(1, <gl.GLuint*> &self._vertexBuffer); 
     50    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._vertexBuffer); 
     51    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB,sizeof(self._axis) , self._axis, gl.GL_STATIC_DRAW_ARB); 
     52    gl.glGenBuffersARB(1, <gl.GLuint*> &self._elementBuffer); 
     53    gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, self._elementBuffer); 
     54    gl.glBufferDataARB(gl.GL_ARRAY_BUFFER_ARB, sizeof(self._elements), self._elements, gl.GL_STATIC_DRAW_ARB); 
    2755 
    2856  ############################################################################ 
     
    3563    # This should be upgraded to use VBO.  Test for buffer ID here. 
    3664    # 
    37     gl.glPushMatrix() 
     65    if self._vertexBuffer : 
     66      gl.glBindBufferARB(gl.GL_ARRAY_BUFFER_ARB, <gl.GLuint> self._vertexBuffer) # Bind to buffer for rendering below 
     67      gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._elementBuffer)  
     68    else: 
     69      self._createBuffer() 
     70    gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); 
     71    gl.glDisableClientState(gl.GL_NORMAL_ARRAY); 
     72    gl.glEnableClientState(gl.GL_COLOR_ARRAY); # We need to render with color arrays 
     73    gl.glVertexPointer(3, gl.GL_FLOAT, 0,<gl.GLvoid *> 0); 
     74    gl.glColorPointer(3,gl.GL_FLOAT,3*sizeof(float),<gl.GLvoid *>0); 
     75    #gl.glPushMatrix() 
    3876    gl.glDisable(gl.GL_CULL_FACE) 
    3977    gl.glDisable(gl.GL_DEPTH_TEST) 
    4078    gl.glDisable(gl.GL_LIGHTING) 
    41     gl.glColor3f(1.,0.,0.) 
    42     gl.glBegin(gl.GL_LINES) 
    43     gl.glColor3f(1.,0.,0.) 
    44     gl.glVertex3f(0.,0.,0.) 
    45     gl.glVertex3f(1.,0.,0.) 
    46     gl.glVertex3f(1.,0.,0.) 
    47     gl.glVertex3f(1.,0.3,0.) 
    48     gl.glVertex3f(1.,0.3,0.) 
    49     gl.glVertex3f(1.3,0,0.) 
    50     gl.glVertex3f(1.3,0,0.) 
    51     gl.glVertex3f(1,-0.3,0.) 
    52     gl.glVertex3f(1,-0.3,0.) 
    53     gl.glVertex3f(1,0,0.) 
    54     gl.glColor3f(0.,1.,0.) 
    55     gl.glVertex3f(0.,0.,0.) 
    56     gl.glVertex3f(0.,1.,0.) 
    57     gl.glVertex3f(0.,1.,0.) 
    58     gl.glVertex3f(0.3,1.,0.) 
    59     gl.glVertex3f(0.3,1.,0.) 
    60     gl.glVertex3f(0.0,1.3,0.) 
    61     gl.glVertex3f(0.0,1.3,0.) 
    62     gl.glVertex3f(-0.3,1.0,0.) 
    63     gl.glVertex3f(-0.3,1.0,0.) 
    64     gl.glVertex3f(0.,1.0,0.) 
    65     gl.glColor3f(0.,0.,1.) 
    66     gl.glVertex3f(0.,0.,0.) 
    67     gl.glVertex3f(0.,0.,1.) 
    68     gl.glVertex3f(0.,0.,1.) 
    69     gl.glVertex3f(0.3,0.,1.) 
    70     gl.glVertex3f(0.3,0.,1.) 
    71     gl.glVertex3f(0.0,0.,1.3) 
    72     gl.glVertex3f(0.0,0.,1.3) 
    73     gl.glVertex3f(-0.3,0.,1.0) 
    74     gl.glVertex3f(-0.3,0.,1.0) 
    75     gl.glVertex3f(0.0,0.,1.0)  
    76     gl.glEnd() 
    77     gl.glBegin(gl.GL_LINE_STRIP) 
    78     gl.glColor3f(0.,0.,1.) 
    79     gl.glVertex3f(-0.2,0,1.35)# 
    80     gl.glVertex3f(0.2,0.,1.35) 
    81     gl.glVertex3f(-0.2,0.,1.75) # Z TAG 
    82     gl.glVertex3f(0.2,0.,1.75) # 
    83     gl.glEnd() 
    84     gl.glBegin(gl.GL_LINE_STRIP) 
    85     gl.glColor3f(0.,1.,0) 
    86     gl.glVertex3f(0.0,1.35,0)# 
    87     gl.glVertex3f(0.0,1.5,0) # Y TAG 
    88     gl.glVertex3f(0.2,1.7,0) # 
    89     gl.glVertex3f(0.0,1.5,0) 
    90     gl.glVertex3f(-0.2,1.7,0) 
    91     gl.glEnd() 
    92     gl.glBegin(gl.GL_LINES) 
    93     gl.glColor3f(1.,0.,0.) 
    94     gl.glVertex3f(1.35,0.2,0)# 
    95     gl.glVertex3f(1.75,-0.2,0) # X TAG 
    96     gl.glVertex3f(1.35,-0.2,0) # 
    97     gl.glVertex3f(1.75,0.2,0) 
    98     gl.glEnd() 
     79    gl.glDrawElements(gl.GL_LINES,1,gl.GL_UNSIGNED_BYTE,<gl.GLvoid *>0) 
    9980    gl.glEnable(gl.GL_LIGHTING) 
    10081    gl.glEnable(gl.GL_DEPTH_TEST) 
    10182    gl.glEnable(gl.GL_CULL_FACE)  
    102     gl.glPopMatrix() 
     83    #gl.glPopMatrix() 
     84    gl.glDisableClientState(gl.GL_COLOR_ARRAY); 
     85    gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY); 
     86    gl.glEnableClientState(gl.GL_NORMAL_ARRAY);