PDA

View Full Version : Particles



ArchMiffo
08-31-2002, 01:02 AM
Is there a way to use glBegin(GL_POINTS) to draw points to witch a whole texture can be applied. If this is possible I would also like to know how to change the size of the points. The reason I want to know all this is that I'm converting a particlesystem I've previously written in directx.
Thanks

ArchMiffo
08-31-2002, 02:38 AM
I need help with this. For the moment I'm drawing quads but it is extremly slow. The number of particles I'm using worked very smooth in my directx code but now it's useless. Am I doing the quads the wrong way do make it this slow?

V66ras
08-31-2002, 01:20 PM
Do you need to use textures?
I mean: can you do (whatever you do) with just large antialiased points?

Maybe you can use triangles instead of quads?

I have allso heard from a extension that would do exactly what you want - but don't remember where (sorry - no name to give).


Originally posted by ArchMiffo:
/.../ Am I doing the quads the wrong way do make it this slow?

Show some code.

MrShoe
08-31-2002, 03:39 PM
Im pretty sure you cant apply a texture to a point, for what should be obvious reasons, it isnt a 2 dimentional object, a point is actually a 0 dimentional object...
Anyway, what you CAN do, is use an extension that alters the size of teh point depending on its distance from the camera, because by default a point is always teh same size in OpenGL, unless you manually alter it. I forgot what the extentions exact name is, but i do know its an SGI extention, and it was used in teh Quake2 engine for its particle system.

However, i dont see why using quads should be slow... Someone correct me if im wrong, but dont most particle systems use triangles or quads with an applied texture??

How are you translating the particle quads?? if you are using glTranslatef to translate the entire matrix of the quad, thats SLOW, instead, alter the parameters of glVertex3f for the particle, translating it that way instead of translating the entire matrix.

[This message has been edited by MrShoe (edited 08-31-2002).]

ArchMiffo
08-31-2002, 11:33 PM
Thanks for the replys, here's some code:

glColor3ub(m_Col.r, m_Col.g, m_Col.b);


glTranslatef(m_Pos.x, m_Pos.y, m_Pos.z);

glBegin(GL_QUADS);

glTexCoord2f(0, 0);
glVertex3f(-m_Size, m_Size, 0);

glTexCoord2f(1, 0);
glVertex3f(m_Size, m_Size, 0);

glTexCoord2f(1, 1);
glVertex3f(m_Size, -m_Size, 0);

glTexCoord2f(0,1);
glVertex3f(-m_Size, -m_Size, 0);

glEnd(); // Done drawing quad

This code is more or less copied from the tutorial I've been reading since I'm new to opengl. The strange thing about theese slowdowns is that they occur at a specific distance from the particlesystem. When the particles are at say coordinate (0,0,0) I can't be close to them. If I'm far away it works just fine. If, however, I move the particlesystem to coordinate (0,0,-10), the slowdown occurs when the camera is somewhere around coodinate (0,0,0). What the hell is going on here?

[This message has been edited by ArchMiffo (edited 09-01-2002).]

V66ras
09-01-2002, 06:25 AM
Originally posted by ArchMiffo:
Thanks for the replys, here's some code:

glColor3ub(m_Col.r, m_Col.g, m_Col.b);


glTranslatef(m_Pos.x, m_Pos.y, m_Pos.z);

glBegin(GL_QUADS);

glTexCoord2f(0, 0);
glVertex3f(-m_Size, m_Size, 0);

glTexCoord2f(1, 0);
glVertex3f(m_Size, m_Size, 0);

glTexCoord2f(1, 1);
glVertex3f(m_Size, -m_Size, 0);

glTexCoord2f(0,1);
glVertex3f(-m_Size, -m_Size, 0);

glEnd(); // Done drawing quad

This code is more or less copied from the tutorial I've been reading since I'm new to opengl. The strange thing about theese slowdowns is that they occur at a specific distance from the particlesystem. When the particles are at say coordinate (0,0,0) I can't be close to them. If I'm far away it works just fine. If, however, I move the particlesystem to coordinate (0,0,-10), the slowdown occurs when the camera is somewhere around coodinate (0,0,0). What the hell is going on here?

[This message has been edited by ArchMiffo (edited 09-01-2002).]
You should draw all quads in one begin/end block and get rid from the translate.

Where you bind your texture (you should do that only once per frame)?
How big is the texture?

ArchMiffo
09-01-2002, 09:16 AM
Here's some updated code:

ParticleVec::iterator itend = m_Particles.end();
for(ParticleVec::iterator it=m_Particles.begin(); it!=itend; ++it)
{
glBegin(GL_TRIANGLE_STRIP); // Build Quad From A Triangle Strip
glColor3ub(it->m_Col.r, it->m_Col.g, it->m_Col.b); // Use particle's color

glTexCoord2d(1,1);
glVertex3f(it->m_Pos.x+it->m_Size,it->m_Pos.y+it->m_Size,it->m_Pos.z); // Top Right

glTexCoord2d(0,1);
glVertex3f(it->m_Pos.x-it->m_Size,it->m_Pos.y+it->m_Size,it->m_Pos.z); // Top Left

glTexCoord2d(1,0);
glVertex3f(it->m_Pos.x+it->m_Size,it->m_Pos.y-it->m_Size,it->m_Pos.z); // Bottom Right

glTexCoord2d(0,0);
glVertex3f(it->m_Pos.x-it->m_Size,it->m_Pos.y-it->m_Size,it->m_Pos.z); // Bottom Left
glEnd(); // Done Building Triangle Strip
} // end for

The texture is 128*128 and is set before the loop. However, I don't think the prolem is with slow rendering. As I said before it works fine sometimes. It kind of feels as if it slows down when the cameras position changes from positive to negative coordinates, it's very wierd. How could the position of the camera affect the framerate? And it's not a small difference, we are talking 60 fps compared to slideshows here, just by changing the camera.

[This message has been edited by ArchMiffo (edited 09-01-2002).]

MrShoe
09-01-2002, 09:41 PM
What is happening to you is fillrate problems... you see, when the particle system is closer to the camera and thus takes up more pixels, there will be slowdown. This also occurs if the particles are very large, basically it depends on how much pixels the particle system takes up. This slowdown occurs because of the alpha blending... I dont think there is any easy way around this except to use fewer particles, and try not to have the particle system very close to the screen. You can have lots of particles as long as they dont take up much screen space (pixels).