Sign in to follow this  

UI Sprite

This topic is 4305 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 am trying to open a sprite in UI.

// in init function


g_SampleUI.SetCallback( OnGUIEvent ); int iY = 5;
g_SampleUI.AddButton( IDC_BUTTN, L"Button", 400, iY, 70, 22 );
    

int nSprite = g_DialogResourceManager.AddTexture(L"Masa.jpg");
CDXUTElement element;
RECT r;
SetRect(&r, 0, 0, 200, 200);
element.SetTexture(nSprite, &r);
g_SampleUI.DrawSprite(&element,&r);


IDC_BUTTN is working well but i can't see the sprinte in the window.Where am i doing wrong ? Do you have any idea about it ?

Share this post


Link to post
Share on other sites
debug step by step, and you'll notive that if the alpha of the element's texture color is 0, the sprite is not rendered.

so

element.TextureColor.Current.a = 1.0f
element.TextureColor.Current.r = 1.0f
...

should help.

Share this post


Link to post
Share on other sites
Oh, I didn't fully understand what you wrote.

It won't work because the sprite starts on the beginning of the Render method of the CDXUTDialog, and ends at the end of the same method.

So when you call CDXUTDialog::DrawSprite from anywhere but inside the Render method of the dialog, it's not inside the ID3DXSprite::Begin / ID3DXSprite::end pair, and it won't draw (turning DirectX runtime to Debug would show a waring / error in the Visual output)

If you want to add a sprite, one solution that I would recommend is to create a new control. You can take the CDXUTStatic class as an example. Duplicate it, change its name, get rid of all the stuff you don't need, and add the AddSprite(), GetSprite(), etc. method to the CDXUTDialog.

And then, in the CDXUTSprite::Render() method, you will be able to draw a sprite with "m_pDialog->DrawSprite(...);"

Share this post


Link to post
Share on other sites

This topic is 4305 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.

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