Sign in to follow this  
hoogie

sprite creation for DirectX

Recommended Posts

Hi, I am currently working on a group project at University making a 2D game for DirectX, basically I have to let the artists know how to create the sprite graphics and as I usually get free sprites I have no idea of the creation process. How exactly is an Alpha colour (the see through colour) set for the backround of the sprite template? Also how many sprite templates should a project use? I figure I want as few as possible to avoid constant texture loading but I assume I cant get all sprite graphics into the same template file? Thanks for any suggestions

Share this post


Link to post
Share on other sites
Are you using the D3DXSprite interfaces? Even if you are you may pick up some hints here.

As far as alpha,if you are using non-alpha image formats (like .bmp or .jpg) you can either lock the texture's surface and set it yourself, pixel by pixel, or you can use D3DXCreateTextureFromFileEx() and supply the color that will be set to transparent black. After that, set the alpha testing renderstates like so:

d3dDevice->SetRenderState(D3DRS_ALPHATESTENABLED,TRUE);
d3dDevice->SetRenderState(D3DRS_ALPHAFUNC,D3DCMP_GREATEREQUAL);
d3dDevice->SetRenderState(D3DRS_ALPHAREF,(DWORD)0x08);


Basically what this does is determine if each pixel being rendered is above or below the target alpha value, if it is below (in this case the target is 0x08) the pixel is not rendered. All you have to do is make sure the pixels you want masked out have an alpha value less than the text value.



As for sprite templates, that was the biggest difficulty I faced when converting from DirectDraw to DirectGraphics. Most video cards have certain requirements that the textures must abide by. Some cards need square textures, some need textures with sizes that are powers of two. All cards have maximum limits for the size.

Your best bet is to try creating sprite templates that fit as many images onto textures of 256x256 dimensions. Textures of this size are very fast, and guaranteed to work only nearly any card made in the last ten years.


Hope this stuff helps =)

Share this post


Link to post
Share on other sites
Hi,

Currently I am simply using the following commands to draw sprites :

m_sprite->Begin(D3DXSPRITE_ALPHABLEND);
m_sprite->Draw(m_texture, &spriteRect, NULL, &pos, 0xFFFFFFFF);
m_sprite->End();

When loading a sprite most sprites they have no surrounding colours. I make none of the SetRenderState calls you described, is there any reason why it works anyway?

P.S. How do you get those nice white backrounds to add source code into?

Share this post


Link to post
Share on other sites
What exactly IS working, the color keying?

I never use the D3DXSprite interface so I'm not all that familiar with it. My guess is the loading interfacee do some color formating or you are using an image format that supports alpha (like .png); and the Begin() method sets up all the render-states for you, using parameters passed to it.

RE: P.S.
Use the tags describe on the "faq" page. The link should be at the top of this page =)
Forum FAQ

Share this post


Link to post
Share on other sites
Hi,

Forget locking the texture just to fill the alpha channel as it will give you unexpected results.

Better, get Photoshop (or Gimp or PaintShop) and manually edit the alpha channel of your texture. It is very easy once you learn how to do it and you control just thexact ammount of transparency. Once you get ir, forget those jagged edges.

After that, save the texture in any format that supports alpha like TGA or DXTn (the latter is better for production, TGA is good for development).

You can load a TGA directly from DX using the D3DXTexture interface. You are ready for very impressive effects, with 256 levels of alpha.

Luck!
Guimo




Share this post


Link to post
Share on other sites
I was planning on using DDS files as I have heard they are the best, I take it these also support alpha values at creation stage so they are already setup as soon as they are loaded into DirectX?
Also what software is used to create DDS files? Do people mainly use exporters?

Share this post


Link to post
Share on other sites
Quote:
Original post by hoogie
I was planning on using DDS files as I have heard they are the best, I take it these also support alpha values at creation stage so they are already setup as soon as they are loaded into DirectX?
Also what software is used to create DDS files? Do people mainly use exporters?


DDS files can store a wide range of formats. Some of these formats store alpha, some don't. Some are compressed in a lossy format. There are a LOT of options.

Generally I'd recommend authoring them in a "normal" format like a PNG. Then you can use (free) tools from ATI and/or NVIDIA to convert them to DDS.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this