2014-05-08 33 views
0

好的,这里是我的源代码,这是我在线创建第一个DX窗口的教程。所以我通过输入它复制它来尝试和记住更好。无论如何,我遇到的问题是,我无法让程序在VS中生成,我试图将链接器子系统更改为Windows,没有工作。我无法在VS 2013中创建我的d3d窗口

ERROR收到

1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol [email protected] referenced in function ___tmainCRTStartup 
1>e:\documents\visual studio 2013\Projects\Project1\Debug\Project1.exe : fatal error LNK1120: 1 unresolved externals 

继承人的外部链接的代码https://gist.github.com/bANNji/24ebedaf5a72f2003d29

//include the basic windows header files and the Direct3dD Header file 
#include <windows.h> 
#include <windowsx.h> 
#include <d3d9.h> 

// Include the DIrect3D library file 
#pragma comment (lib, "d3d9.lib") 

// global declarations 
LPDIRECT3D9 d3d; // The pointer to our Direct3D Interface 
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class 

// functiuon prototypes 
void initD3D(HWND hWnd); // Sets up and initializes Direct3D 
void render_frame(void); // Renders a single frame 
void cleanD3D(void);  // Closes Direct3D and releases memory 

// The window proc function prototype 
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 

// this function initializes and prepares direct3d for use 
void initD3D(HWND hWnd) 
{ 
    d3d = Direct3DCreate9(D3D_SDK_VERSION);  // Create the Direct3D Interface 
    D3DPRESENT_PARAMETERS d3dpp; // create a stuct to hold verious device information 
    ZeroMemory(&d3dpp, sizeof(d3dpp));  //Clear out the stuct for usee 
    d3dpp.Windowed = TRUE;  // Program windowed not full screen 
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Discard old frames 
    d3dpp.hDeviceWindow = hWnd;  // Set the window to be used by Direct3D 

    // Create a deviced calss using this information and information from the d3dpp stuct 
    d3d->CreateDevice(D3DADAPTER_DEFAULT, 
     D3DDEVTYPE_HAL, 
     hWnd, 
     D3DCREATE_SOFTWARE_VERTEXPROCESSING, 
     &d3dpp, 
     &d3ddev); 
} 

// THE FUN STUFF 

// this is the function used to render a single frame 
void render_frame(void) 
{ 
    // clear the window to a deep blue 
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); 

    d3ddev->BeginScene();  // this begins the 3D Scene 

    // do 3D Rendering on the back buffer here... 

    d3ddev->EndScene();   // ends the 3D Scene 

    d3ddev->Present(NULL, NULL, NULL, NULL);  // This displays the created frame 
} 

// THis is the function that cleans up Direct3D and COM 
void cleanD3D(void) 
{ 
    d3ddev->Release();  // close and release the 3D Device 
    d3d->Release();  //Close and release Direct3D 
} 
+0

请在您的文章中的错误。 – Stefan

+0

需要为winProc定义什么,同时本教程还说“HWND hFocusWindow, 这是我们窗口的句柄,当我们传递WinMain()的值时,我们可以把'hWnd'放在这里。我不记得在做什么,也没有告诉我该怎么做。即时消息并不确定WinMain使用dx需要什么,或者与正常情况不同。 – bannji

+0

WinMain不是Direct3D的一部分。这是您的Windows应用程序的入口点。您使用Win32 API来创建窗口。然后在初始化Direct3D的presentparams时使用该窗口的句柄(HWND)。 Direct3D需要你的窗口,但你的窗口不需要Direct3D。 – derpface

回答

1

的错误意味着正是它说:你没有WinMain函数。我强烈建议你先学习如何在使用Direct3D之前使用Win32 API自行创建和操作窗口。它在MSDN上有很大的记录,并且很容易掌握。下面是示例代码(不完全,很明显),以帮助给你一个参考点快速混乱上手:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
{ 
    HRESULT hr = CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); 

    WNDCLASSEX wndClass; 
    ZeroMemory(&wndClass,sizeof(wndClass)); 
    wndClass.cbSize   = sizeof(wndClass); 
    wndClass.cbClsExtra  = 0; 
    wndClass.cbWndExtra  = 0; 
    wndClass.hbrBackground = NULL; 
    wndClass.hCursor  = LoadCursor(hInstance,LoadCursor(NULL,IDC_ARROW); 
    wndClass.hIcon   = LoadIcon(hInstance,LoadIcon(NULL,IDI_APPLICATION); 
    wndClass.hIconSm  = LoadIcon(hInstance,LoadIcon(NULL,IDI_APPLICATION); 
    wndClass.hInstance  = hInstance; 
    wndClass.lpszMenuName = NULL; 
    wndClass.lpfnWndProc = winProc; 
    wndClass.lpszClassName = "derp"; 
    wndClass.style   = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; 
    RegisterClassEx(&wndClass); 

    RECT win = {0,0,width,height}; 
    AdjustWindowRectEx(&win,flags,FALSE,WS_EX_APPWINDOW); 
    int winWidth = win.right - win.left; 
    int winHeight = win.bottom - win.top; 

    hWnd = CreateWindowEx( WS_EX_APPWINDOW, 
     "derp", 
     "derpderp", 
     flags | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 
     GetSystemMetrics(SM_CXSCREEN)/2 - width/2, 
     GetSystemMetrics(SM_CYSCREEN)/2 - height/2, 
     winWidth, 
     winHeight, 
     HWND_DESKTOP, 
     NULL, 
     hInstance, 
     NULL 
     ); 

    SetWindowPos( hWnd, 
     HWND_NOTOPMOST, 
     (GetSystemMetrics(SM_CXSCREEN)/2) - (winWidth/2), 
     (GetSystemMetrics(SM_CYSCREEN)/2) - (winHeight/2), 
     winWidth, 
     winHeight, 
     SWP_SHOWWINDOW 
     ); 

    ShowWindow(hWnd,nCmdShow); 
    UpdateWindow(hWnd); 

/* Do your other stuff here */ 

    return 0; 
} 

而且Winproc传的定义:

LRESULT CALLBACK App::WinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) 
{ 
    switch(uMsg) 
    { 
// NOTE: Obviously you'd need only those that matter to you, and you'd need to fill them in 
    case WM_KEYUP: 
    case WM_KEYDOWN: 
    case WM_CHAR: 
    case WM_LBUTTONDOWN: 
    case WM_LBUTTONUP: 
    case WM_LBUTTONDBLCLK: 
    case WM_RBUTTONDOWN: 
    case WM_RBUTTONDBLCLK: 
    case WM_RBUTTONUP: 
    case WM_MOUSEMOVE: 
    case WM_SYSKEYDOWN: 
    case WM_MOUSEWHEEL: 
    case WM_ACTIVATE: 
    case WM_SYSKEYUP: 
    case WM_SYSCOMMAND: 
    case WM_CREATE: 
    case WM_CLOSE: 
    case WM_DESTROY: 
     App::GetInstance()->Shutdown(); 
     PostQuitMessage(0); 
     break; 
    default: 
     return DefWindowProc(hWnd,uMsg,wParam,lParam); 
    } 

    return 0; 
}