Skip to content

Instantly share code, notes, and snippets.

@pingpoli
Created August 6, 2020 20:15
Show Gist options
  • Save pingpoli/31d3bd53b43a60c1c52550b2c2e7b39e to your computer and use it in GitHub Desktop.
Save pingpoli/31d3bd53b43a60c1c52550b2c2e7b39e to your computer and use it in GitHub Desktop.
SimpleEmitter::SimpleEmitter()
{
// create 100 particles
this->particles.resize( 100 );
for ( uint i = 0 ; i < this->particles.size() ; ++i )
{
// give every particle a random position
this->particles[i].position = lstd_random_between( vec3( -1.0f ) , vec3( 1.0f ) );
this->particles[i].lifetime = lstd_random_between( 1.0f , 2.0f );
}
// create a vertex and position buffer
this->vertexBuffer = lglGenBuffer();
this->positionBuffer = lglGenBuffer();
// fill the vertex buffer
std::vector< float > vertices;
vertices.push_back( 0.0f );
vertices.push_back( 0.0f );
vertices.push_back( 0.0f );
vertices.push_back( 1.0f );
vertices.push_back( 0.0f );
vertices.push_back( 0.0f );
vertices.push_back( 0.0f );
vertices.push_back( 1.0f );
vertices.push_back( 0.0f );
vertices.push_back( 1.0f );
vertices.push_back( 1.0f );
vertices.push_back( 0.0f );
glBindBuffer( GL_ARRAY_BUFFER , this->vertexBuffer );
glBufferData( GL_ARRAY_BUFFER , vertices.size()*sizeof(float) , vertices.data() , GL_STATIC_DRAW );
// fill the position buffer
glBindBuffer( GL_ARRAY_BUFFER , this->positionBuffer );
glBufferData( GL_ARRAY_BUFFER , this->particles.size()*4*sizeof(float) , this->positions , GL_DYNAMIC_DRAW );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment