求助:DirectX 8.0 源码调试

proof1 2020-12-15 03:16:06
学一本书《Direct3D中的2D编程》,书中只写理论,没有实验操作步骤。
第一章第一节的源码,就没有通过。

实验配置:
Windows7、DX8_SDK
Cfree5.0,设置了Include和Library目录。源码未通过。
VC++6.0,设置了Include和Library目录。源码未通过。

网上看到以下片段:
“第二步:添加链接所需的库文件,如dxguid.lib、d3d9.lib、d3dx9.lib等,……”

这一步骤我不懂,不知是否因为缺少这一步骤?针对DX8和本源码,该如何设置?

----------------------------------------------------------------------------------------
下载: 源码 +《Direct3D中的2D编程》PDF
https://download.csdn.net/download/u010971968/5882089

PDF在线阅读
https://ishare.iask.sina.com.cn/f/22639180.html

附源码Example1_1,所有源码可在上面链接下载

//Example1_1
//main.cpp
//Ernest Pazera
//04OCT2001
//TGO-01-C
//Libs: d3d8.lib

#include <windows.h> //include windows stuff
#include <stdio.h> //standard input/output
#include "D3D8.h" //include direct3d8 stuff

//constants
//window class name
const char* WINDOWCLASS = "3D42DGP" ;
//window title
const char* WINDOWTITLE = "Example 1.1 (TGO-01-C): Creating and Destroying an IDirect3D8 object" ;

//globals
//instance handle
HINSTANCE g_hInstance = NULL ;
//window handle
HWND g_hWnd = NULL ;
//IDirect3D8 pointer
IDirect3D8* g_pd3d = NULL ;

//function prototypes
//winmain
int WINAPI WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd ) ;
//window procedure
LRESULT CALLBACK TheWindowProc ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam ) ;
//initialization
void Prog_Init ( ) ;
//clean up
void Prog_Done ( ) ;


//window procedure
LRESULT CALLBACK TheWindowProc ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
//which message did we get?
switch ( uMsg )
{
case WM_DESTROY : //window being destroyed
{
//quit

PostQuitMessage ( 0 ) ;

//message handled, return 0

return ( 0 ) ;

} break ;
default: //all other messages, send to default handler
return ( DefWindowProc ( hWnd , uMsg , wParam , lParam ) ) ;
}
}

//winmain
int WINAPI WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd )
{
//grab instance handle
g_hInstance = hInstance ;

//redirect stderr and stdout output
freopen ( "stderr.txt" , "w" , stderr ) ;
freopen ( "stdout.txt" , "w" , stdout ) ;

//fill in window class
WNDCLASSEX wc ;
wc.cbClsExtra = 0 ; //no extra class information
wc.cbSize = sizeof ( WNDCLASSEX ) ; //size of structure
wc.cbWndExtra = 0 ; //no extra window information
wc.hbrBackground = ( HBRUSH ) GetStockObject ( BLACK_BRUSH ) ; //black brush
wc.hCursor = NULL ; //no cursor
wc.hIcon = NULL ; //no icon
wc.hIconSm = NULL ; //no small icon
wc.hInstance = g_hInstance ; //instance handle
wc.lpfnWndProc = TheWindowProc ; //window procedure
wc.lpszClassName = WINDOWCLASS ; //name of class
wc.lpszMenuName = NULL ; //no menu
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC ; //class styles

//register window class
RegisterClassEx ( &wc ) ;

//create window
g_hWnd = CreateWindowEx ( 0 , WINDOWCLASS , WINDOWTITLE , WS_OVERLAPPEDWINDOW , 0 , 0 , 320 , 240 , NULL , NULL , g_hInstance , NULL ) ;

//show the window
ShowWindow ( g_hWnd , nShowCmd ) ;

//initialization
Prog_Init ( ) ;

MSG msg ;
//message pump
for ( ; ; )
{
//check for a message
if ( PeekMessage( &msg , NULL , 0 , 0 , PM_REMOVE ) )
{
//message exists

//check for quit message
if ( msg.message == WM_QUIT ) break ;

//translate the message
TranslateMessage ( &msg ) ;

//dispatch the message
DispatchMessage ( &msg ) ;
}
}

//clean up
Prog_Done ( ) ;

//exit
return ( msg.wParam ) ;
}

//initialization
void Prog_Init ( )
{
//create the IDirect3D8 object
g_pd3d = Direct3DCreate8 ( D3D_SDK_VERSION ) ;

//error check
if ( g_pd3d )
{
//success
fprintf ( stdout , "IDirect3D8 object created successfully.\n" ) ;
}
else
{
//failure
fprintf ( stderr , "IDirect3D8 object creation failed.\n" ) ;
}
}

//clean up
void Prog_Done ( )
{
//safe release of IDirect3D8 object
if ( g_pd3d )
{
//release
g_pd3d->Release ( ) ;

//set to null
g_pd3d = NULL ;

//report action
fprintf ( stdout , "IDirect3D8 object released.\n" ) ;
}
}


...全文
61166 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
superdai 2021-01-08
  • 打赏
  • 举报
回复
你的问题在于对vc编译器的使用经验,你要先学会怎么编译,如何配置工程,才有可能一步步学会复杂工程的调试。
Directx8.0 SDK : 坦克战 v2.0 基本操作: A/菜单操作: 菜单选择:W、S 或 上、下方向键 菜单确定:回车 B/游戏操作: 方向控制:W、A、S、D或方向键 发射子弹:空格 暂停游戏:回车 退出到菜单:ESC 版本升级说明: 1.可以暂停游戏了。 2.使用DirectxSound提升了声音品质,解决了老版本不能混音的缺点。 3.添加了敌方的AI,敌人撞墙后会搜寻追踪玩家。 4.物品增加到6个,玩家和敌人都可以吃到随机出现的物品。 5.关卡增加到了十关。 6.增加了地图编辑器,可以自己编辑地图和运行。 7.重写了爆炸的即时粒子系统,模拟爆炸时弹片的飞旋效果。 游戏物品说明: 1.钢盔:可以暂时不损血(除却被炸弹炸到)。 2.坦克:可以增加1点血。 3.时钟:暂时冻结坦克的移动。 4.星型:增加子弹和坦克移动速度(累计的)。 5.炸弹:随机轰炸地图的任意地点,被炸到的话,对方损失1点血。 6.船: 可以过河。 补充: 每关开始将重设坦克属性,但玩家坦克的血将不补充。 代码说明: 1.重新编写了代码。 2.编程语言:使用VC++6.0 + Directx8.0 SDK。 3.用DirectxDraw实现基本绘图,用DirectxInput 实现游戏基本操作 4.首次学习并使用DirectxSound组件实现了混音效果。 5.尝试封装了Directx的这三个重要组件。 5.本人为非专业编程人员,代码难免有的地方比较乱和不规范,望大家多多谅解! 问题: 1.游戏在不同的机器上运行会有不同的速度。如何让游戏在不同的机器上都有相对稳定的运行速度呢? 2.坦克爆炸时,一些坦克会暂时不显示,不能解决. 3.我方和对方坦克的碰撞检测是个难题,主要是测到碰撞后坦克倒退时有时会退出边界或穿墙而引起错误。所以去除了。

456

社区成员

发帖
与我相关
我的任务
社区描述
其它游戏引擎
社区管理员
  • 其它游戏引擎社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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