Jump to content
  • Advertisement
Sign in to follow this  
VitaliBR

ID3DXSprite and SetTransform

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

I'm trying to apply a sprite as background (Menu).

I have the window size:
#define WIDTH 800
#define HEIGHT 600

and I'm trying this way:

	D3DXMATRIX m;
D3DXMatrixScaling(&m, WIDTH / (float)1024, HEIGHT / (float)768, 1);
m_Sprite->SetTransform(&m);
m_Sprite->Draw(m_Texture, NULL, NULL, &position, D3DCOLOR_XRGB(255,255,255));




My sprite is the size 1024x768 and window 800x600
but the sprite is not getting the exact size of the screen :(

Look:

The sprite:



The screen with sprite:



I searched on the forum, but have not found the solution
Thanks

[Edited by - VitaliBR on September 28, 2010 8:15:58 PM]

Share this post


Link to post
Share on other sites
Advertisement
In your image the background is correctly scaled on the X-axis, but doesn't seem scaled at all on the Y-axis. Double-check that your parameters are correct.

Also, you should use AdjustWindowRectEx to calculate the window-size when creating your window. If you create the window with size 800x600, then the actual draw-area is smaller, since the window's title-bar and borders are included in the size. However I don't think this is your current problem, as the sprite doesn't seem scaled at all on the Y-axis.

Share this post


Link to post
Share on other sites
Hi,

I'm workin' on D3DX Sprite too :D

You must use D3DXMatrixTransformation2D() instead of D3DXMatrixScaling(). That's the trick ;)

First;
* Create your texture from file via D3DXCreateTextureFromFile().
* Get it's level-0 description: IDirect3DTexture9::GetLevelDesc(). And get width and height data from it.
* Get your window size. With this and the data came from the previous step, get scaling factor via
D3DXVECTOR2 scalingFactor ((float)windowW / (float)textureW, (float)windowH / (float)textureH);


Second;
* Call D3DXMatrixTransformation2D:
D3DXMATRIX spriteMatrix;
D3DXMatrixTransformation2D (&spriteMatrix, NULL, 0, &scalingFactor, NULL, 0, NULL);

* Call ID3DXSprite::SetTransform:
yourD3DXSprite->SetTransform (&spriteMatrix);


Third, and the last;
* Draw it:
yourD3DXSprite->Draw (yourSpriteTexture, NULL, NULL, NULL, D3DXCOLOR (1, 1, 1, 1));


Excellent bg image, btw ;)

hth.
-R

Share this post


Link to post
Share on other sites
Look this friend :D



Thanks for help!
What filters can I use to make better the quality of the sprite?

Quote:
Original post by programci_84

Excellent bg image, btw ;)



Thanks, I'm not a designer :( I tried to do my best!


My blog of Project:
mateusvitali.wordpress.com

Share this post


Link to post
Share on other sites
You can use linear filtering:


yourD3DDevice->SetSamplerState (0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
yourD3DDevice->SetSamplerState (0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
yourD3DDevice->SetSamplerState (0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);


I've heard that anisotropic filtering (i.e. D3DTEXF_ANISOTROPIC) is better but you've to check the max. anisotropy level that driver/gpu work with.

Share this post


Link to post
Share on other sites
Quote:
Original post by programci_84
You can use linear filtering:


yourD3DDevice->SetSamplerState (0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
yourD3DDevice->SetSamplerState (0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
yourD3DDevice->SetSamplerState (0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);


I've heard that anisotropic filtering (i.e. D3DTEXF_ANISOTROPIC) is better but you've to check the max. anisotropy level that driver/gpu work with.
ID3DXSprite will already use bilinear filtering, or anistropic if it's available. Trilinear (linear mip filter) is redundant since sprites shouldn't have more than one mip level.

Share this post


Link to post
Share on other sites
Quote:
ID3DXSprite will already use bilinear filtering, or anistropic if it's available.


I belive it can be true, but I'm working with D3DX Sprite in 3D Space (e.g. flame, smoke, explosion effects etc.). If I don't use any of filtering operations before calling ID3DXSprite::Draw(), it looks like an image built by colored little squares.

I don't know the results in screen space like Vitali's example.

I'm using ATi HD4890, btw.

Quote:
Trilinear (linear mip filter) is redundant since sprites shouldn't have more than one mip level.

Ah yes, I missed it. You're right.

Thanks for correcting me, Steve.

Share this post


Link to post
Share on other sites
Quote:
Original post by programci_84
I belive it can be true, but I'm working with D3DX Sprite in 3D Space (e.g. flame, smoke, explosion effects etc.). If I don't use any of filtering operations before calling ID3DXSprite::Draw(), it looks like an image built by colored little squares.
If you pass the D3DXSPRITE_DONOTMODIFY_RENDERSTATE flag to ID3DXSprite::Begin(), it won't set change the sampler state (Among other things), which would mean it'll be using whatever the device has set, which is point (nearest neighbour) by default.

As for making it look better - so long as you have scaling going on, there's always going to be some blurring or jagged edges. How about not scaling the background, but splitting it into multiple pieces (I.e. title, gun logo and each menu option), and then positioning them based on the resolution, but not scaling them?

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!