Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Particle System 1 pass problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 I CAN DO   Members   -  Reputation: 164

Like
0Likes
Like

Posted 26 April 2013 - 12:19 PM

Im working in Particle System Class from this tutorial Particles - Anton's OpenGL 4 Wiki - Dr Anton Gerdelan

 

Code:

 

//Vertex Shader 

// shader to update a particle system based on a simple kinematics function
#version 330

in vec3 v; // initial velocity
in float tZero; // start time

uniform mat4 projViewModelMatrix;

uniform vec3 emitterPos_wor; // emitter position in world coordinates
uniform float T; // system time T in seconds

out float opacity;

void main() {
// work out how many seconds into our particle's life-time we are (after its starting time)
float t = T - tZero;
vec3 p;
// gradually make particle more transparent over its life-time
opacity = 1 - (t / 3) - 0.2;

// particle stays put until it has reached its birth second
if (t > 0) {
// gravity
vec3 a = vec3(0,-10,0);
// this is a standard kinematics equation of motion with velocity (from VBO) and acceleration (gravity)
p = emitterPos_wor + v * t + 0.5 * a * t * t;
} else {
p =  emitterPos_wor;
}
gl_Position = projViewModelMatrix * vec4(p, 1);
}


// Pixel shader

// shader to render simple particle system's points
#version 330

uniform sampler2D textureMap; // I used a texture for my particles
out vec4 fragColour;

uniform vec4 Color;

in float opacity;

void main() {
vec4 texcol = texture2D(textureMap, gl_PointCoord); // using point uv coordinates which are pre-defined over the point
fragColour = vec4(1-opacity,1-opacity,1-opacity,1-opacity) * texcol * Color; // bright blue!
}

/////// CPU

bool ParticleSystem::init(vec3 Position){

std::vector<vec3> Velocidad;
std::vector<float> Life;

for ( int i = 0; i < MAX_PARTICLES; i++ ) {
Velocidad.push_back(vec3(0,-1,0));
}

for ( int i = 0; i < MAX_PARTICLES; i++ ) {
Life.push_back(0.001f * (float)(i));
}


glGenVertexArrays( 1, &m_VAO );
glBindVertexArray( m_VAO );

glGenBuffers(ARRAY_SIZE_IN_ELEMENTS(m_Buffers), m_Buffers);

glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[VEL_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Velocidad[0]) * Velocidad.size(), &Velocidad[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);    

glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[LIF_VB]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Life[0]) * Life.size(), &Life[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);    

glBindVertexArray(0);

return true;
}

/////////////////// FINAL RENDER 

bool ParticleSystem::render(){

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,ModeloOrtho.getTextureFromID(24));

glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glEnable(GL_POINT_SPRITE);
glPointSize(150.0f);
shaderParticle.setUniform("projViewModelMatrix",vsml->get(VSMathLib::PROJ_VIEW_MODEL));
shaderParticle.setUniform("emitterPos_wor",ParticleInit);
shaderParticle.setUniform("T",ParticleTime);
shaderParticle.setUniform("Color",ColorParticle);

glUseProgram(shaderParticle.getProgramIndex()); 

glBindVertexArray(m_VAO);
glDrawElements(GL_POINTS, 0, GL_UNSIGNED_INT, 0); 
glBindVertexArray(0);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,0);
return true;
}

 

 

The problem is that nothing happens.

And if I change this line: glDrawElements (GL_POINTS, MAX_PARTICLES, GL_UNSIGNED_INT, 0); Crash the system.

What am I doing wrong?

Thank you, best regards.


Edited by I CAN DO, 26 April 2013 - 12:23 PM.


Sponsor:

#2 Sponji   Members   -  Reputation: 1349

Like
1Likes
Like

Posted 26 April 2013 - 12:33 PM

glDrawElements needs an indexbuffer, you probably want to use glDrawArrays instead.


Derp

#3 I CAN DO   Members   -  Reputation: 164

Like
0Likes
Like

Posted 26 April 2013 - 12:48 PM

Ok. Thank you!  

 

Like this?

 

glDrawArrays(GL_POINTS, 0MAX_PARTICLES); 



#4 Sponji   Members   -  Reputation: 1349

Like
0Likes
Like

Posted 26 April 2013 - 01:48 PM

Yup.


Derp

#5 I CAN DO   Members   -  Reputation: 164

Like
0Likes
Like

Posted 26 April 2013 - 04:56 PM

Thank you Sponji,

 

That was the problem






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS