Skip to main content
gamedev.net
🔒 Locked

Creating user interfaces?

Started by nickwinters May 2, 2004 at 6:14 PM 11 replies 1.1k views
Original Post
nickwinters
nickwinters
I have a game where ships fly around, input and everything working... Now I need to figure out how to draw the user interface. Is there a way to draw it without manually finding where the vertices need to be so that they're right in front of the camera? I'm going to include things such as radar, other ships, messages, etc. Thanks. -Nick [edited by - nickwinters on May 2, 2004 7:16:55 PM]
darookie
darookie
You need to be more specific here.
Do you want a 2D interface that is visible all the time?
In this case you just render everything, switch to
ortho mode, turn depth testing off and render the 2D GUI
elements.



[edited by - darookie on May 2, 2004 7:27:18 PM]
nickwinters
nickwinters
Imagine something similar like this. I took it off freelancer, since it's similar to what I want.



I'm talking about things like the health bars in the center, #weapons left, options at the top right, etc.

If it is just switching to ortho mode, would you please provide some sample code? MDX code is prefered, but I can kinda read DX code. In the past, switching from perspective to ortho generally results in crashes or blank screens.

Thanks.

-Nick

[edited by - nickwinters on May 2, 2004 7:36:17 PM]
superpig
superpig
quote:
Original post by Deinonychus
Use ID3DXSprite and ID3DXFont.


Yup, that''s going to be good for most of the time.

To switch to ortho mode:


using Microsoft.DirectX;
device.SetTransform(Direct3D.TransformType.Projection, Matrix.OrthoLH(1.0f, 1.0f, 0.0f, 1.0f));


It should be something like that. I''m not a C# programmer so I don''t really know.

The end result should be - if you set your world and view matrices to identity - that vertex coordinates become fractions of the screen: a vertex at (0.5f, 0.5f) is dead-center, and so on.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
darookie
darookie
I really don''t understand how switching to ortho mode can crash
your app or blank the screen - it''s just a matrix transform after
all...
nickwinters
nickwinters
By switching, I never realized there''s a nice way to do it. I just kinda added the ortho initialization into the rendering code.
nickwinters
nickwinters
Thanks for your help. Since we already have some of our gui in vertices, we're going to try ortho. However, I can't get anything to display. Below is my rendering code, that's between begin scene and end scence.

device.SetTransform(TransformType.Projection, Matrix.OrthoLH(1.0f, 1.0f, 0.0f, 1.0f));
device.VertexFormat = CustomVertex.PositionColored.Format;

CustomVertex.PositionColored[] radarB = new CustomVertex.PositionColored[2];
radarB[0].SetPosition(new Vector3(0.25f, 0.25f, 0.01f));
radarB[0].Color = System.Drawing.Color.Black.ToArgb();
radarB[0].SetNormal(new Vector3(0.0f, 0.0f, -1.0f));
radarB[1].SetPosition(new Vector3(0.40f, 0.25f, 0.01f));
radarB[1].Color = System.Drawing.Color.Black.ToArgb();
radarB[1].SetNormal(new Vector3(0.0f, 0.0f, -1.0f));
device.DrawUserPrimitives(PrimitiveType.LineStrip, 1, radarB);


The 3D stuff that was there before is still there. Just no new ortho vertices.

[edited by - nickwinters on May 3, 2004 1:45:13 PM]
Alvarny
Alvarny
The difference between those 2 points is less than 1 pixel. No wonder nothing shows up.
nickwinters
nickwinters
if it goes from 0 to 1, shouldn''t the distance between .25 and .4 be 15% of the screen?
darookie
darookie
Use transformed vertices for 2D stuff. Normals are not required
and coordinates are absolute screen offsets.


DrunkenHyena
DrunkenHyena
quote:
Original post by nickwinters
if it goes from 0 to 1, shouldn''t the distance between .25 and .4 be 15% of the screen?


Are you remembering to set your World Matrix? If your vertices have the required position already, make sure you''re setting the World matrix to Identity.

Also, ditch the normal and turn off lighting.



Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena</FON

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.