Seriously strange things

Member
Posts: 215
Joined: 2008.06
Post: #1
Been working on a point sprite particle engine for quite a while now and it's thrown me yet another curve ball. I can draw the particles just fine. But I can't draw anything else. If I draw the other stuff, I can't draw the particles. Why? Simply, in code:

Code:
[ps drawParticles];
        glPushMatrix();
        glTranslatef([ps x], [ps y], [ps z]);
        [ps drawObject];
        glPopMatrix();

Taking out the drawParticles call draws the object as I expect, but obviously no particles. Leaving in the call doesn't draw the object, but draws the particles just fine. WTF?

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #2
What happens in [ps drawParticles]? Is it changing the blend function, binding the wrong texture, enabling/disabling states, transforming off screen etc.?
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #3
maximile Wrote:What happens in [ps drawParticles]? Is it changing the blend function, binding the wrong texture, enabling/disabling states, transforming off screen etc.?

The following is called on creation of the particle engine:

Code:
//Make space for particle limits and fill it from OGL call.
    GLfloat sizes[2];
    glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, sizes);
    
    //Enable point sprites and set params for points.
    float quadratic[] =  { 1.0f, 0.0f, 0.01f };
    glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic );
    glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 60.0f );
    
    //Tell it the max and min sizes we can use using our pre-filled array.
    glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, sizes[0] );
    glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, sizes[1] );
    
    //Tell OGL to replace the coordinates upon drawing.
    glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
    
    //Set the size of the points.
    glPointSize(16.0f);

And the following happens when [ps drawParticles] is callled:

Code:
//Create the texture we want to use.
    BBSTexture* t = textures[0];
    
    //Enable our texture type (in this case, it must be GL_TEXTURE_2D)
    glEnable([t type]);
    
    //Bind the texture data.
    glBindTexture([t type], [t data]);
    
    //Enable blending and set for particles
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    
    //Turn off depth masking so particles in front will not occlude particles behind them.
    //glDepthMask(GL_FALSE);
    
    glDisable(GL_DEPTH_TEST);
    
    //Save the current transform.
    glPushMatrix();
    
    glEnable(GL_POINT_SPRITE_ARB);
    
    //Begin drawing points.
    glBegin(GL_POINTS);
    //Iterate through our particles, setting the color and specifying their position.
    for (Particle* p in particles)
    {
        glColor4f([[p color] magnitudeX], [[p color] magnitudeY] - [p lifespan], [[p color] magnitudeZ] - ([p lifespan] * 2), [[p color] magnitudeW]);
        glVertex3f([p x], [p y], [p z]);
    }
    glEnd();    //Stop drawing points.
    
    //glDepthMask(GL_TRUE);
    
    glDisable(GL_POINT_SPRITE_ARB);
    
    glEnable(GL_DEPTH_TEST);
    
    //glDisable(GL_BLEND);
    
    //Return to the previous matrix.
    glPopMatrix();

Keep in mind, my texturing loading is still giving me issues (see my other new thread) so that may be one of the major stumbling blocks at the moment. However, as I said before, if I try to draw both the particle source (a simple green quad) and the particles in the same frame, one of them does not display (usually source).

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
-drawParticles changes GL state by leaving a texture enabled and bound, GL_BLEND enabled, and potentially changes the current color. All of those are likely to affect subsequent drawing.
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #5
so...

glDisable(GL_TEXTURE_RECTANGLE_EXT);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDisable(ANYTHING ELSE);

will solve my problems?

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #6
Try my tips on how to debug. Here, you want to set a breakpoint in OpenGL Profiler on your draw call that doesn't work, and inspect all of the state. Profiler lets you save the state to a text file, so you can keep it around. Then change your app so the draw call works, and repeat. Compare the two sets of state-- what's different?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL text and other things. Talyn 7 4,562 Jul 22, 2008 02:09 AM
Last Post: OneSadCookie
  3D Things Douglas O'Brien 11 4,794 Aug 15, 2002 09:20 PM
Last Post: Ian Kerr