Directx3d development of the first DIRECTX3D project

Source: Internet
Author: User

Welcome to visit Easyliu's blog! This blog for Bo Master original, without permission not reproduced!

Development environment: Win764+vs2013+directx SDK (June 2010)

The Directx3d package is provided first: HTTP://PAN.BAIDU.COM/S/16WITW.

After downloading it, double-click the installation directly, the default installation directory is: C:\Program Files (x86) \microsoft DirectX SDK (June 2010).

Let's start with our first Directx3d project.

1, create a new empty Win32 application, remember not the Win32 console application, the two are made from the difference!

2. After the project is complete, configure the DirectX development environment:

Select "Project"-"properties" to open the Properties Configuration window as shown below:

Select "VC + + directory"to include the DirectX SDK's "Include Directory" and "Library Directory (LIB)" in the following, respectively:

C:\Program Files (x86) \microsoft DirectX SDK (June) \include

C:\Program Files (x86) \microsoft DirectX SDK (June) \lib\x86, although my system is win764 bit, but when my reference library directory changed to x64 will be an error, instead of x86 will not error, do not know how What's going on!

Click OK to exit the Properties Configuration window.

New file: main.cpp, add Reference Library at the beginning of the file:

#pragma comment (lib, "D3d9.lib")
#pragma comment (lib, "D3dx9.lib")

Open the Help document: C:\Program Files (x86) \microsoft DirectX SDK (June) \documentation\directx9\directx_sdk.chm, switch to the following directory:

Toutorial 1 in detail how to create a DirectX 3D project, although it is English but should not be ugly, and toutorial 1 has the corresponding sample project, located in the following directory:

C:\Program Files (x86) \microsoft DirectX SDK (June) \\samples\c++\direct3d\tutorials\tut01_createdevice , which contains a complete project, we just need to copy the code into our file main.cpp inside the line!

Here is the source code: should not be ugly to understand, pure use of Win32 API development, including Design window, registration window, create window, such as a series of processes, if the Win32 development is not very understanding of the students can first look at the VC + + depth of xinxin Sun, speak very detailed, easy to understand!

-----------------------------------------------------------------------------//file:createdevice.cpp////Desc : This is the first tutorial for using Direct3D. In this tutorial, all//we be doing is creating a Direct3D device and using it to clear the//window.////Cop Yright (c) Microsoft Corporation. All rights reserved.//-----------------------------------------------------------------------------#pragma Comment (lib, "D3d9.lib")//introduce dependent library #pragma comment (lib, "D3dx9.lib") #include <d3d9.h> #include "Windows.h"// This folder must be included #pragma warning (disable:4996)//disable deprecated warning #include <strsafe.h> #pragma warning (defau lt:4996)//-----------------------------------------------------------------------------//Global variables//---- -------------------------------------------------------------------------lpdirect3d9 g_pd3d = NULL; Used to create the D3DDevice lpdirect3ddevice9 g_pd3ddevice = NULL; Our rendering device//-----------------------------------------------------------------------------//NAME:INITD3D ()//desc:initializes direct3d//---------- -------------------------------------------------------------------HRESULT INITD3D (hwnd hwnd) {//Create the D3D object, which is needed to create the d3ddevice.if (NULL = = (G_pd3d = Direct3dcreate9 (d3d_sdk_version))) return e_fail;//S Et up the structure used to create the D3DDevice. Most parameters are//zeroed out. We set windowed to TRUE, since we want to does D3D in a//window, and then set the SwapEffect to "discard", which is the MoS  t//efficient method of presenting the back buffer to the display. and//We request a back buffer format this matches the current desktop display//format. D3dpresent_parameters D3DPP; ZeroMemory (&AMP;D3DPP, sizeof (D3DPP));d 3DPP. windowed = TRUE;D3DPP. SwapEffect = D3DSWAPEFFECT_DISCARD;D3DPP. Backbufferformat = d3dfmt_unknown;//Create the Direct3D device. Here we is using the default adapter (most//systems only has one, unless they has MUltiple Graphics hardware cards//installed) and requesting the HAL (which is saying we want the hardware//device rather than a software one). Software vertex processing is//specified since we know it'll work on all cards.  On cards this support//hardware vertex processing, though, we would see a big performance gain//by specifying hardware Vertex processing.if (FAILED (G_pd3d->createdevice (D3dadapter_default, D3ddevtype_hal, hwnd,d3dcreate_software_ VERTEXPROCESSING,&AMP;D3DPP, &g_pd3ddevice)) {return e_fail;} Device state would normally is set Herereturn S_OK;} -----------------------------------------------------------------------------//Name:cleanup ()//Desc:releases All previously initialized objects//----------------------------------------------------------------------------- VOID Cleanup () {if (g_pd3ddevice! = null) g_pd3ddevice->release (); if (g_pd3d! = null) g_pd3d->release ();} //-----------------------------------------------------------------------------//Name:render ()//Desc:draws the scene//-------------------------------------------------------------------------- ---VOID Render () {if (NULL = = g_pd3ddevice) return;//Clear the backbuffer to a blue colorg_pd3ddevice->clear (0, NULL, D3 Dclear_target, D3dcolor_xrgb (0, 0, 255), 1.0f, 0);//Begin The Sceneif (SUCCEEDED (G_pd3ddevice->beginscene ())) {// Rendering of Scene objects can happen here//End the Sceneg_pd3ddevice->endscene ();} Present the backbuffer contents to the displayg_pd3ddevice->present (null, NULL, NULL, NULL);} -----------------------------------------------------------------------------//Name:msgproc ()//Desc:the Window ' s message handler//-----------------------------------------------------------------------------LRESULT WINAPI Msgproc (HWND hwnd, UINT MSG, WPARAM WPARAM, LPARAM LPARAM) {switch (msg) {case wm_destroy:cleanup (); PostQuitMessage (0); return 0;case Wm_paint:render (); ValidateRect (HWnd, NULL); return 0;} Return DefWindowProc (HWnd, MSG, WParam, LParam);} -----------------------------------------------------------------------------//Name:wwinmain ()//Desc:the Application ' s entry point//-----------------------------------------------------------------------------INT WINAPI wWinMain (hinstance hInst, hinstance, LPWStr, INT) {unreferenced_parameter (hInst);//Register the window Classwndclassex WC ={sizeof (wndclassex), CS_CLASSDC, Msgproc, 0L, 0l,getmodulehandle (null), NULL, NULL, NULL, NULL, "D3D T Utorial ", NULL}; RegisterClassEx (&AMP;WC);//Create the application ' s windowhwnd hWnd = CreateWindow ("D3d Tutorial", "D3D Tutorial 01:crea Tedevice ", Ws_overlappedwindow, +, +, 300,null, NULL, wc.hinstance, NULL);//Initialize Direct3dif (SUCCEEDED ( INITD3D (hwnd)) {//Show the Windowshowwindow (hwnd, Sw_showdefault); UpdateWindow (hWnd);//Enter the message loopmsg msg;while (GetMessage (&msg, NULL, 0, 0)) {translatemessage (&msg) ;D ispatchmessage (&msg);}} Unregisterclass ("D3d Tutorial", wc.hinstance); return 0;}

The results of the operation are as follows:


Summary: The help document is still very good, write very detailed, also helps to exercise our English level! Ha ha!



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Directx3d development of the first DIRECTX3D project

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.