Jump to content
  • Advertisement
Sign in to follow this  
timeshifter

DX9 and PNG images/sprites?

This topic is 3780 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

Firstly, I'm fairly new to the world of DirectX.. I'm working on a Breakout game right now, and it's working surprisingly well. I have it limited at about 60fps, and it appears to be very smooth. I'm also working with C# 2008, but targetted for the .NET 2.0 framework. Now for the actual questions, of which I have two: 1) GIF Transparency. Can it be done? I'm using the Sprite class to do my drawing, and it doesn't seem to draw transparencies very well... and by not very well, I mean not at all. Is there a property that needs to be set for the Sprite object for it to understand transparency? 2) GIF Animations. Can they be done with a standard animated GIF? Or am I stuck to using the actual Sprite mentality of said class? If so, how? Thanks in advance, and slick forum you guys got here! [Edited by - timeshifter on February 15, 2008 4:27:42 PM]

Share this post


Link to post
Share on other sites
Advertisement
a) GIF Transparency is not supported in the sense that it will not automatically work. It will merely show the color you've chosen to be transparent (as you've seen). The obvious solution to this is when loading your texture to specify the COLORKEY parameter to be the same color as your GIF image. This will cause the color to become transparent when you render it with Alpha Blending enabled.

b) GIF animations are not supported in any way. Attempting to load an animated GIF would be the same as loading it into most image editors -- you'll only see the first frame. Your best bet is to roll your own animation class.

You're better off just using the PNG or TGA file format anyway, as they support 32 bit color, with various levels of alpha blending.

Share this post


Link to post
Share on other sites
You'll have to handle animation yourself, I'm afraid. The typical way of doing this is to use the ID3DXSprite interface, and load a texture that has all of your animation frames in one row. Then you loop through your frames by specifying a source rectangle when rendering. I could show you code in C++, but I don't know C# I'm afraid.

Share this post


Link to post
Share on other sites
It can be done, but you have to load them with GDI+ and then create a texture and draw all the frames to it(or just create one texture per frame). This tends to use up quite a lot of memory, thus defeating the whole point of the GIF format to begin with, so I would suggest using something like PNG or DDS.

If you're interested I wrote a journal post along with the C#/MDX code to do it here. If the link doesn't work, it's from August 7th, 2006.

Share this post


Link to post
Share on other sites
I recieved this when clicking your link:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CLng'

/community/forums/mod/journal/journal.asp, line 224




Besides that, the animations have kinda fallen aside... not a big priority anymore. The real thing I want to get working is the transparencies... having fragments of bricks fall over other bricks with black backgrounds in the fragment image isn't very appealing...

Another thing, if anybody knows a decently easy way, would be sprite rotation... in following Intellisense, it does SOMETHING, but it's not what it seems like it should... I'll post code later if anyone wants to see what I've tried that doesn't work.

Share this post


Link to post
Share on other sites
Quote:
Original post by timeshifter
I recieved this when clicking your link
Corrected link

As for the rest of your question, how are you using sprites at the moment? Are you rendering quads in screen space, or are you using ID3DXSprite (Or whatever it's called in C#)?

Share this post


Link to post
Share on other sites
@FlimFlam:
I did change to PNG's, and they do have alpha transparency. A bit of poking around with a program I found online and I found two lines that enable the transparency:
device.RenderState.AlphaBlendEnable = true;
device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.BothInvSourceAlpha;

Looks great, too.

@Evil Steve:
I'm using the Microsoft.DirectX.Direct3D.Sprite class, and as far as I can tell, it's drawing the sprite straight to the device using Textures that I load in at the start of the app.

Share this post


Link to post
Share on other sites
Quote:
Original post by timeshifter
device.RenderState.AlphaBlendEnable = true;
device.RenderState.DestinationBlend = Microsoft.DirectX.Direct3D.Blend.BothInvSourceAlpha;


If you just want transparency and not blending, your performance might be better using alpha testing.

Device.RenderState.AlphaTestEnable = true;
Device.RenderState.AlphaFunction = Direct3D.Compare.Greater;

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!