VS2008 direct9.0 开发平台搭建————第一个D3D程序
来源:互联网 发布:乐视2用不了移动数据 编辑:程序博客网 时间:2024/05/22 12:27
VS2008 direct9.0 开发平台搭建————第一个D3D程序
一.VS2008中DirectX 9.0的配置方法
1. 在VS2008里面选择: ”工具”-->”选项”-->”项目和解决方案”-->”vc++目录”
2. 在”显示以下内容的目录”下的下拉框中选择"包含文件"中插入新行输入
选择“E:/Include”
3.在”显示以下内容的目录”下的下拉框中选择”库文件”插入新行并输入
”E:/Lib/x86”
( 没有双引号,具体看你的DirectX安装目录)
二.测试程序:
1. 平台:windows XP direct9.0 VS2008
2. 打开 vs2008 选择新建项目 ->win32项目 ,输入项目名,选择空项目。
向“源文件”添加文件main.cpp
输入以下代码:
- #include<d3d9.h>
- #include <tchar.h>
- #pragma comment(lib, "d3d9.lib")
- #pragma comment(lib, "d3dx9.lib")
- #define WINDOW_CLASS _T("UGPDX")
- #define WINDOW_NAME _T("Blank D3D Window")
- // Function Prototypes...
- bool InitializeD3D(HWND hWnd, bool fullscreen);
- void RenderScene();
- void Shutdown();
- // Direct3D object and device.
- LPDIRECT3D9 g_D3D = NULL;
- LPDIRECT3DDEVICE9 g_D3DDevice = NULL;
- LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- break;
- case WM_KEYUP:
- if(wParam == VK_ESCAPE) PostQuitMessage(0);
- break;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevhInst, LPSTR cmdLine, int show)
- {
- // Register the window class
- WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
- GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
- WINDOW_CLASS, NULL };
- RegisterClassEx(&wc);
- // Create the application's window
- HWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME, WS_OVERLAPPEDWINDOW,
- 100, 100, 640, 480, GetDesktopWindow(), NULL,
- wc.hInstance, NULL);
- // Initialize Direct3D
- if(InitializeD3D(hWnd, false))
- {
- // Show the window
- ShowWindow(hWnd, SW_SHOWDEFAULT);
- UpdateWindow(hWnd);
- // Enter the message loop
- MSG msg;
- ZeroMemory(&msg, sizeof(msg));
- while(msg.message != WM_QUIT)
- {
- if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- else
- RenderScene();
- }
- }
- // Release any and all resources.
- Shutdown();
- // Unregister our window.
- UnregisterClass(WINDOW_CLASS, wc.hInstance);
- return 0;
- }
- bool InitializeD3D(HWND 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.Windowed = FALSE;
- d3dpp.BackBufferWidth = 640;
- d3dpp.BackBufferHeight = 480;
- }
- else
- d3dpp.Windowed = 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;
- }
- void RenderScene()
- {
- // Clear the backbuffer.
- g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
- // Begin the scene. Start rendering.
- g_D3DDevice->BeginScene();
- // End the scene. Stop rendering.
- g_D3DDevice->EndScene();
- // Display the scene.
- g_D3DDevice->Present(NULL, NULL, NULL, NULL);
- }
- void Shutdown()
- {
- if(g_D3DDevice != NULL) g_D3DDevice->Release();
- if(g_D3D != NULL) g_D3D->Release();
- g_D3DDevice = NULL;
- g_D3D = NULL;
- }
安装错误解决:
问题1..
d3d002/d3d002/main.cpp(46) : error C3861: “_T”: 找不到标识符
解决方法:加载 头文件:#include <tchar.h>
- VS2008 direct9.0 开发平台搭建————第一个D3D程序
- VS2008 direct9.0 ————Lines划线
- 第一个D3D程序
- 第一个D3D程序
- 从0到第一个D3D程序
- 搭建Window环境下android NDK开发环境——编译第一个NDK程序
- 【一】cocos2dx开发环境的搭建,第一个程序——HelloWorld
- Linux下C++的编程——开发环境搭建与第一个程序
- Linux下C++的编程——开发环境搭建与第一个程序
- angularjs学习笔记一——了解angularjs、开发环境搭建、第一个angularjs程序
- Mybatis第一个程序搭建————2
- D3D学习笔记(我的第一个D3D程序)
- D3D学习笔记(我的第一个D3D程序)
- D3D学习笔记(我的第一个D3D程序)
- vs2008+DirectX9.0 第一个程序
- 《Android开发从零开始》——3.第一个Android程序
- IOS开发——01_第一个OC程序
- DJI SDK开发——第一个程序
- for /while 循环
- oracle 1
- oracle 2
- oracle 3
- 使用RealViewMDK时常见的问题(1)
- VS2008 direct9.0 开发平台搭建————第一个D3D程序
- 学习
- 从搜索的角度看互联网
- Android tabhost
- Android wifi锁
- 2-16 malloc(1)
- 【转】Java类的初始化顺序 (静态变量、静态初始化块、变量、初始化块、构造器)
- fck不能显示编辑框,显示源代码
- Cmos checksum error-Defaults loaded