I made a quick LWJGL port of a fountain particle system. I skipped the texture bit (added a 1001 int value in place of a proper texture reference) for faster result.
/**
Simple LWJGL port of NatureWizard's fountain particle system (ORIGINAL CAN BE FOUND AT http://www.naturewizard.com/tutorial08.html)
Ported BY AGP (BR) ON Dec. 02, 2011
*/
import org.lwjgl.opengl.*;
import org.lwjgl.LWJGLException;
public class ParticleSystem {
private Particle[] particle;
public ParticleSystem() {
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.create();
}
catch (LWJGLException e) {System.out.println("Could not create display. ");e.printStackTrace();System.exit(1);}
particle = new Particle[10];
for (int i = 0; i < particle.length; i++)
createParticle(i);
loop();
}
public void createParticle(int i) {
particle[i] = new Particle();
particle[i].lifetime= (float)Math.random()*500000.0f;
particle[i].decay=0.001f;
particle[i].r = 0.7f;
particle[i].g = 0.7f;
particle[i].b = 1.0f;
particle[i].xpos= 0.0f;
particle[i].ypos= 0.0f;
particle[i].zpos= 0.0f;
particle[i].xspeed = 0.0005f-((float)Math.random()*100)/100000.0f;
particle[i].yspeed = 0.01f-(float)Math.random()*100/100000.0f;
particle[i].zspeed = 0.0005f-(float)Math.random()*100/100000.0f;
particle[i].active = true;
}
public void evolveParticle() {
for (int i = 0; i < particle.length; i++) { // evolve the particle parameters
particle[i].lifetime-=particle[i].decay;
particle[i].xpos+=particle[i].xspeed;
particle[i].ypos+=particle[i].yspeed;
particle[i].zpos+=particle[i].zspeed;
particle[i].yspeed-=0.00007;
}
}
public void drawObjects() {
// rendering functions
GL11.glLoadIdentity();
GL11.glRotatef(50.0f,1.0f,0.0f,0.0f); // show scene from top front
GL11.glBindTexture(GL11.GL_TEXTURE_2D,1001); // choose particle texture
for (int i = 0; i < particle.length; i++){
if (particle[i].ypos < 0.0f)
particle[i].lifetime = 0.0f;
if (particle[i].active==true && particle[i].lifetime > 0.0f) {
GL11.glColor3f(particle[i].r,particle[i].g,particle[i].b);
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(0.0f, 1.0f); GL11.glVertex3f(particle[i].xpos+0.002f, particle[i].ypos+0.002f, particle[i].zpos+0.0f); // top right
GL11.glTexCoord2f(0.0f, 0.0f); GL11.glVertex3f(particle[i].xpos-0.002f, particle[i].ypos+0.002f, particle[i].zpos+0.0f); // top left
GL11.glTexCoord2f(1.0f, 1.0f); GL11.glVertex3f(particle[i].xpos+0.002f, particle[i].ypos-0.002f, particle[i].zpos+0.0f); // bottom right
GL11.glTexCoord2f(1.0f, 0.0f); GL11.glVertex3f(particle[i].xpos-0.002f, particle[i].ypos-0.002f, particle[i].zpos+0.0f); // bottom left
GL11.glEnd();
}
else createParticle(i);
}
evolveParticle();
}
private void loop() {
while (!Display.isCloseRequested()) {
drawObjects();
Display.update();
}
Display.destroy();
}
public static void main(String[] args) {
new ParticleSystem();
}
}
class Particle {
protected float lifetime; // total lifetime of the particle
protected float decay; // decay speed of the particle
protected float r,g,b; // color values of the particle
protected float xpos,ypos,zpos; // position of the particle
protected float xspeed,yspeed,zspeed; // speed of the particle
protected boolean active;
}