SDL -> DirectX 9
I'm converting a game I started in SDL over to DirectX 9 as my game will eventually contain 3D elements.
At the moment I'm working on the GUI. Each GUI element has a draw function and in SDL this simply blitted a texture onto the screen at the control's co-ordinates.
In directx I'm planning to do this with textured quads, I have a general idea on how it works but I'd like to know I'm on the right track or if there is a much better solution.
- Before calling any draw() meathod my GUI manager will call IDirect3DDevice::SetTransform to set the device to render from transformed model co-ordinates.
- Each draw function will call SetTexture to set the correct texture from an array of GUI textures.
- Then I must call SetTextureStageState for the texture (maybe this should just be called once before drawing all of the controls?)
- Then call DrawPrimitive to draw the control.
Should each control have it's own vertex buffer for storing co-ordinates?
Thanx for any advice :)
Use this vertex structure for your 2D GUI.
static const DWORD FVF;
Create a vertex buffer with this structure. Set Pos.z to 1.0f and set x and y in SCREEN space. Just like you are drawing right to the screen. Using D3DFVF_XYZRHW will force a complete bypass of the T&L DX pipeline. Basically we are saying this vertex has already been processed so don't do any math on it.
const DWORD GUIVertex::FVF=D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1
Create your quads like this:
Triangle 1 - 0,1,2
Triangle 2 - 1,3,2
Triangle 1 - 2,1,0
Triangle 2 - 3,1,2
Texture coords should be:
0 - 0.0f,0.0f
1 - 1.0f,0.0f
2 - 0.0f,1.0f
3 - 1.0f,1.0f
To get DX to draw to your 'Window' per se without drawing outside of the boundaries of it (all drawing is clipped to the control) use
Thanx Bubba I'm getting the hang of this now