ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • MSDN question : Adding textures to CDXUTDialog
    정리필요2 2008. 7. 14. 16:30


    DXUT의  customUI의 지겨운 콘트롤 스타일을 입맛에 맞게 바꾸고 싶다.

    나와 같은 의문을 가진 사람이 MSDN에 질문을 했고, 친절하게 나쁘지 않은 답변도 달려있었다. ㅡㅡ;



    질문 :

    Hi.

    I'm trying to create an ingame GUI with the CDXUTDialog. There is a possibility to add custom textures to buttons, checkboxes, etc.

    If I add an texture, it isn't aligned correctly. Does anybody know how to add a texture that it looks correct?

    Cheers,
    Daniel





    대답 :


    I've mainly been reading the C# version of those classes, but it should work the same.

    They load textures using the CDXUTDialogResourceManager class:
    textureIndex = AddTexture(textureFilename);

    This loads the texture image into a list and returns an index which is basically a handle.

    When you want to add a texture to an object (like a button), they then use:
    SetTexture(textureIndex, location);

    - the textureIndex is same as above.
    - the location is a rectangle that represents a sub-region in the texture to use. This is so they can have multiple gui elements all stored in one image. To see an example, look at 'dxutcontrols.dds' in the SDK's Samples\Media\UI directory.


    So to answer your question, no you cant load images into rects - you load the image before that and use the rect to say which part of the image is which control.

    - Wyzfen




    대답의 대답 :
     

    Thanks for the comments, that all makes sense coneptually to me. I tried the following code and it didn't draw anything, do you have any suggestions?

    int tIndex = g_DialogResourceManager.AddTexture(L"frigate_picture.jpg");
    
    CDXUTElement ele;
    RECT r;
    SetRect(&r, 0, 0, 200, 200);
    ele.SetTexture(tIndex, &r);
    myRandomDialog.DrawSprite(&ele,&r);
    


     

    대답의 대답의 대답 :

    Have you called all the draw-initialisation code first ?
    In the library, theres a CDXUTDialog::OnRender() method that sets up the render state, enables sprite drawing and THEN starts getting each element to draw itself.

    Without seeing more of your code, thats my best guess; that you've not set up the drawing.


    In general, the method to use the library (from what i can see) is to make an instance of an object (Button etc) and add it to the dialog. The Dialog acts as a container for all your objects.
    The dialog then calls the render method.


    Have you had a look at the CustomUI sample ? (Samples\C++\Direct3D\CustomUI)
    It shows setting up a dialog (in InitApp) and the render routine, which just calls OnRender on your Dialog.


    - Wyzfen




    대답의 대답의 대답의 대답 :

    Yes, I actually have a fully functional UI using the CDXUT methods up and running. The UI has multiple dialogs, each one of which I've added statics and buttons to. I'm correctly handling the buttons to navigate around the UI, etc etc. I'm calling .OnRender() on all of my dialogs which is rendering them.

    I'm only having trouble using the DrawSprite because I'm not exactly sure how/what the CDXUTElements are. So I've got the UI working but there arent any examples in the DX Samples that I've seen that actually show any of the DrawSprites (or even DrawRect for that matter).

    In an InitGraphics function, I'm building my CDXUTDialog class which will hold my sprite to draw. I'm also then using the following code to add a Sprite to my dialog:

    int tIndex = g_DialogResourceManager.AddTexture(L"mypicture.jpg");
    CDXUTElement ele;
    RECT r;
    SetRect(&r, 0, 0, 200, 200);
    ele.SetTexture(tIndex, &r);
    myRandomDialog.DrawSprite(&ele,&r);
    



    Then in my OnFrameRender function, I'm calling myRandomDialog.OnRender( fElapsedTime ). I know the call to the FrameRender is working correctly because other elements of myRandomDialog, like buttons or statics, are drawing correctly.

    Perhaps DrawSprite needs to be called consantly, such that I should have another function called DrawSprites that is called by OnFrameRender, which each time goes through and calls myRandomDialog.DrawSprite(blah blah)? I tried this initially but it did not seem to work either.





    다른 이의 대답 :

    Every GUI element (CDXUTElement) has the method 'SetTexture' which takes a texture ID and a rectangular area to be linked with the element. When your dialog draws its elements it stretches their textures from source ('skin' by the default) to the target position. If the source rectangle has the size of the target rectangle, the drawn texture will apear in its original size. So You should make sure that the source rectangle in the CDXUTElement::SetTexture() method and the target rectangle (x, y, width, height) for the element have the same size.

    P. S. It may be better to change the skin 'Media\UI\dxutcontrols.dds' in most cases to keep the style over the game. But it greatly depends from the game. Also You can look at the file 'Common\DXUTgui.cpp' and find the essential code.


    다른이의 대답 :

    So did you manage to set the texture of the CDXUTButton.
    I have a problem with this.

    When I call the button->getElement(0)->SetTexture(UINT Id, Rect, Color)

    it seems I have problem with the UINT Id.

    I loaded before a png file in a LPDirect3DTexture9 with the LoadTextureFromFileEx function, but it displays nothing.



     

Designed by Tistory.