Parse the simplest DirectX program "blank window" (2)

Source: Internet
Author: User

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:
  1. Bool initialized3d (hwnd, bool fullscreen)
  2. {
  3. D3ddisplaymode displaymode;
  4. // Create the d3d object.
  5. G_d3d = direct3dcreate9 (d3d_sdk_version );
  6. If (g_d3d = NULL) return false;
  7. // Get the desktop display mode.
  8. If (failed (g_d3d-> getadapterdisplaymode (d3dadapter_default, & displaymode )))
  9. Return false;
  10. // Set up the structure used to create the d3ddevice
  11. D3dpresent_parameters d3dpp;
  12. Zeromemory (& d3dpp, sizeof (d3dpp ));
  13. If (fullscreen)
  14. {
  15. D3dpp. incluwed = false;
  16. D3dpp. backbufferwidth = 640;
  17. D3dpp. backbufferheight = 480;
  18. }
  19. Else
  20. D3dpp. paiwed = true;
  21. D3dpp. swapeffect = d3dswapeffect_discard;
  22. D3dpp. backbufferformat = displaymode. format;
  23. // Create the d3ddevice
  24. If (failed (g_d3d-> createdevice (d3dadapter_default, d3ddevtype_hal, hwnd,
  25. D3dcreate_software_vertexprocessing, & d3dpp, & g_d3ddevice )))
  26. {
  27. Return false;
  28. }
  29. Return true;
  30. }

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.