Sign in to follow this  

GUI in directx - online resources?

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

Hello, I am still toying with the idea of building my own GUI for my game. I was hoping to avoid it, due to the extra work, but have not had much success with existing GUIs out there. I tried the customUI SDK sample, but thats VERY slow, and dabbled with Crazy Eddies GUI, but it's very complex. Are there any others I could play with, or any advice online or books about how to go about this? At lease by doing my own, I could produce something original.... :) Many thanks Simon

Share this post


Link to post
Share on other sites
Either you use "complex" GUIs like CrazeEddie or you go and make your own (like the majority) which will start simple and easy, but at the end it will also be "complex" and you will notice it ate lots of your time.
This is what happend to me ;)
One advantage of your own GUI is that it will perfectly fit into your game/app.

Share this post


Link to post
Share on other sites
Can I ask -

Are the controls in your GUI entirely 'home made', or can you inherit some functionality from windows controls?

How do you go about structuring it? Are you continually checking the mouse position against all the visible controls?

I already have raytracing working for 3d objects in game - can I just use this for my GUI objects as well? Or should I just keep them in screen space?

Thanks for geting me started!

Si

Share this post


Link to post
Share on other sites
Personally, I don't like CEGUI all that much. I've used it for one of my projects and I think that will be enough. It's rather easy to learn, but I dislike the use of singletons. It makes tracking down memory leaks harder. I like singletons in general, but one or two of em is quite enough.

I think i'll write my own GUI lib...sometime. =)

Share this post


Link to post
Share on other sites
Quote:
Original post by publicmmi
but at the end it will also be "complex" and you will notice it ate lots of your time.
Yeah, I agree - writing a GUI system has a tendency to "snow ball" and just get bigger-and-bigger-and-bigger [oh]

BUT it was a great learning exercise. Not so much for graphics/DirectX but more for OOP concepts and code construction. I made a few decisions early on that seemed to make sense but later came back to cause me a lot of trouble. Nothing like learning from your own mistakes [lol]

Quote:
can you inherit some functionality from windows controls?
I don't think you'll be able to do this. Or, rather, if you could you'd probably end up with some fugly code that has lots of restrictions - to the extent that it probably won't be much better than what you'd have if you rolled it all yourself!

Quote:
Are you continually checking the mouse position against all the visible controls?
You will find it's both easier to code and faster to execute if you design some sort of heirarchical system:

if( Mouse is in window )
Check_All_Frames
if( Mouse is in frame )
Check_All_Controls_In_Frame


That way if it fails one of the early tests you won't need to test any of the objects it contains...

Quote:
Or should I just keep them in screen space?
Screen space is probably easier (unless you specifically hate the mapping texels to pixels thing [grin]), but putting it into projection space (or world space with an orthogonal projection) allows you to apply vertex shaders and other hardware transforms - which can be a pretty neat feature [wink]

hth
Jack

Share this post


Link to post
Share on other sites
there's some pretty good tutorials on gui design here:
http://www.c-unit.com/tutorials/mdirectx/
tutorials 23-26 (managed c# though)

this is what i started with. it does have it's problems, it's not very fast for one. but it's a good starting point, and there are plenty of optimizations to be made.

hth,
n.

Share this post


Link to post
Share on other sites
Quote:
You will find it's both easier to code and faster to execute if you design some sort of heirarchical system:

if( Mouse is in window )
Check_All_Frames
if( Mouse is in frame )
Check_All_Controls_In_Frame


That way if it fails one of the early tests you won't need to test any of the objects it contains...


Yes, I imagined I might implement a heirachy, even a offshoot of my terrain quadtree....

Quote:
putting it into projection space (or world space with an orthogonal projection) allows you to apply vertex shaders and other hardware transforms - which can be a pretty neat feature [wink]

hth
Jack


Hardware shaders are definately part of the attraction of producing my own implementation.


...............

To confirm - the best way to keep the speed up is to keep all components from one or two textures. One is a static one, with all the unchanging elements, the second is a dynamic texture rendertarget, used to draw occasionally, then reused frame to frame. This textureis redrawn when something changes.

Really dynamic stuff is just drawn straight to screen, without using the render target.

What do you think?

Si

Share this post


Link to post
Share on other sites
You could also try the GUI which is given in the DirectX SDK.
It's quite easy to understand, you have almost anything that you'll need, and adding a new control is quite straightforward (I added a tree view control recently, took me half a day or so)

So I think it would be a good idea to look at that sample. It will give you a good start, and you'll probably learn a few things that will help you.

Share this post


Link to post
Share on other sites
I've written a GUI and while its not the best or the most effecient, it can give you another idea.

my website

Go to the BX libraries and download one of the examples to get a feel for the GUI and then decide if its worth checking out. Source code provided.

Share this post


Link to post
Share on other sites
The other week, I rolled my own (we wanted to step up the quality of our samples). To be honest, it really wasn't that difficult (nor did it involve much development time). The hardest part for me was making art that looked good [grin] I only did the controls that we needed - message box, tooltip, label, button, image button (these are nice, they rollout like menus), context menu, checkbox, and slider. Basically, what I went for was to make it as close to C# as possible.

Anyhow, I did figure out something cool. C++ function pointers are pretty dang inflexible, so it is hard to do a good event-handling model. The problem is that it is hard to cast and manipulate them (I guess for good reason, it totally breaks type saftey hehe). For example, being able to do something like this:


typedef void (Resource::*MemberFncPtr)(void);

// Our 'Add Handler to event function'
Control::AddEventHandler( MemberFncPtr fncPtr );

// Then add an event handler from a function with this signature:
void MyCheckBoxHandler( bool isChecked );


However, I was looking at MFC source and they do a nice hack. What you do is make a union of function pointers, including all of your different signatures. Like this:


union MemberFunction
{
MemberFncPtr fncPtr;

// Our handlers
void (Resource::*fpNone) (Resource*);
void (Resource::*fpBool) (Resource*, bool);
void (Resource::*fpIntInt)(Resource*, int, int);
};

// Also, make an enum for this type, so you know what it is:
enum FunctionType
{
FT_UNKNOWN,
FT_NONE,
FT_BOOL,
FT_INT_INT
};


So, now all you have to do to assign any function pointer to MemberFunction::fncPtr is to reinterpret_cast() it. When you fire off an event, you of course have to handle each type of function separately. When using va_args, this isn't too bad at all, considering the limited number of function types you are dealing with.

The rest of the C#-ness just comes from standard operator overloads. This is what the end result looks like:


checkRender = new Checkbox( "blahblahbalh", 0, 0 );
checkRender->OnChecked += StaticHandler( OnMyCheckboxHandler );
checkRender->OnMouseEnter += MemberHandler( myResource, Class::OnMouseEnter );
baseForm += checkRender;

Share this post


Link to post
Share on other sites

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