C++ & DirectX: How to render lasers particles and explosions

I have a top down space game that uses DirectX and generic bitmaps.
When I want to draw a basic laser I do something like this:

Render::setRenderMode(Render::laserMode);
dxbb->drawLaser(x1,y1, x2,y2, width, color1|0xFF000000);

Where lasermode:
                  case (Render::laserMode):
                        device->SetRenderState(D3DRS_ALPHATESTENABLE, 1);
                        device->SetRenderState(D3DRS_ALPHABLENDENABLE, 1);
                        device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
                        device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
                        break;

And drawlaser:

void DxCanvas::drawLaser(int ix1, int iy1, int ix2,int iy2,int iwidth, D3DCOLOR color){
      int r = ((color & 0xFF0000) >> 16),
            g = ((color & 0xFF00) >> 8), b = (color & 0xFF);
      r = r/4 + 0xFF*3/4;
      g = g/4 + 0xFF*3/4;
      b = b/4 + 0xFF*3/4;
      if (r > 0xFF)
            r = 0xFF;
      if (g > 0xFF)
            g = 0xFF;
      if (b > 0xFF)
            b = 0xFF;
      D3DCOLOR outerColor = (color & 0xFFFFFF)|0x00000000;
      D3DCOLOR innerColor = (r << 16) | (g << 8) | (b) | (color & 0xFF000000);//color |0xFF000000;
      float x1 = (float)ix1;
      float x2 = (float)ix2;
      float y1 = (float)iy1;
      float y2 = (float)iy2;
      float width = (float)iwidth;
      float dx = x2-x1;
      float dy = y2-y1;
      float len = sqrt(dx*dx + dy*dy);
      if(len){
            dx /= len;
            dy /= len;
      }
      else
            return;
      dx *= width*0.5f;
      dy *= width*0.5f;
      float px = -dy;//perpendicular
      float py = dx;

      Render::setTexture(0);

      GLDraw::beginPrimitive(D3DPT_TRIANGLESTRIP);

      GLDraw::setColor(outerColor);
      GLDraw::vertex2f(x1 - dx, y1 - dy);

      GLDraw::setColor(innerColor);
      GLDraw::vertex2f(x1, y1);

      GLDraw::setColor(outerColor);
      GLDraw::vertex2f(x1 - px, y1 - py);

      GLDraw::setColor(innerColor);
      GLDraw::vertex2f(x1, y1);

      GLDraw::setColor(outerColor);
      GLDraw::vertex2f(x2 - px, y2 - py);

      GLDraw::setColor(innerColor);
      GLDraw::vertex2f(x2, y2);

      GLDraw::setColor(outerColor);
      GLDraw::vertex2f(x2 + dx, y2 + dy);

      GLDraw::setColor(innerColor);
      GLDraw::vertex2f(x2, y2);

      GLDraw::setColor(outerColor);
      GLDraw::vertex2f(x2 + px, y2 + py);

      GLDraw::setColor(innerColor);
      GLDraw::vertex2f(x2, y2);

      GLDraw::setColor(outerColor);
      GLDraw::vertex2f(x1 + px, y1 + py);

      GLDraw::setColor(innerColor);
      GLDraw::vertex2f(x1, y1);

      GLDraw::setColor(outerColor);
      GLDraw::vertex2f(x1 - dx, y1 - dy);

      GLDraw::setColor(innerColor);
      GLDraw::vertex2f(x1, y1);

      GLDraw::endPrimitive();
}


====

This draws a 'star wars' type laser, which overall does look good. However, it's basic. It's just shooting a line from your ship to the enemy ship, no particles around the laser or damage where the laser hits. So this was my first question, if theres a simple way to do this so it looks more 'pretty'

Another issue is explosions. I was wondering if there is a tutorial on how to design/add explosions using directx rendering instead of bitmaps as it currently is. I want it to look a bit more fancier since we added DirectX recently and bitmaps are pretty generic and eat up alot of resources when tons are being used at the same time.

Would anyone have any ideas/tutorials that I could read up, mainly to make explosions and use some sort of particle system for laser looks? Thanks!
LVL 7
VallerianiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

phoffric\Commented:
>> Another issue is explosions. I was wondering if there is a tutorial on how to design/add explosions using directx

Perhaps using particle effects you can get a nice explosion. You can download a DirectX Particle Demo with source code (so it says):
     http://www.elitecoder.com/particle.html

Also, see Tutorial 11 to learn how to use dynamic buffers to create a nice particle effect.
     http://www.chadvernon.com/blog/tutorials/directx9/
Looks like many other useful tutorials with source code as well.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
George TokasCommented:
The code you provided is using 2Dimentional rendering..
In this case explosion or particle rendering is just a matter of sprites rendered in the screen...
For an explotion use an image with frames of the explotion and render the frames when needed...
For particles its another story...
In this case you need some (more than one - maybe 3-4) buffers (sprites) and display them in a center based incremental distance...
In case of just explotion that is not required since you can made it with the frames of the explotion....
Take care because those functions consumes memory video or system...
Have in mind that in whatever format you use to store and load your pictures, when loaded there are converted in DIBs and that is a kind of bitmap...

George Tokas.
0
VallerianiAuthor Commented:
Thanks both!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.