Jump to content
  • Advertisement
Sign in to follow this  

User Interface Question

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

Hey all, Ive been creating a simple user interface for my game, previously when i have developed a UI for an application in directX i simply created a plane and textured it with the button, and placed the plane close to the camera so it obstructs whatevers behind it like you would expect. I know this is a terrible way of doing this and thats why in the game im developing (where the camera is moving and not static like in the previous example) i dont want to/cant do this. Ive created a simple class structure for the buttons and what i ideally want is some way of passing the x and y values of the top left and bottom right co-ordinates and overlaying it on the screen much in the same way that you can by creating a RECT structure and applying text to it like so:
void Button::RenderText(IDirect3DDevice9* Device, LPCSTR buttonText, int x, int y)
 DEFAULT_PITCH | FF_DONTCARE, TEXT("Times New Roman"), &g_pd3dxFont );

        RECT rButtonTextBox;
	SetRect( &rButtonTextBox, x, y, 0, 0 );

g_pd3dxFont->DrawText( NULL,buttonText, -1, &rButtonTextBox, DT_NOCLIP, 
		       D3DXCOLOR(255, 255, 255, 1.0f) );
Im basically looking for a way of doing the above but with a rectangle(?) containing an image not text. Hopefully ive explained what im after well enough hehe, im still very much learning the ropes with DirectX so go easy !! - Chett

Share this post

Link to post
Share on other sites
If you are wanting to have fun and create a UI go ahead. But if you want to create something else (like a game or 3D app) and the UI is just something that needs to be done you might want to give DirectForms Designer a try. It can save you a tremendous amount of time. But again if you are desiring to do it yourself then I would love to help.

It sounds like a texture quad is what you want. It's basically four points that make up two triangle primitives with UV coordinates for your texture that you're going to paint onto it.

You can just give the points the actual screen coordinates, ie: 0,0 and 1024,768 would describe the entire screen area of a screen that was in 1024,768 resolution. If you do give actual screen coordinates then you want to set up the Device's transforms and/or vertex format appropriate for those coordinates.

As such, there are two ways of doing this:

Way 1: use transformed vertices, ie: using CustomVertex.TransformedColoredTextured format. This way the Device treats the vertex data as if it's already transformed into screen coordinates.

Way 2: use Transforms that allow the use of screen relative coordinates. This way the Device doesn't know that they are screen coordinates like way #1, but your transforms make it work that way. I do this by calling the following method at start up:

/// <summary>
/// Sets up the DirectForms matrices.
/// </summary>
public void SetupFormMatrices()
float x = this.device.Viewport.Width;
float y = this.device.Viewport.Height;
this.projection = Microsoft.DirectX.Matrix.OrthoOffCenterLH(0, x, y, 0, 0, 1);
this.view = Microsoft.DirectX.Matrix.Identity;
this.world = Microsoft.DirectX.Matrix.Identity;
this.wvp = this.world * this.view * this.projection;

You would, of course, assign the variables: this.projection, this.view and this.world to their respective Device.Transform."matrix name here" counterpart.

I personally prefer method 2 as I can give it a more versatile data type. I can't remember why but the transformed data types were causing my software some type of restriction. But it may just work fine for you.

If you need more info, please say so.



Share this post

Link to post
Share on other sites
Hi there, Im currently making a interface and have just finnished makeing my first edit box, I was going to make quads to do all the buttons and that, so I tested that and the Sprite and the sprite is so easy so I went with that. works good try the Sprite out save some work.
if you put all you interface image on the one texture you can use rectangles to locate and size them and also you can render all you interface with one sprite object cool.

//get the texture
IDirect3DTexture9 *tex = rc->Textures[ResourceEntry];

//this is the old sprite class
D3DCOLOR_RGBA(255, 255, 255, alpha));//colour key or this value 0xFFFFFFFF);

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!