PDA

View Full Version : OpenGL particle system



stan_smith
03-10-2011, 03:44 AM
I'm really new with OpenGL, so bear with me.

I'm trying to simulate a particle system using OpenGl but I can't get it to work, this is what I have so far:



#include <GL/glut.h>
int main (int argc, char **argv){

// data allocation, various non opengl stuff
............
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE );
glutInitWindowPosition(100,100);
glutInitWindowSize(size, size);
glPointSize (4);
glutCreateWindow("test gl");
............
// initial state, not opengl
............
glViewport(0,0,size,size);
glutDisplayFunc(display);
glutIdleFunc(compute);
glutMainLoop();


}

void compute (void) {

// change state not opengl

glutPostRedisplay();

}

void display (void) {

glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);

for(i = 0; i<nparticles; i++) {

// two types of particles
if (TYPE(particle[i]) == 1) glColor3f(1,0,0);
else glColor3f(0,0,1);

glVertex2f(X(particle[i]),Y(particle[i]));

}

glEnd();
glFlush();
glutSwapBuffers();

}


I get a black window after a couple of seconds (the window has just the title bar before that). Where do I go wrong? Any help would be very much appreciated. Thanks.

The x and y coordinates of each particle are within the interval (0,size)

mobeen
03-10-2011, 04:13 AM
There are a number of things wrong here
1) You should always call gl functions after calling glutCreateWindow. Here u r calling glPointSize before this call.
2) You have not setup ur projection matrix, modelview matrix .

Zenja
03-15-2011, 08:23 AM
Most particle systems use GL_POINT_SPRITES instead of GL_POINTS. Also, use the alpha channel to simulate fading out of particles.