Jump to content
  • Advertisement
Sign in to follow this  

Multiple objects on map, how to achieve that?

This topic is 5151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Good day folks, I am writing a strategy game and I have a directx9 programming scenario here. I would like achieve 1)Put a tile on the map. The tiles arent rectangles in my game. There are part of my tile texture has black color which will become transparent in alpha blending so that tiles can join together nicely. 2)put a castle(or other map structure) on the tile. Again, the castle texture has black color which will become transparent in alpha blending so that only the castle shows and not the black part of texture. 3)put a unit on top of castle. Same requiement here. My code is like this p3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); p3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); p3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); DrawTile(...); // basically draw vertices DrawCastle(...); DrawUnit(...); The result is unit blends into castle then blends into tile. That isnt really what I want. What I would like to achieve is black becomes transparent and other keeps whatever color it is. A bit like: p3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); p3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO); Except the texture black color over writes the destination texture. I have tried a few combination of blendings here but still cant achieve what I want. Any help is appreciated Cheers

Share this post

Link to post
Share on other sites
You must make black become transparent yourself, and for this you must give it an alpha of 0. There are several ways to do this:

- Load the image from a file that contains an alpha channel (such as Targa .tga), and set the alpha channel to 0 for the black areas.
- Load the image from a bitmap file, and use a loading function that takes a colorkey and makes all pixels of that color transparent (just choose black).
- Create your own loader, that sets an alpha of 255 for all pixels, except black pixels, which receive an alpha of 0, by creating a texture, getting its surface, and editing the raw byte data after reading them from a file.

Once your alpha has been loaded, you can use either:
if you only want your pixels to be fully transparent or fully opaque, or:
if you want to have multiple levels of transparency for your pixels.

In any case, don't forget to activate *alpha testing*, which will discard pixels if their alpha is too small (they become transparent).

Share this post

Link to post
Share on other sites
Thanks ToohrVyk.

I think you are right that my problem lies in the texture loading. My code is like this:

hResult = D3DXCreateTextureFromFileEx(m_pD3DDevice, "image\\grassland.bmp",

I have tried using different color key eg 0xFF000000. What should I use in my case to make black transparent. I also suspect that the black in my bitmap may not be "real". Are there any free graphic tool that I can use to check the color value.
Sorry for newbish questions. I am an experience programmer but just starting on the graphic programming.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!