Sign in to follow this  
Chrisz_6

Direct3D 9c, two questions

Recommended Posts

Chrisz_6    122
First question, ID3DXSprite. Totally changed in 9c. The 'scaling' vector is now gone, how do I make certain sprites larger or smaller? Second question, I was wondering if it is possible to use the renderstates to do alpha blending on certain conditions... for example when the alpha value is 255 (0xff) no blending is done, but when the value goes to less than 255 for example, 254 (0xfe) alpha blending would automatically take place. I've saw this done alot of times in other games im just having trouble recreating it without manual interferance. I also cant use if statements etc since im using an ID3DXSprite interface. Any help appreciated thanks :( Note: I have tried using D3DBLEND_SRCALPHA and D3DBLEND_INVSRCALPHA, that just changes the transparency gradually, which I dont want :(... D3DBLEND_SRCALPHA and D3DBLEND_DESTALPHA is the effect im trying to achieve.

Share this post


Link to post
Share on other sites
Permafried-    274
Chrisz_6,

As far as your first question goes, all I did was scaled my sprite using D3DXMatrixScaling and then called the ID3DXSprite::SetTransform( D3DXMATRIX mat ) method prior to calling it's Draw() method. This seemed to resize everything for me just as it would when scaling say a 1*1 vertex buffer.

As for your second question, are you refering to the alpha channel contained within the texture or some other color (which you pass to the draw method I believe)?

Permafried-

Share this post


Link to post
Share on other sites
Chrisz_6    122
Kinda yeah, the image may be a grayscale light texture for example, that will need to be drawn with alpha blending but it will also be drawn using an ID3DXSprite interface... So I cant just turn it on and off (Trying to be as optimized as possible...)

As for the matrix thing, I'll need to try that :D!

Share this post


Link to post
Share on other sites
Permafried-    274
I believe if you want to load the greyscale image if you were to pass it to draw first and then the image you want to blend it with (or vice-versa) I believe you should be able to acheieve the effect you want (unless it's all part of one texture of type .dds or something).

Calling ID3DXSprite::Begin( DWORD Flags ) sets a number of render states upon calling it all of which can be found here

MSDN ID3DXSprite::Begin.

You can pass a number of flags to it including one D3DXSPRITE_DONOTMODIFY_RENDERSTATE which tells it that you have setup the device to handle the correct rendering of the object....though I don't know if I'd recommend doing this unless you really have an in-depth understanding of what all the interface's methods do.

Check out the link and maybe it'll help point you in the right direction. If not, I'll look into it a little more when I get home from work where I'll have more time to do research ^_^.

Permafried-

Share this post


Link to post
Share on other sites
Chrisz_6    122
And i've been through all the flags - its not what I want. It involves using two calls to ID3DXSprite per frame, which I dont want. I want it all batched in one call, but where some sprites are blended. (I'm picky :P But its critical its all in the one call for speed reasons)

Share this post


Link to post
Share on other sites
Permafried-    274
I setup something like this between my Begin() and End() tags. I believe this works in world coordinates but I could be wrong. I haven't really used the interface all that often just played around with it here and there. Rather than mess around with it myself, here's a link to a nice tutorial to give you a general idea on how it works. One of the most important things to remember is that if your actual texture file you're loaing (example.png) is 128*128 (pixels) then calling D3DXScaling( &d3dmScale, 2.0f, 2.0f, 0.0f ); will result in a texture of 256*256 pixels.

Trip99's Sprite Tutorial

As far as wanting to batch them all as one call, I'll be dead honest and say I have no idea....though anything placed between Begin() and End() is cached and dumped out all at once upon the call to End() (not sure if you were aware of this or not though I'd assume yes ^_^)

Hopefull this helps you out ^_^.

Permafried-

Share this post


Link to post
Share on other sites
Chrisz_6    122
Wow. Interesting tutorial I have to say :D. I dont know much of the concepts to 3D yet.. matrices and such, since I only recently began using it, but heck learning fast :)

Share this post


Link to post
Share on other sites
Permafried-    274
DirectX just seems to work that way. Once you get past the first initial hurdle it starts to flow from there. My current project is my second game, the first being a 2D rail shooter involoving jets, but this one is going to be fully 3D. It seems one of the best ways to learn is experiement and see what you can come up with ^_^.

Best of luck,

Permafried-

Share this post


Link to post
Share on other sites
dhanji    192
You do not HAVE to call Begin() with DONOTMODIFY_RENDERSTATE to pass your own device states, this is an alternate (pseudocode):


Begin(D3DXSPRITE_ALPHABLEND)
SetRenderState( AlphaCompare Func )
Draw()
SetRenderState( restore alpha compare func, if needed )
Draw()
End() //restores device states to pre begin state


Quote:
And i've been through all the flags - its not what I want. It involves using two calls to ID3DXSprite per frame, which I dont want. I want it all batched in one call, but where some sprites are blended


When you call Draw() it basically batches the texture to be drawn. They are only actually drawn when you call Flush() or End(), which does it for you.

Quote:

Can you explain how i can use matrices to do the scaling on individual sprites??? Im lost and confused :(


psuedo:

D3DXMATRIX mat, oldMat;
sprite->GetTransform( &oldMat );
D3DXMatrixTransformation2D(...) //look in docs-easy enough to fill out
sprite->SetTransform( &mat );
sprite->Draw();
sprite->SetTransform( &oldMat ); //restore old transform (if need be)


note, the above will only work if you have not set WorldView transforms and are using sprites just for 2D (otherwise it may take some tweaking).

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