Hardware alpha blending with Direct Draw

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Hardware alpha blending with Direct Draw

      Hi,
      I'w writing a simple side scrolling game using the Direct Draw 7 library.
      I would like to know if there is a way to implement the alpha blending blitting using some DD function (hardware).I wrote a software alpha blending function
      but when I use it I need to lock/unlock the sufaces with a resulting decrease in the fps of the game especially in older machines.
      Thanks in advance.
      LuckyLuke
    • RE: Hardware alpha blending with Direct Draw

      Have you read LaMothe's "Tricks of the Windows Game Programming Gurus"? I seem to remember him going over it (its essentially a book on DirectDraw). When I get home I'll see if I can find it and post a solution for you (if it is in fact in there)
      -Larrik Jaerico

      www.LarrikJ.com
    • RE: Hardware alpha blending with Direct Draw

      Okay, since I'm not going sit here and type out huge sections 300 pages deep into a book, I'll just say this.

      You can use:
      IDIRECTDRAWSURFACE7::Blt() or
      IDIRECTDRAWSURFACE7::BltFast().

      The last parameter in Blt() is a struct called a DDBltFx, which is a hulking mass of a structure, and will probably let you do anything with the blitter that you can ever think of (including all types of transparency).

      BltFast, not surprisingly, has a much easier prototype, with a simple DWORD paramter for the type of transparancy, which can be DDBLTFAST_SRCCOLORKEY, DDBLTFAST_DESTCOLORKEY (which you probably won't use), DDBLTFAST_NOCOLORKEY, and DDBLTFAST_WAIT. BltFast is probably what you want, but it does NOT support clipping.

      I'm sorry I haven't given you something you can just drop in there, but you know the function names now, and can look them up in the docs easily.
      -Larrik Jaerico

      www.LarrikJ.com
    • RE: Hardware alpha blending with Direct Draw

      Um...unfortunately there's no hardware alpha blending in DirectX7 - it was never implemented, and you'd have to do it completely in software like I show in the book with the CopyAlpha() method.

      If you are feeling adventurous, I'd suggest you rip out the core of your 2D routines and replace them with 3D routines, and you'll get all the hardware alpha you need. But beware - you're game will require a 3D card, and you may need to change your 2D sprites to accomodate 3D texture dimensions. It could be a lot of work, and you may find some hardware incompatibility as well - so don't do this unless you have a good 3D coder to handle it.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • RE: Hardware alpha blending with Direct Draw

      Well - you weren't 100% completely wrong - in DirectDraw you can use the hardware to do color key blits in hardware - wihich lets you define a sprite with completely transparent pieces.

      If you want to have a percentage of opactiy - so that bits of a sprite are opaque and other bits are transparent and other bits are somewhere in between, you have to either blend it yourself in software, like you suggested, or use Direct3D and use the alpha channel of a texture map on a polygon drawn on top of all the other polygons. That's the only way DirectX can draw hardware accelerated alpha blended objects.

      The annoying part - is that the hooks have always been there to make this work, but no one at Microsoft or the video card manufacturers thought it was important to expose it.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • RE: Hardware alpha blending with Direct Draw

      Many thanks!
      I saw the CopyAlpha() procedure in the book and it is very similar to the procedure that I wrote myself.
      The problem is the locking of the surfaces that makes the fps of the game go down on older machines even if I use the triple buffering.
      When I began writing my 2D graphics library, I decided to use DirectDraw because I saw all that beatifull flags relating to alpha blending,dest color keying and so on, but now I know that only few of them works.In addition, some flags are supported only by a few cards.
      Rewriting the engine from scratch using D3D is a lot of work and I've no time to do it, so I've decided not to implement alpha blending at all.For my next game I'm going to learn a 3d API and I dont't know if I'll choose OpenGL or Direct 3D.I'm afraid the D3D is full of not-working flags like Direct Draw.Is OpenGL a cleaner library?What do you suggest?

      Thanks in advance.
      LuckyLuke
    • RE: Hardware alpha blending with Direct Draw

      OpenGL vs. Direct3D is a huge debate and filled with "religious" pitfalls. There's no 100% perfect answer - but if it's a PC game I'd suck it up and go Direct3D.

      Let the flame war begin!!!!
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • Everything I've read, OpenGL and Direct3D are pretty much comparable to each other in terms of available features and performance. OpenGL is a state-based procedural way of doing 3D graphics, whereas with Direct3D, you work through COM objects which gives it a more OOP feel to it. I guess if you are more comfortable with a more C-ish procedural feel, you might want to go with OpenGL, or if you are more comfortable with something that has a little more C++ OOP feel to it, you would go with Direct3D. For me personally, however, it wasn't a big issue to me whether the API was more procedural or more object oriented.

      I would probably argue that Direct3D has more support "out of the box" than OpenGL. Reason I say this is because Microsoft only ships version 1.1 of the OpenGL library with Windows, and the latest version of OpenGL is version 1.5, which takes advantage of many of the features supported on modern video cards. You can still access post version 1.1 features through OpenGL's extension method, it's just a bit of a more roundabout way of getting there. Gamedev.net has an article that explains using OpenGL extensions.

      You'll also find many more well-written tutorials and examples using Direct3D, such as Drunken Hyena, andy pike, and even the DirectX SDK docs and samples (which are quite good). There's always NeHe's tutorial site when it comes to learning OpenGL, but I've never been really impressed with his tutorials. For one, some are pretty outdated, many using the GLaux library, a deprecated library that you are strongly discouraged from using. You can also download the Red Book from OpenGL's website, which gives you a real good overview of OpenGL 1.1 (there's a OpenGL 1.5 Red Book out, but you have to buy that one ;))

      With that all said, I've decided to go with OpenGL, mainly because it's portable, and I'm trying to reach as wide an audience as possible with this latest game I'm currently working on. In the end, I would say that it's just best to pick one and learn how to use it well. Later on you can always learn the other, as I don't think core concepts change between the two.

      The post was edited 2 times, last by MRom ().