#include <d3d9.h>
#pragma warning( disable : 4996 ) // disable deprecated warning
#include <strsafe.h>
#pragma warning( default : 4996 )
#include <d3dx9math.h>
bool InitD3D(HWND hWnd, bool fullscreen);
void RenderScene();
void ShutDown();
bool InitializeObjects();
LPDIRECT3D9 g_D3D = NULL;
LPDIRECT3DDEVICE9 g_D3DDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 g_VertexBuffer = NULL; //顶点缓存接口
LPDIRECT3DINDEXBUFFER9 g_pIndexBuf = NULL; //索引缓存接口
struct CUSTOMVERTEX
{
FLOAT _x, _y, _z; // �������
DWORD _color; // ��������ɫ
CUSTOMVERTEX(FLOAT x, FLOAT y, FLOAT z, DWORD color)
: _x(x), _y(y), _z(z), _color(color) {}
};
#define D3DFVF_VERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)
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;
default:
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevInst, LPSTR cmdLine, int show)
{
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0, 0, hInst, NULL, NULL, NULL, NULL, L"UGPDX", NULL };
RegisterClassEx(&wc);
HWND hWnd = CreateWindow(L"UGPDX", L"Blank D3D Window", WS_OVERLAPPEDWINDOW, 100, 100, 640, 480, NULL, NULL, wc.hInstance, NULL);
if (InitD3D(hWnd, false))
{
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
正方体矩阵变换
最新推荐文章于 2024-10-09 10:03:30 发布
本文介绍了Direct3D中D3DFVF_XYZ和D3DFVF_XYZRHW两种顶点格式的区别。D3DFVF_XYZ用于定义3D空间中的顶点位置,而D3DFVF_XYZRHW则表示顶点已在屏幕坐标系中,用于2D渲染,其中RHW是 Homogeneous W 的倒数,用于雾化和裁剪计算。使用D3DFVF_XYZRHW时,系统不进行视图、投影和世界变换,直接进行光栅化操作,但z值可能不起作用。
摘要由CSDN通过智能技术生成