# OpenGL Particle System 1 pass problems

This topic is 2059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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);
}

// 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<float> Life;

for ( int i = 0; i < MAX_PARTICLES; i++ ) {
}

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]);
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);

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

##### Share on other sites

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

##### Share on other sites

Ok. Thank you!

Like this?

glDrawArrays(GL_POINTS, 0MAX_PARTICLES);

Yup.

##### Share on other sites

Thank you Sponji,

That was the problem

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633725
• Total Posts
3013561
×