利用vc++做的第一个程序,就出错了。(关于DirectX)

minsnake 2003-10-09 03:41:49
我找一篇文章抄了一段程序,但是一编译就出错谁能给我解释一下:

我吧那段文章已经摘录下来。(我就是找他做的)

Okay, that’s enough theory lets get started. Follow the step-by-step guide below to create your first DirectX Graphics project.

1. In Visual C++ create a new Win32 Application.
a. File > New
b. From the Projects tab select Win32 Application
c. Enter a name for your project such as “DX Project 1”
d. Select a folder for the location of your source code files
e. Click Next
f. Select the empty project option.
g. Click Finish
2. Make sure that your project settings are correct.
a. Project > Settings...
b. On the Link tab, make sure that "d3d8.lib" is in the list of Object/Library Modules. If it isn’t simply type it in.
3. Make sure that your search paths are correct.
a. Tools > Options > Directories Tab
b. In the "Show directories for" drop-down, select "include files".
c. If it does not exist already, add the following path: <SDK INSTALL PATH>\include.
d. Make sure that this path is at the top of the list by clicking on the up arrow button (if needed).
e. In the "Show directories for" drop-down, select "library files".
f. If it does not exist already, add the following path: <SDK INSTALL PATH>\lib.
g. Make sure that this path is at the top of the list by clicking on the up arrow button (if needed).
4. Add the source code.
a. File > New
b. From the Files tab, select C++ Source File
c. Enter a filename such as “Main.cpp”
d. Copy the code segment below, and then paste it into your new file.
5. Build and Run the program.
a. Press F7 to build your project
b. Press F5 to run
...全文
84 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaoha2003 2003-10-09
  • 打赏
  • 举报
回复

to mfc168(闶阆


这个问题我都遇到很多次了,也解决了很多次了,这样设置:

project->settings->c/c++ ->category ->Precompiled Headers-> 选择 Not using...
我不懂为何要这样做?回答一下嘛?


minsnake 2003-10-09
  • 打赏
  • 举报
回复
按照mfc168(闶阆)大虾的方法搞定了!谢谢mfc168(闶阆) ,在这里也感谢各位的热情,特别是xadave(xadave) ,散分了!
minsnake 2003-10-09
  • 打赏
  • 举报
回复
我的确是想用Direct3D,但是我安装DirectX SDK了!我安装的是9.0,而程序用的是8.0(不知道是不是这个错误?),我看到我安装目录里面C:\DXSDK\Lib有个d3d8.lib的文件,并且C:\DXSDK\Include里面也有d3d8.h


还有,请问你的e_mail地址是???
mfc168 2003-10-09
  • 打赏
  • 举报
回复
这个问题我都遇到很多次了,也解决了很多次了,这样设置:

project->settings->c/c++ ->category ->Precompiled Headers-> 选择 Not using...
xadave 2003-10-09
  • 打赏
  • 举报
回复
你做的应该是tutorial for using Direct3D。
出现这个错误,可能跟你没有安装DirectX SDK或者D3D8.H文件版本不对,抑或你第3步指定的include path不对。
你可以到MS Web download DirectX SDK,或者给我mail,我给你D3D8.H & D3D8.LIB.
minsnake 2003-10-09
  • 打赏
  • 举报
回复
程序应该是没有错的!肯定是我那里设置出错了,大家看的时候其实不用看程序!
yaoha2003 2003-10-09
  • 打赏
  • 举报
回复
UP
minsnake 2003-10-09
  • 打赏
  • 举报
回复
我是这样设置的,你替我看看有没有错!(我不知道这里是不是搞错了)(在线等待)

project>settings....>link>object/library modules: C:\DXSDK\Lib\d3d8.lib

其他的设置都是按照这里来的(这里写得比较清楚,应该没错):
3. Make sure that your search paths are correct.
a. Tools > Options > Directories Tab
b. In the "Show directories for" drop-down, select "include files".
c. If it does not exist already, add the following path: <SDK INSTALL PATH>\include.
d. Make sure that this path is at the top of the list by clicking on the up arrow button (if needed).
e. In the "Show directories for" drop-down, select "library files".
f. If it does not exist already, add the following path: <SDK INSTALL PATH>\lib.
g. Make sure that this path is at the top of the list by clicking on the up arrow button (if needed).
lysbeyondlys 2003-10-09
  • 打赏
  • 举报
回复
沒頭文件集啊,好兄
dreamy 2003-10-09
  • 打赏
  • 举报
回复
内容太长,没看。
就看了错误信息,一般出现precompiled header错误都是因为没有包括StdAfx.h文件引起的。
阿甘 2003-10-09
  • 打赏
  • 举报
回复
看看d3d8.h(以及其它相关文件)在默认路径里面吗?
minsnake 2003-10-09
  • 打赏
  • 举报
回复
guankaifu(疯牛) 先生说的能明白一点吗?(我实在是新手)
smxx 2003-10-09
  • 打赏
  • 举报
回复
同病相怜,
我做的第一个项目也出错了
不知道怎么改
guankaifu 2003-10-09
  • 打赏
  • 举报
回复
你把用到的头文件加到主程序的头文件里就好了
minsnake 2003-10-09
  • 打赏
  • 举报
回复
然后这是我出错的信息:(希望哪个高手不吝赐教)

Compiling...
main.cpp
f:\minlw\d3dst\dx project 1\main.cpp(166) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.

DX Project 1.exe - 1 error(s), 0 warning(s)
minsnake 2003-10-09
  • 打赏
  • 举报
回复
上面是如何设置的文字,下面是我抄的程序:

#include <d3d8.h>

LPDIRECT3D8 g_pD3D = NULL;
LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;

HRESULT InitialiseD3D(HWND hWnd)
{
//First of all, create the main D3D object. If it is created successfully we
//should get a pointer to an IDirect3D8 interface.
g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
if(g_pD3D == NULL)
{
return E_FAIL;
}

//Get the current display mode
D3DDISPLAYMODE d3ddm;
if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
{
return E_FAIL;
}

//Create a structure to hold the settings for our device
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));

