我是直接导演x 3d的人,对此一无所知。香港专业教育学院最近开始(观看)一系列教程(https://youtu.be/2NOgrpXks9A),甚至似乎无法对“ hello world”进行分类。当我从教程中运行该程序时,我的不会显示任何内容,而应该显示一个空窗口。虽然这个问题看起来很幼稚,但我不知道还有什么地方可以提出这样的问题...
[我在网上看到有人在宣告'winmain'这样的论点,例如:
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
...但是,这仍然行不通。我在x86的解决方案平台上运行:-Windows 10-visual studio 2019
#include <Windows.h>
int CALLBACK WinMain(
HINSTANCE hInstance, //allows us to load bitmmaps or icons
HINSTANCE hPrevInstance,//always 0
LPSTR LPcmdLine,//contains cmd line arguments
int nCmdShow)
{
const auto pClassName = "hw3dbutts";
//register window class
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof( wc );
wc.style = CS_OWNDC;
wc.lpfnWndProc = DefWindowProc;
wc.cbClsExtra = 0;
wc.cbClsExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = nullptr;
wc.hCursor = nullptr;
wc.hbrBackground = nullptr;
wc.lpszMenuName = nullptr;
wc.lpszClassName = nullptr;
RegisterClassEx(&wc);
//create window instance
HWND hWnd = CreateWindowEx(
0, pClassName,
"happy Hard Window",
WS_CAPTION | WS_MINIMIZE | WS_SYSMENU,
200, 200, 640, 480,
nullptr,nullptr,hInstance, nullptr
);
//show the damn window!
ShowWindow(hWnd, SW_SHOW);
while(true);
return 0;
}
似乎没有错误消息,因为没有错误,但是什么也没有输出,我想知道为什么...
问题是:while(true);
创建和显示窗口后,您的最小Win32程序需要包含“消息泵”:
// Main message loop
MSG msg = {};
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
由于您是Direct3D的新手,所以建议您查看GitHub上的Direct3D游戏模板。
您应该看一下DirectX Tool Kit,它是tutorials。互联网上的许多教程都过时了,并使用了legacy DirectX SDK,尽管它们都可以在适当的情况下使用。
请参见Anatomy of Direct3D 11 Create Device和Getting Started with Direct3D 11。