Introduction: I deeply feel that this "blank window" is so complicated. A lot of functions need to be called for a black screen. It is no wonder that our programmers need to form a team to be competent for game production.
Okay. I have a question last time. What is the difference between the wndproc () function and the msgproc () function? With this question, I posted a post and asked my friends. I finally came up with my own opinions under various answers.
In fact, most of the wndproc () and msgproc () functions are the same, but they are named differently. In the Win32 program, we can see that their function prototype is in front of the winmain () function, so we can think that it is a user-defined, man-made function, we can even cancel this function name and rename it.
This time I learned how to create and display the direct3d window. Of course, I still use this book:
First, check the Code:
Code:
- Bool initialized3d (hwnd, bool fullscreen)
- {
- D3ddisplaymode displaymode;
- // Create the d3d object.
- G_d3d = direct3dcreate9 (d3d_sdk_version );
- If (g_d3d = NULL) return false;
- // Get the desktop display mode.
- If (failed (g_d3d-> getadapterdisplaymode (d3dadapter_default, & displaymode )))
- Return false;
- // Set up the structure used to create the d3ddevice
- D3dpresent_parameters d3dpp;
- Zeromemory (& d3dpp, sizeof (d3dpp ));
- If (fullscreen)
- {
- D3dpp. incluwed = false;
- D3dpp. backbufferwidth = 640;
- D3dpp. backbufferheight = 480;
- }
- Else
- D3dpp. paiwed = true;
- D3dpp. swapeffect = d3dswapeffect_discard;
- D3dpp. backbufferformat = displaymode. format;
- // Create the d3ddevice
- If (failed (g_d3d-> createdevice (d3dadapter_default, d3ddevtype_hal, hwnd,
- D3dcreate_software_vertexprocessing, & d3dpp, & g_d3ddevice )))
- {
- Return false;
- }
- Return true;
- }
Initialized3d () is a function defined by the author and is not a built-in function. Its parameters are the window handle and whether it is a full-screen logical variable. In short, the structure of this function is used to create d3d windows. The details are as follows:
Here are two points:
1. Using the "If (failed (...) return false" structure can effectively save code and determine whether the code is successful. If you add a statement cout <"error code (1009)" before "Return false" (of course, this is an example, win32 programs cannot make cout output simply .), You can determine the error during running.
2. Using the zeromemory () function is also a good habit. Because you do not know whether the memory used to create the device is 0 at the initial time. If it is not 0, some inexplicable errors will inevitably occur during use. Using the zeromemory () function is similar to clearing the box before putting it in. It can avoid damage to our computer, so it is strongly recommended.