View Full Version : GL_POINTS array issue

06-05-2009, 03:31 PM
I have an issue that has been giving me fits trying to debug, and am hoping someone here can help me locate the problem.

I am working on a game with some explosions that are made up of two parts:

1) A 2D polygon "card" for a bitmapped explosion graphic
2) An array of single-pixel points making up a particle system of "sparks" flying out from the explosion.

The view I'm rendering is out the front of a spaceship, and as the player steers, I am rotating the elements outside the window in my own code,with my spaceship always at 0,0,0 and looking out along the negative Z axis.

So let's say I set off an explosion. I create two elements in my data, one for the bitmapped vapor cloud and one for the particle system. Both have the same XYZ coordinates. Both initially appear in the same location on the screen.

Each explosion's particles are stored as an array of 3D points, all relative to the particle system's centerpoint. Each particle has its own position and vector, which is updated elsewhere and works fine. The plan here is that setting the transform to the center of the explosion would plot all the particles relative to that point on the screen, with the proper 3D transform handling the transformations of all the particles.

Here is the code which draws the particles:

for(int i = 0; i < thePExplosionObjects->active; ++i) {
glTranslatef(thePExplosionObjects->pos[i].x, thePExplosionObjects->pos[i].y, thePExplosionObjects->pos[i].z); // Positions the object
glVertexPointer(3, GL_FLOAT, 0, thePExplosionObjects->particles[i]); // And just point to the coordinate table!
glDrawArrays(GL_POINTS, 0, thePExplosionObjects->pcount[i]); // BAM! n points of debris plotted!

And here is the code that draws the bitmapped vapor clouds on 2d cards:

PlanarElement &amp;theElement = thePlanarElements.elements[index];
glVertexPointer(3, GL_FLOAT, 0, theElement.vertices);
glBindTexture(GL_TEXTURE_2D, theElement.texture);
glTexCoordPointer(2, GL_FLOAT, 0, theElement.texcoords);
glColor4ub(theElement.brite, theElement.brite, theElement.brite, theElement.brite);
glTranslatef(theElement.where.x, theElement.where.y, theElement.where.z); // Positions the object
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

The problem comes when I start steering around. As the ship steers (any axis), the particle system falls behind the bitmapped card -- Even though they are using the same transform (a simple translate to where they are located), and I have triple-checked to be sure that they are at the exact same 3D coordinates. I put in debug prints to the system log and the coordinates being fed to OpenGL are identical.

I even went in and simplified the particle system down to one point fixed at 0,0,0 within the particle system and that does the same thing -- It's almost as if the drawing of the points array is scaled differently somehow, despite the fact that I reset the transform to identity prior to the call.

Is there a reason why the drawing of a GL_POINTS array would not end up in the same place onscreen as a 2d card that was transformed to the exact same point in space? Are GL_POINTs not scaled the same way as the 2d card? I've been looking through all the documentation I can find, and cannot locate anything that says the GL_POINTS are treated any differently than any other element in OpenGL.

Any suggestions appreciated!

06-09-2009, 04:07 AM
If it's possible, I would render the points and the vapor cloud together, something like this:

glTranslate(x,y,z) // translate to center of explosion

drawPoints() would draw the particles using the coordinates relative to the center of the system, as would the 2d cards. I'm not entirely sure why what you're doing doesn't work, but rearranging it slightly may fix something or reveal the problem.

06-09-2009, 04:34 AM
The problem comes when I start steering around. As the ship steers (any axis), the particle system falls behind the bitmapped card

"the particle system falls behind", can you elaborate more on this? Perhaps some screenshots or videos may be helpful.