OpenGL particle system
        Posted  
        
            by 
                allan
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by allan
        
        
        
        Published on 2011-03-10T04:17:17Z
        Indexed on 
            2011/03/10
            16:10 UTC
        
        
        Read the original article
        Hit count: 379
        
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(&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.
LE: the x and y coordinates of each particle are within the interval (0,size)
© Stack Overflow or respective owner