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 ?

directx 9 ?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devperformancequestion
4 Posts 4 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.
  • B Offline
    B Offline
    bluatigro
    wrote on last edited by
    #1

    i fount this on internet but i have a set of Q : why not initd3d in WM_CREATE and render_frame in WM_PAINT and cleard3d in WM_DESTROY ----------------------------code

    // include the basic windows header files and the Direct3D header file
    #include
    #include
    #include

    // define the screen resolution
    #define SCREEN_WIDTH 800
    #define SCREEN_HEIGHT 600

    // include the Direct3D Library file
    #pragma comment (lib, "d3d9.lib")

    // global declarations
    LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
    LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
    LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; // the pointer to the vertex buffer

    // function prototypes
    void initD3D(HWND hWnd); // sets up and initializes Direct3D
    void render_frame(void); // renders a single frame
    void cleanD3D(void); // closes Direct3D and releases memory
    void init_graphics(void); // 3D declarations

    struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
    #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS\_HREDRAW | CS\_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC\_ARROW);
    wc.lpszClassName = L"WindowClass";
    
    RegisterClassEx(&wc);
    
    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our Direct3D Program",
                          WS\_OVERLAPPEDWINDOW,
                          0, 0,
                          SCREEN\_WIDTH, SCREEN\_HEIGHT,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);
    
    ShowWindow(hWnd, nCmdShow);
    
    // set up and initialize Direct3D
    initD3D(hWnd);
    
    // enter the main loop:
    
    MSG msg;
    
    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM\_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        if(msg.message == WM\_QUIT)
            break;
    
        render\_fram
    
    L D L 3 Replies Last reply
    0
    • B bluatigro

      i fount this on internet but i have a set of Q : why not initd3d in WM_CREATE and render_frame in WM_PAINT and cleard3d in WM_DESTROY ----------------------------code

      // include the basic windows header files and the Direct3D header file
      #include
      #include
      #include

      // define the screen resolution
      #define SCREEN_WIDTH 800
      #define SCREEN_HEIGHT 600

      // include the Direct3D Library file
      #pragma comment (lib, "d3d9.lib")

      // global declarations
      LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
      LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
      LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; // the pointer to the vertex buffer

      // function prototypes
      void initD3D(HWND hWnd); // sets up and initializes Direct3D
      void render_frame(void); // renders a single frame
      void cleanD3D(void); // closes Direct3D and releases memory
      void init_graphics(void); // 3D declarations

      struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
      #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

      // the WindowProc function prototype
      LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

      // the entry point for any Windows program
      int WINAPI WinMain(HINSTANCE hInstance,
      HINSTANCE hPrevInstance,
      LPSTR lpCmdLine,
      int nCmdShow)
      {
      HWND hWnd;
      WNDCLASSEX wc;

      ZeroMemory(&wc, sizeof(WNDCLASSEX));
      
      wc.cbSize = sizeof(WNDCLASSEX);
      wc.style = CS\_HREDRAW | CS\_VREDRAW;
      wc.lpfnWndProc = WindowProc;
      wc.hInstance = hInstance;
      wc.hCursor = LoadCursor(NULL, IDC\_ARROW);
      wc.lpszClassName = L"WindowClass";
      
      RegisterClassEx(&wc);
      
      hWnd = CreateWindowEx(NULL,
                            L"WindowClass",
                            L"Our Direct3D Program",
                            WS\_OVERLAPPEDWINDOW,
                            0, 0,
                            SCREEN\_WIDTH, SCREEN\_HEIGHT,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);
      
      ShowWindow(hWnd, nCmdShow);
      
      // set up and initialize Direct3D
      initD3D(hWnd);
      
      // enter the main loop:
      
      MSG msg;
      
      while(TRUE)
      {
          while(PeekMessage(&msg, NULL, 0, 0, PM\_REMOVE))
          {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
          }
      
          if(msg.message == WM\_QUIT)
              break;
      
          render\_fram
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try asking the person who wrote it.

      1 Reply Last reply
      0
      • B bluatigro

        i fount this on internet but i have a set of Q : why not initd3d in WM_CREATE and render_frame in WM_PAINT and cleard3d in WM_DESTROY ----------------------------code

        // include the basic windows header files and the Direct3D header file
        #include
        #include
        #include

        // define the screen resolution
        #define SCREEN_WIDTH 800
        #define SCREEN_HEIGHT 600

        // include the Direct3D Library file
        #pragma comment (lib, "d3d9.lib")

        // global declarations
        LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
        LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
        LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; // the pointer to the vertex buffer

        // function prototypes
        void initD3D(HWND hWnd); // sets up and initializes Direct3D
        void render_frame(void); // renders a single frame
        void cleanD3D(void); // closes Direct3D and releases memory
        void init_graphics(void); // 3D declarations

        struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
        #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

        // the WindowProc function prototype
        LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

        // the entry point for any Windows program
        int WINAPI WinMain(HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
        LPSTR lpCmdLine,
        int nCmdShow)
        {
        HWND hWnd;
        WNDCLASSEX wc;

        ZeroMemory(&wc, sizeof(WNDCLASSEX));
        
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS\_HREDRAW | CS\_VREDRAW;
        wc.lpfnWndProc = WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC\_ARROW);
        wc.lpszClassName = L"WindowClass";
        
        RegisterClassEx(&wc);
        
        hWnd = CreateWindowEx(NULL,
                              L"WindowClass",
                              L"Our Direct3D Program",
                              WS\_OVERLAPPEDWINDOW,
                              0, 0,
                              SCREEN\_WIDTH, SCREEN\_HEIGHT,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
        
        ShowWindow(hWnd, nCmdShow);
        
        // set up and initialize Direct3D
        initD3D(hWnd);
        
        // enter the main loop:
        
        MSG msg;
        
        while(TRUE)
        {
            while(PeekMessage(&msg, NULL, 0, 0, PM\_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        
            if(msg.message == WM\_QUIT)
                break;
        
            render\_fram
        
        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        bluatigro wrote:

        i fount this on internet but i have a set of Q :

        Have you considered asking here?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        • B bluatigro

          i fount this on internet but i have a set of Q : why not initd3d in WM_CREATE and render_frame in WM_PAINT and cleard3d in WM_DESTROY ----------------------------code

          // include the basic windows header files and the Direct3D header file
          #include
          #include
          #include

          // define the screen resolution
          #define SCREEN_WIDTH 800
          #define SCREEN_HEIGHT 600

          // include the Direct3D Library file
          #pragma comment (lib, "d3d9.lib")

          // global declarations
          LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
          LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class
          LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; // the pointer to the vertex buffer

          // function prototypes
          void initD3D(HWND hWnd); // sets up and initializes Direct3D
          void render_frame(void); // renders a single frame
          void cleanD3D(void); // closes Direct3D and releases memory
          void init_graphics(void); // 3D declarations

          struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
          #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

          // the WindowProc function prototype
          LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

          // the entry point for any Windows program
          int WINAPI WinMain(HINSTANCE hInstance,
          HINSTANCE hPrevInstance,
          LPSTR lpCmdLine,
          int nCmdShow)
          {
          HWND hWnd;
          WNDCLASSEX wc;

          ZeroMemory(&wc, sizeof(WNDCLASSEX));
          
          wc.cbSize = sizeof(WNDCLASSEX);
          wc.style = CS\_HREDRAW | CS\_VREDRAW;
          wc.lpfnWndProc = WindowProc;
          wc.hInstance = hInstance;
          wc.hCursor = LoadCursor(NULL, IDC\_ARROW);
          wc.lpszClassName = L"WindowClass";
          
          RegisterClassEx(&wc);
          
          hWnd = CreateWindowEx(NULL,
                                L"WindowClass",
                                L"Our Direct3D Program",
                                WS\_OVERLAPPEDWINDOW,
                                0, 0,
                                SCREEN\_WIDTH, SCREEN\_HEIGHT,
                                NULL,
                                NULL,
                                hInstance,
                                NULL);
          
          ShowWindow(hWnd, nCmdShow);
          
          // set up and initialize Direct3D
          initD3D(hWnd);
          
          // enter the main loop:
          
          MSG msg;
          
          while(TRUE)
          {
              while(PeekMessage(&msg, NULL, 0, 0, PM\_REMOVE))
              {
                  TranslateMessage(&msg);
                  DispatchMessage(&msg);
              }
          
              if(msg.message == WM\_QUIT)
                  break;
          
              render\_fram
          
          L Offline
          L Offline
          leon de boer
          wrote on last edited by
          #4

          You generally do put the initD3D in the WM_CREATE and the cleanD3D in the WM_DESTROY. The problem is you can't really put the render in the WM_PAINT you need to pump the render over and over. So they have done a horrible hack to use the message loop to pump the render. The problem with their hack is they can only have one render window and the render speed is controlled by the message loop. Do you see the sneaky render_frame(); call in the message loop which is the render pump. The correct way to do it is create a thread in WM_CREATE to pump the render call .. good old CreateThread() You can link up WM_WINDOWPOSCHANGED (window size change) and WM_PAINT to the render thread if you want to do things from them to the renderer. So they are basically trying to dodge having to deal with the complexity of having a render thread because it is targetted at beginners. It is horrible as the render complexity and time goes up the message response time goes out the window. MS has a proper threaded samples and there are probably others around Windows Direct3D Multithreaded Rendering Win32 Sample in C++ for Visual Studio 2012[^] NVidia also has do's and dont's ... see under do's ... Master Render Thread DX12 Do's And Don'ts | NVIDIA Developer[^]

          In vino veritas

          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