explosions using OpenGL and textures...

Sage
Posts: 1,199
Joined: 2004.10
Post: #16
I had no luck googling for Rosen's demo. Do you have any links? I'm curious to see...
Quote this message in a reply
dave05
Unregistered
 
Post: #17
thanks for all the explosion tips guys! I'm back with this explosion-drawing method, and I just have one concern. It seems that if the glBlendFunc is set to GL_ONE_MINUS_DST_COLOR, GL_ONE, it makes the actual explosion sprites look really good and fire-like, however the alpha set in glColor4f(r,g,b,a) seems to have no effect. this makes perfect sense, as the alpha is not mentioned whatsoever in either gl blend constant. So I ended up altering the r,g, and b of the coloring to attempt to fade in the explosions at the start, and fade out the explosions at the end. I have no real complaints about the fade-in, but my explosion fragments seem to "pop" out of existence when their frame count has expired, even though I smoothly reduce the rgb values to 0...

Code:
void    UI_DrawExplosions (void)
{
    int i;
    int facetNum;
    float fadeGB, fadeR;
    
    OGL_BindImage( particleImg );
    for (i=0; i<kMaxExplosions; i++) {
    if (explosion[i].fwState == fwState_firing) {
        
        fadeGB = (32.0f-explosion_fn[i]) / 32.0f;
        
        //if (explosion_fn[i] < 20)
            OGL_BlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE);
        
        for (facetNum=0; facetNum<16; facetNum++) {
        if (explosion_fn[i] < explosion[i].facet[facetNum].framecount) {
        
            if (explosion_fn[i] < 4)
                OGL_SetColor4f( 0.25f*explosion_fn[i] + 0.25f,fadeGB,fadeGB, 1 );
            else if (explosion_fn[i] < explosion[i].facet[facetNum].framecount-16)
                OGL_SetColor4f( 1,fadeGB,fadeGB,1 );
            else if (explosion_fn[i] < explosion[i].facet[facetNum].framecount)
            {
                fadeR = (explosion[i].facet[facetNum].framecount - explosion_fn[i]) / 16.0f;
                OGL_SetColor4f( fadeR,fadeGB,fadeGB,1);
            }
            else continue;
            
            /*if (facetNum<5)
                OGL_DrawParticleInRectWithOriginRotation( particle_ice, UI_GetFWRectForExplosion(i),
                enemy[i].x_position + explosion[i].facet[facetNum].x_position,
                enemy[i].y_position + explosion[i].facet[facetNum].y_position,
                explosion[i].facet[facetNum].rotation );
            else if (facetNum<9)
                OGL_DrawParticleInRectWithOriginRotation( particle_smoke, UI_GetFWRectForExplosion(i),
                enemy[i].x_position + explosion[i].facet[facetNum].x_position,
                enemy[i].y_position + explosion[i].facet[facetNum].y_position,
                explosion[i].facet[facetNum].rotation );
            else*/
            OGL_DrawParticleInRectWithOriginRotation( particle_fire, UI_GetFWRectForExplosion(i),
                enemy[i].x_position + explosion[i].facet[facetNum].x_position,
                enemy[i].y_position + explosion[i].facet[facetNum].y_position,
                explosion[i].facet[facetNum].rotation );
        }}
    }}
    OGL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

also, I need to learn how to load all these vertices into a VAR, since I'm beginning to lose frame rate once i get multiple explosions on the screen. If anyone has any good resources for glBindVertexArrayRangeAPPLE or whatever, Let me know.

Thanks again, this forum is super-helpful. I will post some screens once I implement window-mode, because i get crazy interlaced madness when i try to capture in full screen mode.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #18
I'd suggest using VBO rather than VAR. It's cross-platform and a lot easier to use.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [SOLVED]OpenGL edges of textures mk12 2 4,370 Sep 2, 2010 08:07 PM
Last Post: mk12
  OpenGL Image Textures mikey 52 24,339 Jun 30, 2009 10:42 AM
Last Post: AnotherJake
  Dealing with inverted textures in OpenGL johncmurphy 7 6,986 Jun 15, 2009 08:11 AM
Last Post: Skorche
  Using textures OpenGL switches to software renderer bruno 2 3,542 Oct 12, 2008 03:06 AM
Last Post: bruno
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 6,140 Dec 8, 2007 02:06 PM
Last Post: Malarkey