Archived

This topic is now archived and is closed to further replies.

My menusystem needs a enhancement...

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

Hi there.. I''ve made a menusystem including windows, buttons, list-,edit- and comboboxes for directx7 directdraw. Now I''ve made a 3dsprite-engine and want my menusystem to work in d3d8.. But when not using screenspace all the coordinates are worldunits instead of pixels (of course) and I want to be able to place the windows and controls orthogonal to the cameraview and with coords 0,0 in the upper-left corner.. I''ve tried to set up a orthogonal projection matrix but I can''t get it working. Also I wouldn''t be able to have my 0,0 point in the upper-left corner of the screen... Suggestions, help anyone? Anyone made the same thing?

Share this post


Link to post
Share on other sites
Can I combine rhw and transformed vertices? So I can use two types of vertex shaders for world and menus?

And won''t rhw vertices give the same effect as 2d so that the gui scales according to screenresolution?

Since I use transformed vertices (XYZ not XYZRHW) for the world, wouldn''t it be easier to use the same shader for the menus?

Share this post


Link to post
Share on other sites
You basically need to be using transformed vertices (XWZRHW). These are then in the range [-1,1] for x and y, and [0,1] for z. Where (-1,-1,0,1) is the bottom left corner.

If you are using vertex shaders then you don''t even need to do this really. You can set your fvf as the usual XYZ vertices, then in the shader, just don''t transform the vertex positions at all.

Rory.

Share this post


Link to post
Share on other sites
But I have to transform the positions in order to face the camera all the time, don''t I?

If I don''t transform their positions they won''t have a worldposition and won''t be drawn... at least that''s what I thought..

Thanx for your help tho.. but I don''t think that''s what I''m looking for..

What do you mean by "in the shader"?

Share this post


Link to post
Share on other sites
If you specify RHW in the FVF then you are telling Direct3D not to transform the coordinates. This means that you can specify them in screen space and all will be well.

Normally in direct3d, a point in space will get transformed by the view matrix and the projection matrix. Visible points will then be in the range [-1,1] for x and y and [0,1] for z. But if you just want to do 2d stuff such as HUDs and menus, there is no point going through these translations - you can use the RHW flag in the FVF to tell direct3d to skip them and use screen space coords.

So basically, imagine you need to draw a square that is centred in the middle of the screen and is exactly half the width of the screen, and half the height. You also want this square to sit on top of everything else...


e.g.

-------------------
| |
| |-------| |
| |-------| |
| |-------| |
| |-------| |
| |
-------------------


Then you need four vertices (x, y, z, w):

1: (-0.5, -0.5, 0.0, 1.0)
2: (0.5, -0.5, 0.0, 1.0)
3: (0.5, 0.5, 0.0, 1.0)
4: (-0.5, 0.5, 0.0, 1.0)

Remember to keep the w value as 1.0 for all vertices because the x,y,z get divided by this!

When I wrote "in the shader", I was talking about using the programmable pipeline to specify a vertex shader. So a simple shader for a sprite would look something like this:


  
vs.1.0

// Position

mov oPos, v0

// Diffuse

mov oD0, v1


Hope this helps,

Rory.

Share this post


Link to post
Share on other sites
Helps a bit but since I use lighting and alpha blending I can''t use rhw, can I?

I know how to use rhw vertices, I did that at first but now since lighting is in I need transformed vertices...

So, what I ask is how to simulate rhw in transformed vertex format..

Also I want to use my camera class for zooming and rotation of view and stuff. That won''t work with rhw either. Hope you understand what I want now. Thanx

Share this post


Link to post
Share on other sites
In my last project, I had a menu that combined 2d and 3d things. I set up the camera and lighting to do the 3d stuff the way it needed to be done, and then did another pass to render 2d transformed vertices for the menu bitmaps.

The rendering basically looked like this:

set vertex shader to use the 3d vertex type
set up lighting and camera for 3d stuff
render all 3d objects

set vertex shader to use the 2d transformed vertex type
disable lighting
draw 2d stuff using blitter class

This is also the way that I drew the HUD for the game and it seemed to work fine.

Hope this helps or gives you ideas.

If you feel like looking at code you can dl my game with source from http://blackhat.farky.net. The game was for a games programming class.

Darryl Gates

Share this post


Link to post
Share on other sites
Thanx! That''s what I wanted to hear.. so I can change vertex shader in realtime?

Can I still use blending?

I''ll go right now downloading it! Thanx again!

Share this post


Link to post
Share on other sites
I use alpha blending in my HUD extensively, as well as in the 3d stuff as well so you shouldn''t have any trouble. Basically it just a few more render state calls to turn it on for what you need and off when you don''t need it. Same goes for the lighting.

Darryl Gates

Share this post


Link to post
Share on other sites