Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DirectX 9 in code:blocks fails on initD3D

DirectX 9 in code:blocks fails on initD3D

Scheduled Pinned Locked Moved C / C++ / MFC
helpvisual-studiographicsgame-devtutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Korowai
    wrote on last edited by
    #1

    Hello, i am trying to handle problem with directX 9 and code:blocks. i searched the internet and after installing the sdk properly and used a tutorial to compile the directx code in an static control window of my winapi program. The IDE doesn't give an error, but instead of compiling a grey window the code only does a black window over the other dialog elements, who won't be compiled properly on screen. The programm doesn't shutdown and the window bar still is in function. Does anyone knows what's to do? Here ist the code in cuts:

    void initD3D(HWND hDlg30)
    {
    d3d = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT\_PARAMETERS d3dpp;    
    
    ZeroMemory(&d3dpp, sizeof(d3dpp));    
    d3dpp.Windowed = TRUE;    
    d3dpp.SwapEffect = D3DSWAPEFFECT\_DISCARD;    
    d3dpp.hDeviceWindow = hDlg30;    
    
    d3d->CreateDevice(D3DADAPTER\_DEFAULT,
                      D3DDEVTYPE\_HAL,
                      hDlg30,
                      D3DCREATE\_SOFTWARE\_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
    

    }

    HRESULT CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
    D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface);

    void render_frame(void)
    {
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

    d3ddev->BeginScene();    
    
    d3ddev->EndScene();    
    
    d3ddev->Present(NULL, NULL, NULL, NULL);    
    

    }

    void cleanD3D(void)
    {
    d3ddev->Release();
    d3d->Release();
    }

    And this is the dialog code so far:

    BOOL CALLBACK RaumkarteProc(HWND hDlg30, UINT message, WPARAM wParam, LPARAM lParam)
    {
    PAINTSTRUCT ps;
    HDC hdc;
    HDC hdcZeichnung;
    RECT rect;

    static HWND hwndRaumkarteAktion1, hwndRaumkarteAktion2,
    hwndRaumkarteHScroll, hwndRaumkarteVScroll, hwndRaum;
    int AnzahlGegner;
    static int rightWidth=1100;
    static int lowerHeight=650;
    static int leftWidth=300;
    static int upperHeight=50;
    bool Kartezeichnen=true;
    static int iAktions1index;
    static int Aktion1auslesen;
    static char Aktion1auswahl\[100\];
    int Kartenmobilanzahl;
    Kartenmobilanzahl=Zufallsgegner\_Raum.size();
    hwndRaum=GetDlgItem(hDlg30,ID\_RAUMKARTE31);
    initD3D(hDlg30);
    
    switch (message)
    {
        case WM\_INITDIALOG:
        {
            SendDlgItemMessage(hDlg30, ID\_RAUMKARTEAKTIONSLISTE34,LB\_ADDST
    
    L 1 Reply Last reply
    0
    • K Korowai

      Hello, i am trying to handle problem with directX 9 and code:blocks. i searched the internet and after installing the sdk properly and used a tutorial to compile the directx code in an static control window of my winapi program. The IDE doesn't give an error, but instead of compiling a grey window the code only does a black window over the other dialog elements, who won't be compiled properly on screen. The programm doesn't shutdown and the window bar still is in function. Does anyone knows what's to do? Here ist the code in cuts:

      void initD3D(HWND hDlg30)
      {
      d3d = Direct3DCreate9(D3D_SDK_VERSION);

      D3DPRESENT\_PARAMETERS d3dpp;    
      
      ZeroMemory(&d3dpp, sizeof(d3dpp));    
      d3dpp.Windowed = TRUE;    
      d3dpp.SwapEffect = D3DSWAPEFFECT\_DISCARD;    
      d3dpp.hDeviceWindow = hDlg30;    
      
      d3d->CreateDevice(D3DADAPTER\_DEFAULT,
                        D3DDEVTYPE\_HAL,
                        hDlg30,
                        D3DCREATE\_SOFTWARE\_VERTEXPROCESSING,
                        &d3dpp,
                        &d3ddev);
      

      }

      HRESULT CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
      D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface);

      void render_frame(void)
      {
      d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

      d3ddev->BeginScene();    
      
      d3ddev->EndScene();    
      
      d3ddev->Present(NULL, NULL, NULL, NULL);    
      

      }

      void cleanD3D(void)
      {
      d3ddev->Release();
      d3d->Release();
      }

      And this is the dialog code so far:

      BOOL CALLBACK RaumkarteProc(HWND hDlg30, UINT message, WPARAM wParam, LPARAM lParam)
      {
      PAINTSTRUCT ps;
      HDC hdc;
      HDC hdcZeichnung;
      RECT rect;

      static HWND hwndRaumkarteAktion1, hwndRaumkarteAktion2,
      hwndRaumkarteHScroll, hwndRaumkarteVScroll, hwndRaum;
      int AnzahlGegner;
      static int rightWidth=1100;
      static int lowerHeight=650;
      static int leftWidth=300;
      static int upperHeight=50;
      bool Kartezeichnen=true;
      static int iAktions1index;
      static int Aktion1auslesen;
      static char Aktion1auswahl\[100\];
      int Kartenmobilanzahl;
      Kartenmobilanzahl=Zufallsgegner\_Raum.size();
      hwndRaum=GetDlgItem(hDlg30,ID\_RAUMKARTE31);
      initD3D(hDlg30);
      
      switch (message)
      {
          case WM\_INITDIALOG:
          {
              SendDlgItemMessage(hDlg30, ID\_RAUMKARTEAKTIONSLISTE34,LB\_ADDST
      
      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      Start with the obvious the line that is supposed to make the screen grey is Render_frame

      d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

      That function actually returns a result which isn't used in your code, so use the return and debug it

      HRESULT result = d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

      Now put a breakpoint on the line and check the result is D3D_OK. It tells you in the directx9 help for the function IDirect3DDevice9::Clear will fail if you: Try to clear either the depth buffer or the stencil buffer of a render target that does not have an attached depth buffer. Try to clear the stencil buffer when the depth buffer does not contain stencil data. Creating a Depth Buffer (Direct3D 9) (Windows)[^] It is noted in your initD3D function it doesn't seem to do that It is noted in you setup these two lines you appear to be missing

      d3dpp.EnableAutoDepthStencil = TRUE;
      d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

      In vino veritas

      K 2 Replies Last reply
      0
      • L leon de boer

        Start with the obvious the line that is supposed to make the screen grey is Render_frame

        d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

        That function actually returns a result which isn't used in your code, so use the return and debug it

        HRESULT result = d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

        Now put a breakpoint on the line and check the result is D3D_OK. It tells you in the directx9 help for the function IDirect3DDevice9::Clear will fail if you: Try to clear either the depth buffer or the stencil buffer of a render target that does not have an attached depth buffer. Try to clear the stencil buffer when the depth buffer does not contain stencil data. Creating a Depth Buffer (Direct3D 9) (Windows)[^] It is noted in your initD3D function it doesn't seem to do that It is noted in you setup these two lines you appear to be missing

        d3dpp.EnableAutoDepthStencil = TRUE;
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

        In vino veritas

        K Offline
        K Offline
        Korowai
        wrote on last edited by
        #3

        Hello, i tried to fix this, but it still doesn't work. I thougth about it and i guess it could be anything with the ressource file of the dialogue.

        LANGUAGE 0, SUBLANG_NEUTRAL
        IDD_DIALOG30 DIALOG 0, 0, 1000, 600
        STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
        CAPTION "Raumkarte"
        FONT 8, "Ms Shell Dlg"
        {
        CONTROL "", ID_RAUMKARTE31, WC_STATIC, SS_BLACKFRAME, 201, 0, 800, 600, WS_EX_ACCEPTFILES | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
        SCROLLBAR ID_SCROLLBARVER32, 202, 2, 19, 186, SBS_VERT, WS_EX_LEFT
        SCROLLBAR ID_SCROLLBARHOR33, 222, 2, 214, 15, 0, WS_EX_LEFT
        LISTBOX ID_RAUMKARTEAKTIONSLISTE34, 1, 0, 198, 183, WS_TABSTOP | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_SORT | LBS_NOTIFY, WS_EX_LEFT
        LISTBOX ID_RAUMKARTEWAHLAKTIONSLISTE35, 1, 187, 198, 188, WS_TABSTOP | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_SORT | LBS_NOTIFY, WS_EX_LEFT
        }

        The DirectX Code should be in the Static Control "ID_RAUMKARTE31". Maybe i have to add a parameter. Thx & Greetings

        1 Reply Last reply
        0
        • L leon de boer

          Start with the obvious the line that is supposed to make the screen grey is Render_frame

          d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

          That function actually returns a result which isn't used in your code, so use the return and debug it

          HRESULT result = d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(70, 70, 70), 1.0f, 0);

          Now put a breakpoint on the line and check the result is D3D_OK. It tells you in the directx9 help for the function IDirect3DDevice9::Clear will fail if you: Try to clear either the depth buffer or the stencil buffer of a render target that does not have an attached depth buffer. Try to clear the stencil buffer when the depth buffer does not contain stencil data. Creating a Depth Buffer (Direct3D 9) (Windows)[^] It is noted in your initD3D function it doesn't seem to do that It is noted in you setup these two lines you appear to be missing

          d3dpp.EnableAutoDepthStencil = TRUE;
          d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

          In vino veritas

          K Offline
          K Offline
          Korowai
          wrote on last edited by
          #4

          I added these lines. There is still no effect. Please take a look at the code i postet with a thread i made in questions. I think it has something to do with the way i manage the edit control where directx is supposed to render. It would be really nice if you take a look in my other thread. Thanks a lot.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups