directx 9 ?
-
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 declarationsstruct 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
-
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 declarationsstruct 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
-
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 declarationsstruct 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
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
-
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 declarationsstruct 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
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