Thread: do you have to use createwindow to create the main directx window?

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    do you have to use createwindow to create the main directx window?

    do you have to use createwindow to create the main directx window? or does the directx api have its own way?

    plus which compiler is best ,
    i read in the directx update visual studio 6 is no longer supported :
    so do i go with visual studio 2003.net
    thanks

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I use VS 2003 and it works fine for me.
    AFAIK you'll have to use the windows API or MFC to create a window in which to run your DirectX apps.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    ok thanks i wasnt sure if directx had something to make a window as well

    if your using 2003 .net ,
    which .h direct includes do i need ,
    because alot of diferent tutorials show diferent ones

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    I use the Microsoft Visual C++ Toolkit 2003 command line compiler.

    Do you mean the CreateWindow/CreateWindowEx functions? Then yes, you set up a window just as you would normally. When you create a D3D device you pass it the HWND of the window you want it to draw to.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    yes i mean Createwindow
    and do you need the msg loop running and the switch ?

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Anddos
    ok thanks i wasnt sure if directx had something to make a window as well

    if your using 2003 .net ,
    which .h direct includes do i need ,
    because alot of diferent tutorials show diferent ones
    The one I can remember off the top of my head is d3d9.h sorry.
    EDIT: That's assuming you're using the DirectX 9 SDK.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by Anddos
    which .h direct includes do i need ,
    because alot of diferent tutorials show diferent ones
    You'll need to download the directx 9 SDK.

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    ive got it

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    so how do you make the ShowWindow in full screen without the taskbar at the bottom ,
    ive tried all the parameters that comes with the function

  10. #10
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    You really need to start following a DirectX tutorial now. Have a google about for one.

    EDIT:
    http://www.drunkenhyena.com/
    Is the best one I've found, IIRC.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    ahluka not being funny or anything but that tut dosent even show about adding inlclude and libs plus saying what .h files you need
    plus adding the stuff to link
    but the rest is pritty good
    Last edited by Anddos; 03-27-2006 at 04:45 AM.

  12. #12
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Anddos
    ahluka not being funny or anything but that tut dosent even show about adding inlclude and libs plus saying what .h files you need
    plus adding the stuff to link
    but the rest is pritty good
    Trust me when I say you're unlikely to find anything much better online other than sifting through example apps. that come with the SDK. Take this advice handed to me by Bubba: buy books. There's a surprising lack of good material online.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Code:
    bool CD3DApp::InitD3D(HINSTANCE hInstance,
    	                    int width, 
                          int height,
    	                    bool windowed,
    	                    D3DDEVTYPE DeviceType)
                          
    {
      m_iWidth=width;
      m_iHeight=height;
      m_bWindowed=windowed;
      m_hAppInstance=hInstance;
      m_pDeviceType=DeviceType;
      
      //
    	// Create the main application window.
    	//
    
      WNDCLASS wc;
    
    	wc.style=0;
      wc.style         = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc   = (WNDPROC)g_WndProc; 
    	wc.cbClsExtra    = 0;
    	wc.cbWndExtra    = 0;
    	wc.hInstance     = hInstance;
    	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
    	wc.hCursor       = LoadCursor(0, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wc.lpszMenuName  = 0;
    	wc.lpszClassName = "CD3DApp";
    
    	if( !RegisterClass(&wc) ) 
    	{
    		::MessageBox(0, "RegisterClass() - FAILED", 0, 0);
    		return false;
    	}
      
      HWND hwnd=0;
    	DWORD style=0;
      if (m_bWindowed)
      {
        style=WS_OVERLAPPEDWINDOW;
      }
      else
      {
        style=WS_OVERLAPPEDWINDOW | WS_VISIBLE;
      }
    
      m_hwndAppWindowHandle = ::CreateWindow("CD3DApp", 
                                             NULL, 
    		                                     style,
    		                                     0, 
                                             0, 
                                             m_iWidth, 
                                             m_iHeight,
    		                                     0,
                                             0, 
                                             hInstance, 
                                             0); 
      
    
    	if( !m_hwndAppWindowHandle )
    	{
        ::MessageBox(0,0,"CreateWindow() - FAILED",0);
    		return false;
    	}
    
      //
    	// Init D3D: 
    	//
    
    	HRESULT hr = 0;
    
    	// Step 1: Create the IDirect3D9 object.
    
    	IDirect3D9* d3d9 = 0;
        d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
    
        if( !d3d9 )
    	{
    		::MessageBox(0, "Direct3DCreate9() - FAILED", 0, 0);
    		return false;
    	}
    
    	// Step 2: Check for hardware vp.
    
    	d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, DeviceType, &m_pDeviceCaps);
    
    	int vp = 0;
    	if( m_pDeviceCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
    		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
    	else
    		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
    
    	// Step 3: Fill out the D3DPRESENT_PARAMETERS structure.
     
    	
    	if (m_bWindowed)
      {
        m_pPresentParams.BackBufferWidth            = 0;
    	  m_pPresentParams.BackBufferHeight           = 0;
        m_pPresentParams.BackBufferFormat           = D3DFMT_UNKNOWN;
    
    	  
      }
      else
      {
    	  m_pPresentParams.BackBufferWidth            = m_iWidth;
    	  m_pPresentParams.BackBufferHeight           = m_iHeight;
    	  m_pPresentParams.BackBufferFormat           = D3DFMT_A8R8G8B8;
      }
    
        
        m_pPresentParams.BackBufferCount            = 1;
    	  m_pPresentParams.MultiSampleType            = D3DMULTISAMPLE_NONE;
        m_pPresentParams.MultiSampleQuality         = 0;
    	  m_pPresentParams.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
    	  m_pPresentParams.hDeviceWindow              = m_hwndAppWindowHandle;
    	  m_pPresentParams.Windowed                   = m_bWindowed;
    	  m_pPresentParams.EnableAutoDepthStencil     = true; 
    	  m_pPresentParams.AutoDepthStencilFormat     = D3DFMT_D24S8;
    	  m_pPresentParams.Flags                      = 0;
    	  m_pPresentParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    	  m_pPresentParams.PresentationInterval       = D3DPRESENT_INTERVAL_ONE;
      
      
    	// Step 4: Create the device.
    
    	 
    
      hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT,     
    		                      DeviceType,             
    		                      m_hwndAppWindowHandle,                 
    		                      vp,                     
    	                        &m_pPresentParams,     
    	                        &m_pDevice);             
      
    
    	if( FAILED(hr) )
    	{
    		// try again using a 16-bit depth buffer
    		m_pPresentParams.AutoDepthStencilFormat = D3DFMT_D16;
    		
    		hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT,
    			                      DeviceType,
    			                      m_hwndAppWindowHandle,
    			                      vp,
    			                      &m_pPresentParams,
    			                      &m_pDevice);
    
    		if( FAILED(hr) )
    		{
    			d3d9->Release(); // done with d3d9 object
    			::MessageBox(0, "CreateDevice() - FAILED", 0, 0);
    			return false;
    		}
    	}
    
      if (m_bWindowed)
      {
        ShowWindow(m_hwndAppWindowHandle,SW_SHOW);
      }
    
    
    	d3d9->Release(); // done with d3d9 object
    
      	
    	return true;
    }
    Most of this can be found in books. This comes from one of my sources - Introduction to 3D Game Programming with DirectX 9.0 by Frank Luna. www.moon-labs.com is it's website and a 2nd edition is due out soon which I'll grab in a heartbeat. You can get it at www.amazon.com.

    I used a lot of ideas from this book, however, have significantly altered the entire setup to better suit my needs. His approach was too "C-like" for me so I encapsulated, re-arranged, sorted, off-loaded some code to other classes, and the like.

    The class looks like this:
    Code:
    #ifndef CD3DApplication
    #define CD3DApplication
    
    #include <d3dx9.h>
    #include <string>
    #include <limits>
    
    #include "CDXInput.h"
    #include "CMouse.h"
    #include "CKeyboard.h"
    #include "CDXAudio.h"
    #include "CDXShowWnd.h"
    
    
    
    
    const float INFINITY = FLT_MAX;
    const float EPSILON  = 0.001f;
    
    LRESULT CALLBACK      g_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
    LRESULT CALLBACK      g_VideoWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
    
    
    #define CDX_AUDIO_SOUNDFX   0x01
    #define CDX_AUDIO_MUSIC     0x03
    
    #define MODE_START          0x01
    #define MODE_PAUSE          0x02
    #define MODE_GAME           0x03
    
    
    class CD3DApp
    {
      
      protected:
        int                   m_iWidth;
        int                   m_iHeight;
        bool                  m_bWindowed;
        D3DDEVTYPE            m_pDeviceType;
        D3DPRESENT_PARAMETERS m_pPresentParams;
    
        HWND                  m_hwndAppWindowHandle;
        HINSTANCE             m_hAppInstance;
        D3DCAPS9              m_pDeviceCaps;
        DWORD                 m_dwStyle;
    
        //Add ins
        CDXInput              Input;
        CMouse                *Mouse;
        CKeyboard             *Keyboard;
        CDXAudio              *Audio;
        CDXSoundEmitter       *SoundFX;
        CDXSoundEmitter       *Music;
        CDXShowWnd            *m_pDirectShow;
    
        IDirect3DDevice9      *m_pDevice;
    
        int                   m_iGameMode;
    
      public:
    
        int EnterMsgLoop(void);
        
        CD3DApp(void):m_iWidth(0),m_iHeight(0),m_bWindowed(false),
                      m_hwndAppWindowHandle(0),m_hAppInstance(0),
                      m_pDevice(NULL),m_pDirectShow(NULL) { }
    
        virtual ~CD3DApp(void)
        {
          delete Keyboard;
          delete Mouse;
        }
        
        int GetMode(void) {return m_iGameMode;}
        void SetMode(int iGameMode) {m_iGameMode=iGameMode;}
    
        CDXSoundEmitter *GetSoundSystem(WORD wSoundObject)
        {
          switch (wSoundObject)
          {
            case CDX_AUDIO_SOUNDFX: return SoundFX;break;
            case CDX_AUDIO_MUSIC:   return Music;break;
          }
        }
    
    
        CKeyboard *GetKeyboard(void) 
        {
          if (Keyboard)
          {
            return Keyboard;
          } else return NULL;
        }
    
        CMouse *GetMouse(void)
        {
          if (Mouse)
          {
            return Mouse;
          } else return NULL;
        }
    
        
        void SetWindowStyle(DWORD dwStyle) {m_dwStyle=dwStyle;}   
        //DWORD GetWindowStyle(void) { return m_dwStyle;}
    
        //void SetPresentParams(D3DPRESENT_PARAMETERS d3dpp) {m_PresentParams=d3dpp;};
        //void GetPresentParams(D3DPRESENT_PARAMETERS *d3dpp) {d3dpp=&m_PresentParams;};
    
       
        bool GetCaps(D3DCAPS9 *devCaps)
        {
          devCaps=&m_pDeviceCaps;
          return true;
          
        }
    
        
      //
    	// Init
    	//
    	bool InitD3D(HINSTANCE hInstance,       // [in] Application instance.
    		           int width,                 // [in] Backbuffer dimensions.
                   int height,                
    		           bool windowed,             // [in] Windowed (true)or full screen (false).
    		           D3DDEVTYPE deviceType);
    		
      bool InitInput(void);
      bool InitAudio(DWORD dwNumPChannels,DWORD dwMSLatency);
      
    
      
      // Lights
    	//
    
    	D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color);
    	D3DLIGHT9 InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color);
    	D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color);
    
    	//
    	// Materials
    	//
    	D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);
    
    	//
    	// Bounding Objects
    	//
    	struct BoundingBox
    	{
    		BoundingBox();
    
    		bool isPointInside(D3DXVECTOR3& p);
    
    		D3DXVECTOR3 _min;
    		D3DXVECTOR3 _max;
    	};
    
    	struct BoundingSphere
    	{
    		BoundingSphere();
    
    		D3DXVECTOR3 _center;
    		float       _radius;
    	};
    
    	float GetRandomFloat(float lowBound, float highBound);
    	void GetRandomVector(
    		D3DXVECTOR3* out,
    		D3DXVECTOR3* min,
    		D3DXVECTOR3* max);
    
    	//
    	// Conversion
    	//
    	DWORD FtoDw(float f);
    
    	
    	// Interpolation
    	float LI(float a, float b, float t);
    
      virtual bool Setup(void)=0;
      virtual bool Render(float fTimeDelta)=0;
      virtual bool Cleanup(void)=0;
    
    };
    
    #endif
    It's a mess and needs sep classes for lights and materials. I show you this to prove you need not just one book, but many. So far I have over 30 some books about all of this stuff. The more the better.
    Last edited by VirtualAce; 03-27-2006 at 07:06 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  4. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM
  5. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 04:49 PM