Jump to content
  • Advertisement
Sign in to follow this  
pherik

Creating a GUI with Direct3D

This topic is 5148 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 create some sort of GUI in 2D using Direct3D for all it's features like hardware acceleration and alpha blending. I'm having a lot of trouble. I've got quite a lot of general Direct3D information, and 2D in Direct3D information but I'm having so much trouble handling all the small images that make up GUI elements in Direct3D with all it's limitations on texure sizes and other factors. Has anyone had any experience with this? I can't find anything on the net at all and I'm pulling my hair out trying to get D3D to draw a simple window frame using PNG files that contain all the elements. I could really do with talking to someone who has experience with 2D in Direct3D. I assume most modern, professional game GUIs use Direct3D (take Square Enix's PlayOnline Viewer for example). Am I right? Any help greatly appreciated. Many thanks, Daniel

Share this post


Link to post
Share on other sites
Advertisement
im doing the exact same thing right now: 2d gui in direct3d. im using dx8.

i havent had any problems loading jpgs, pngs, or bmps. i use pngs for 32 bit images and they seem to work very well. everything is texquad-based. lines, circles, windows, buttons, etc. resources are preloaded at startup, too. i load my textures up into a vector and whenever i want to texture a quad, i just pass it TextureVector[5] or something and it uses that texture.

make sure you have ur texquads down, complete with showing textures properly, setting position, rotation if needed, etc. then use them to make everything else. there are lots of examples on gamedev.net, but some worked for me and some didnt

another HUGE thing is that you have to have your texture stages set right or the quad will not be visible, or a flat color.

Share this post


Link to post
Share on other sites
I use ID3DXSprite to handle GUI drawing, but the doco is not so good. It took me a while to get stuff drawing at the right place on the screen with the right scale. As far as the power-of-two texture sizes are concerned my artist ensures the gui image files are power-of-two in size so that they don't get stretched/filtered by D3DXCreateTextureFromFileEx() to a power-of-two size when loading (because that just reduces quality). Whether multiple GUIs are packed into a single texture and how they're packed is up to the artist in my case. ID3DXSprite also takes care of batching for you - you call Begin() and then a number of Draw() calls and then End() will sort by texture (if that's the sorting criteria you've chosen) and render in batches.

Also the latest release of dx9 has a GUI but I've not tried it - I found out it was coming just after I finished implementing my own GUI - doh.

Share this post


Link to post
Share on other sites
Thanks for all the tips everyone.

I get the general ideas of how to do it, it's the actual details and code implementation that I'm having trouble with.

For example, everyone says the easiest way is to make your textures square sizes with square numbers. Ok, obviously all my GUI elements aren't going to be that size so how do I implement it all using only those texture sizes.

I think the kind of problems I'm having could only be solved by reading some rendering code or something to see it exactly how the textures, images, and quads all work together and how to write them to the screen.

Has anyone got any code they could give to me that I can have a look at?

Thanks,

Daniel

Share this post


Link to post
Share on other sites
Have a look in the DirectX forum. You should do a search for "Crazy Eddie's GUI", which I believe was open source. Might be helpful.

Cheers,
Dchavez.

Share this post


Link to post
Share on other sites
Also, you can check for a texture caps flag D3DPTEXTURECAPS_NONPOW2CONDITIONAL. This allows you to use non-power of 2 textures under certain conditions which basically 2D rendering pretty much meets. Alot more cards seem to have this flag, definitely the geforce FX series and radeons.

Share this post


Link to post
Share on other sites
Just because the textures are square doesn't mean the quad you render them to needs to be square. D3D will happily stretch, mangle, and resize the texture to fit into whatever you specify. Further D3DX's texture from file command likely will happily load non-square textures and fiddle with them so you don't need to worry about the square requirements [but don't quote me on that...]

Share this post


Link to post
Share on other sites
Thanks.

I think I'm starting to work out how to do this. I need to get my brain thinking textures and quads and not thinking about how to render pixel perfect data to the screen as in DirectDraw

Share this post


Link to post
Share on other sites
Quote:


Just because the textures are square doesn't mean the quad you render them to needs to be square. D3D will happily stretch, mangle, and resize the texture to fit into whatever you specify. Further D3DX's texture from file command likely will happily load non-square textures and fiddle with them so you don't need to worry about the square requirements [but don't quote me on that...]



Quoted :P

If I understand what you're saying, what I could do is (If indeed D3DX functions do support it) load a non square texture into a square texture object, which would automatically be stretched to fit, and then load it onto a quad which was the same size as the original image, there-by stretch it back down again to look right.

Do you think this is possible and would it mangle the image being processed like that?

Daniel

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!