I want to render a ParticleGroup
from JBox2d
using OpenGL. I've managed to define a particle group area, but I'm unsure how to draw the individual particles.
Here's how I create the ParticleGroup
:
m_world.setParticleRadius(0.15f);
m_world.setParticleDamping(0.2f);
PolygonShape shape = new PolygonShape();
shape.setAsBox(8, 10, new Vec2(-12, 10.1f), 0);
ParticleGroupDef pd = new ParticleGroupDef();
pd.shape = shape;
m_world.createParticleGroup(pd);
This is how I draw a normal Square
(which I don't know how to apply to groups of particles):
public void draw(GLAutoDrawable gLDrawable, Vec3 position, float angle){
gLDrawable.getGL().getGL2().glEnable(GL.GL_BLEND);
gLDrawable.getGL().getGL2().glEnable(GL.GL_TEXTURE_2D);
gLDrawable.getGL().getGL2().glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gLDrawable.getGL().getGL2().glBindTexture(GL2.GL_TEXTURE_2D, TextureFactory.getTextureIndex(TextureCollection.valueOf(getTextureSelection())));
gLDrawable.getGL().getGL2().glPushMatrix();
gLDrawable.getGL().getGL2().glTranslatef(position.x * getP2M(), position.y * getP2M(), position.z);
gLDrawable.getGL().getGL2().glRotated(Math.toDegrees(angle), 0, 0, 1);
gLDrawable.getGL().getGL2().glBegin(GL2.GL_QUADS);
gLDrawable.getGL().getGL2().glTexCoord2f(0.0f, 0.0f);
gLDrawable.getGL().getGL2().glVertex3f(-getWidth() / 2 * getP2M(), -getHeight() / 2 * getP2M(), 0.0f);
gLDrawable.getGL().getGL2().glTexCoord2f(0.0f, 1.0f);
gLDrawable.getGL().getGL2().glVertex3f(-getWidth() / 2 * getP2M(), getHeight() / 2 * getP2M(), 0.0f);
gLDrawable.getGL().getGL2().glTexCoord2f(1.0f, 1.0f);
gLDrawable.getGL().getGL2().glVertex3f(getWidth() / 2 * getP2M(), getHeight() / 2 * getP2M(), 0.0f);
gLDrawable.getGL().getGL2().glTexCoord2f(1.0f, 0.0f);
gLDrawable.getGL().getGL2().glVertex3f(getWidth() / 2 * getP2M(), -getHeight() / 2 * getP2M(), 0.0f);
gLDrawable.getGL().getGL2().glEnd();
gLDrawable.getGL().getGL2().glFlush();
gLDrawable.getGL().getGL2().glPopMatrix();
gLDrawable.getGL().getGL2().glDisable(GL.GL_TEXTURE_2D);
gLDrawable.getGL().getGL2().glDisable(GL.GL_BLEND);
}
How should I do this? (Example code would be great.)