iDevGames Forums
Seriously strange things - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Seriously strange things (/thread-1794.html)



Seriously strange things - Talyn - Feb 5, 2009 08:25 PM

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?


Seriously strange things - maximile - Feb 5, 2009 11:48 PM

What happens in [ps drawParticles]? Is it changing the blend function, binding the wrong texture, enabling/disabling states, transforming off screen etc.?


Seriously strange things - Talyn - Feb 7, 2009 10:47 AM

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).


Seriously strange things - ThemsAllTook - Feb 7, 2009 12:41 PM

-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.


Seriously strange things - Talyn - Feb 7, 2009 09:00 PM

so...

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

will solve my problems?


Seriously strange things - arekkusu - Feb 8, 2009 11:28 AM

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?