So here is my code. If you find anything “suspicious” let me know.
To be honest, now I’m sure that it is a problem with my OpenGL
implementation. I don’t know precisly how OGL use a framebuffer
but it seems that writing repetadly colors in the same position causes
lost of performance. For example, if IsRotating flag is set on true
program runs faster because particles are rotating and the don’t accumulate.
I’m not sure if there is any simple way to make things better.
Here are 3 basic functions which draws and update particles,
move them and create display lists for them.
<CODE>
void PARTICLE::SolveSimple(float dt)
{
// Solving Euler equation
V = V + a * dt;
Pos = Pos + V * dt;
}
void PARTICLE::Live(float dt)
{
// Drawing
glPushMatrix();
glTranslatef(Pos.x, Pos.y, Pos.z);
GLfloat Kolor[] = {R, G, B, Energy};
glColor4fv(Kolor);
if (IsRotating)
{
glRotatef(CurRotX, 1, 0, 0);
glRotatef(CurRotY, 0, 1, 0);
glRotatef(CurRotZ, 0, 0, 1);
CurRotX += RotX;
CurRotY += RotY;
CurRotZ += RotZ;
}
glCallList(ListID);
glPopMatrix();
// Updating current particle
Energy -= DyingSpeed * dt;
SolveSimple(dt);
}
GLuint CreateParticle(TEXTURE tekstura)
{
// Creates a display list for a specified texture to use in particles
GLuint lista;
lista = glGenLists(1);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, tekstura);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glNewList(lista, GL_COMPILE);
glDisable(GL_DEPTH_TEST);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0, 1); glVertex2f(-1, 1);
glTexCoord2f(0, 0); glVertex2f(-1, -1);
glTexCoord2f(1, 1); glVertex2f(1, 1);
glTexCoord2f(1, 0); glVertex2f(1, -1);
glEnd();
glEnable(GL_DEPTH_TEST);
glEndList();
return lista;
}
</CODE>
Thanks
See you,
Orzech