//Fill the structure.
//We want our program to be windowed, and set the back buffer to a format
//that matches our current display mode
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
d3dpp.BackBufferFormat = d3ddm.Format;

//Create a Direct3D device.
if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp,
&g_pD3DDevice)))
{
return E_FAIL;
}

return S_OK;
}

void Render()
{
if(g_pD3DDevice == NULL)
{
return;
}

//Clear the back buffer to a green colour
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);

//Begin the scene
g_pD3DDevice->BeginScene();

//Rendering of our game objects will go here

//End the scene
g_pD3DDevice->EndScene();

//Filp the back and front buffers so that whatever has been rendered on the
//back buffer will now be visible on screen (front buffer).
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}

void CleanUp()
{
if(g_pD3DDevice != NULL)
{
g_pD3DDevice->Release();
g_pD3DDevice = NULL;
}

if(g_pD3D != NULL)
{
g_pD3D->Release();
g_pD3D = NULL;
}
}

void GameLoop()
{
//Enter the game loop
MSG msg;
BOOL fMessage;

PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);

while(msg.message != WM_QUIT)
{
fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);

if(fMessage)
{
//Process message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
//No message to process, so render the current scene
Render();
}

}
}

//The windows message handler
LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_KEYUP:
switch (wParam)
{
case VK_ESCAPE:
//User has pressed the escape key, so quit
DestroyWindow(hWnd);
return 0;
break;
}
break;

}

return DefWindowProc(hWnd, msg, wParam, lParam);
}

//Application entry point
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
//Register the window class
WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"DX Project 1", NULL};
RegisterClassEx(&wc);

//Create the application's window
HWND hWnd = CreateWindow("DX Project 1", "www.andypike.com: Tutorial 1",
WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
GetDesktopWindow(), NULL, wc.hInstance, NULL);

//Initialize Direct3D
if(SUCCEEDED(InitialiseD3D(hWnd)))
{
//Show our window
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);

//Start game running: Enter the game loop
GameLoop();
}

CleanUp();

UnregisterClass("DX Project 1", wc.hInstance);

return 0;
}

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