Hi guys,
I am developing a general purpose GUI library in C# DX9 and I was using transformed vertices . That worked out all right.
Now I want to move onto positioned vertices so get some more flexibility, moving resizing etc without having to rebuild my buffers.
So first step is to define the quads that are the minimal bounding box for the controls. To increase the intuitive feel I define them with upper left at (0,0) and then unit length and height.
Next is to setup the matrices.
By default the world matrix is identity, and the view and projection is defined as:
Matrix.LookAtLH(new Vector3(width/2,height/2,1),new Vector3(width/2,height /2,0),new Vector3(0,-1,0));
Matrix.OrthoOffCenterLH( -width/2, width/2, -height/2, height/2, 0.01f, 10.0f );
And when rendering is define the transform matrix for a control c as:
Matrix.Scaling( new Vector3( c.Width, c.Height, 1.0f ) ) *
Matrix.RotationYawPitchRoll( 0.0f, 0.0f, 0.0f ) *
Matrix.Translation( new Vector3( c.Position.X, c.Position.Y, 0.0f ) );
Note that the positions are relative to parent control if no parent then screen.
This places the control right where i want it so that the control (x,y) correspond to the screen coordinates.
So far so good.
The problem arises when i want to draw control part inside another control.
Each control has a texture which is the graphical representation of the control and child controls rendered onto it. Thereby saying it is also used as render target.
Say W is a window and L is a label in W. To draw W i must first draw W's layout and then draw L onto W. Drawing W and only W is no problem but when drawing L onto W I do as follows:
1. I swap render targets setting W's texture as render surface.
2. Push new view and projection matrices to correspond texture dimension of W.
Matrix.LookAtLH(new Vector3(W.Width/2,W.Height/2,1),new Vector3(W.Width/2,W.Height /2,0),new Vector3(0,-1,0));
Matrix.OrthoOffCenterLH( -W.Width/2, W.Width/2, -W.Height/2, W.Height/2, 0.01f, 10.0f );
3. Render L using same transformation matrix as listed above.
4. Pop matrices and reset render target to previous.
Somehow L is not placed where I want it, in fact it does not show.
Not excluding my code is broken elsewhere, is this a correct approach?
I was pretty certain until the results showed me something else. Sorry for the long post >.<