GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


A Paste by iridium
1
 
class CParticleEmitter
{
public:
    float * ParticlePositionsList;
    float * ParticleColourList;

    float * ParticleVelocityList;

    void Initialize()
    {
        ParticlePositionsList = new float[ numParticles * (TrailLength+2) * 3 + 1 ];
        ParticleColourList    = new float[ numParticles * (TrailLength+2) * 4 + 1 ];
        ParticleVelocityList  = new float[ numParticles * 3 + 1 ];

        if ( !ParticlePositionsList || !ParticleColourList || !ParticleVelocityList )
            throw;

        memset( ParticlePositionsList, 0, numParticles * (TrailLength+2) * 3 );
        memset( ParticleColourList,    0, numParticles * (TrailLength+2) * 4 );
        memset( ParticleVelocityList,  0, numParticles * 3 );
        for ( int i = 0; i < numParticles; i++ )
            ReSpawnParticle( i );
    }

    void Render()
    {
        int temp;
        //VertexCount = 0;
        VertexCount = numParticles * (TrailLength+2);


        glColorPointer( 4, GL_FLOAT, 0, ParticleColourList );
        glVertexPointer( 3, GL_FLOAT, 0, ParticlePositionsList );

        glEnableClientState( GL_VERTEX_ARRAY );
        glEnableClientState( GL_COLOR_ARRAY );

        glDrawArrays( GL_LINE_STRIP, 0, numParticles * (TrailLength + 2) );

        temp = glGetError();
        if ( temp != 0 )
            throw;
    }
}