?
Solved

Alpha Blending

Posted on 2003-03-30
14
Medium Priority
?
871 Views
Last Modified: 2007-12-19
Hi,

I am writing a 2D RPG engine in VB with DirectDraw 7. I was wondering if there is any easy way to do Alpha Blending with certain tiles.

I have a custom format for my tiles, which is simply a bunch of Long's (ABGR) describing the 32x32 tile.

I would like to know how to do the alpha stuff, since DD7 doesn't support it.
0
Comment
Question by:pkmnfrk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +4
14 Comments
 
LVL 4

Expert Comment

by:joachimc
ID: 8237926
I am not using DD7 any more but I am sure that alpha is supported in it. Isn't there the example with a background pic and something flying in circles on it. That is alpha blended I think
0
 

Author Comment

by:pkmnfrk
ID: 8241248
No. It says in the SDK quite clearly that "the alpha channel will be ignored" and "alpha blending is not supported in this version".
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 8246616
But why are you using DirectDraw? It can't do anything you cannot do with Direct3D [or DirectXGraphics as it is known in DX8+], and the simplicity comes at a price, namely that DirectDraw isn't that well supported in modern graphics drivers anymore. The functionality is there, sure, but the performance just isn't since modern cards are more and more tweaked towards handling 3D data.

I would very much suggest saying good bye to the soon-to-be-forgotten DirectDraw interfaces and use Direct3D instead. You will have to learn about new concepts, but that's a Good Thing (tm) anyway.

.f
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Assisted Solution

by:tinkledoomhammer
tinkledoomhammer earned 150 total points
ID: 8250164
If you aren't trying to make a high-end game, no acceleration is needed and dx7 will work fine.
Actually, mmx technology is what your situation calls for.

If a high alpha means opaque, then just.
1. Multiply the rgb values in each layer by the alpha.
2. Divide by the maximum alpha.
3. Add each layer together.

If you want a high alpha to mean transparent, then just divide each r,g, and b by the corresponding alpha.

This example assumes that your bitmaps are in 4 arrays:
source_a[layer,col,row]
source_r[layer,col,row]
etc

FOR x=1 to width
  FOR y=1 to height
    final_r[x,y]=0
    final_g[x,y]=0
    final_b[x,y]=0
    FOR z=1 to numberOfLayers
      final_r[x,y]=final_r+source_r[z,x,y]/source_a[z,x,y]
      final_g[x,y]=final_g+source_g[z,x,y]/source_a[z,x,y]
      ...
    ...
  ...
...

My basic is a little rusty, so I will appologize in advance for any errors.

There are a few optomizations that would make it a bit faster, but the internal VB optomizations should be more than sufficient. Code like that tends be compiled to do several pixels or the entire triplets with a single machine-language command. If you set it to comple for pentium pro, pentium 2, or later. If it there is a check box for MMX, use it.
0
 

Expert Comment

by:tinkledoomhammer
ID: 8250183
One more thing:
If you don't need a lot of different shades of transparency (no fade-ins or -outs) then a binary shift would speed it up a little.
0
 

Author Comment

by:pkmnfrk
ID: 8250314
Hmm, I'll try your suggestion and see what I can do. I never really thought about approaching it from that angle. I'll try it before I award the points, though.
0
 
LVL 8

Accepted Solution

by:
fl0yd earned 150 total points
ID: 8251938
While SIMD [MMX/SSE/...] would be the way to go for a software render kernel, it involves a steep learning curve. I doubt that you will be able to access those CPU features through Visual Basic calls to start with. Again, I would suggest using Direct3D. Check out this link http://www.directx4vb.com/ to see how easy it actually is. Except for the setup code you will hardly have to change anything in your current project. Follow the DirectX 8 links, to get 27 introductory tutorials. There's also a DX7 section, but I haven't looked into it. I may also provide helpful information to you.

.f
0
 
LVL 1

Expert Comment

by:red_sodium
ID: 8470395
When you say D3D can do everything DD can do and much more, which I truly believe, could i make a 2D sprite engine with it? And would I be able to use rotation, scaling, alphablending, etc, all in it? And how much would I need to know about maths?
0
 

Author Comment

by:pkmnfrk
ID: 8484237
I've tried D3D and for some reason, I can't get it to work. (I'm probably not setting the geometry correctly)

Anyway, I found an easy solution for my project: scrap the alpha for now. I'll do it later, after I have SOMETHING ready for the public. <sigh>
0
 

Expert Comment

by:BAGR
ID: 8860717
If there is no way to create fast alpha blending in DirectDraw, so why some games, for example Jazz Jackrabbit 2, have it? And why this game runs on Pentium 90 ???!!!  :P
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 8870875
BAGR:

* I never claimed there wasn't a way to do fast alpha blending -- SIMD instruction sets are damn fast
* While there may not be alphablending, there certainly is colorkeying-support in DirectDraw -- that's what sprites in general use
* Jazz Jackrabbit 2 is old -- back in those days Direct3D was a _lot_ more computationally expensive

Anything else you have to add?

.f
0
 
LVL 1

Expert Comment

by:red_sodium
ID: 8871544
I've now converted to D3D, and I can safely say that as long as you use LPD3DXSPRITEs, its great. Alpha blending is really easy too, you just set the Alpha channel when calling Draw function.
0
 

Expert Comment

by:CleanupPing
ID: 9464232
pkmnfrk:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 9464663
Question was fully answered, both in a software- as well as hardware-approach. I suggest splitting points between tinkledoomhammer and me [fl0yd].

.f
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question