Thread: SDL -> DirectX 9

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    847

    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

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Use this vertex structure for your 2D GUI.

    Code:
    struct GUIVertex
    {
      D3DXVECTOR3  Pos;
      float Rhw;
      D3DCOLOR Diffuse;
      D3DCOLOR Specular;
      float u,v;
      static const DWORD FVF;
    };
    Code:
    const DWORD GUIVertex::FVF=D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1
    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.

    Create your quads like this:

    0........1
    ............
    ............
    2.........3

    For CCW:
    Triangle 1 - 0,1,2
    Triangle 2 - 1,3,2

    For CW:
    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

    IDirect3DDevice9::SetViewPort()

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Thanx Bubba I'm getting the hang of this now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL using SDL --> Should I or shouldn't I?
    By Devils Child in forum C++ Programming
    Replies: 12
    Last Post: 02-01-2008, 01:18 PM
  2. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  3. Widgets with OpenGL, DirectX or SDL?
    By nickname_changed in forum Game Programming
    Replies: 1
    Last Post: 09-25-2004, 11:33 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. DirectX or SDL?
    By Leeman_s in forum Game Programming
    Replies: 2
    Last Post: 01-19-2003, 10:13 PM