游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2943|回复: 4

各位帮帮忙,这玩意弄的我快哭了!!

[复制链接]

52

主题

103

帖子

103

积分

注册会员

Rank: 2

积分
103
发表于 2009-7-16 14:34:00 | 显示全部楼层 |阅读模式
就这个D3D9的初始化程序,我自己模仿WINDOWS游戏编程大师技巧里的DDRAW的初始化写的,但为什么编译的时候总是提示
E:\work space\d3din\fasdf.cpp(49) : error C2440: 'initializing' : cannot convert from 'const int' to 'struct _D3DCAPS9'
        No constructor could take the source type, or constructor overload resolution was ambiguous
E:\work space\d3din\fasdf.cpp(50) : error C2440: 'initializing' : cannot convert from 'const int' to 'struct _D3DPRESENT_PARAMETERS_'
        No constructor could take the source type, or constructor overload resolution was ambiguous
我也添加了d3d9x.lib这个库文件啊,另外我还把dxd9这个文件也包含进去了,应该不是却文件吧,各位帮帮我,真的莫法了,谢谢!!!


  1. #define WIN32_LEAN_AND_MEAN  // just say no to MFC
  2. #define STRICT
  3. #define INITGUID // make sure directX guids are included

  4. #include <windows.h>   // include important windows stuff
  5. #include <windowsx.h>
  6. #include <mmsystem.h>
  7. #include <iostream.h> // include important C/C++ stuff
  8. #include <conio.h>
  9. #include <stdlib.h>
  10. #include <malloc.h>
  11. #include <memory.h>
  12. #include <string.h>
  13. #include <stdarg.h>
  14. #include <stdio.h>
  15. #include <math.h>
  16. #include <io.h>
  17. #include <fcntl.h>

  18. #include <d3dx9.h> // include directdraw
  19. #include <d3d9.h>

  20. // DEFINES ////////////////////////////////////////////////

  21. // defines for windows
  22. #define WINDOW_CLASS_NAME "WINCLASS1"

  23. // default screen size
  24. #define SCREEN_WIDTH    640  // size of screen
  25. #define SCREEN_HEIGHT   480
  26. #define SCREEN_BPP      16    // bits per pixel



  27. #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
  28. #define KEYUP(vk_code)   ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)


  29. // GLOBALS ////////////////////////////////////////////////
  30. HWND      hwnd_app = NULL;
  31. HINSTANCE hinstance_app      = NULL;
  32. HRESULT hr = 0;
  33. // direct3d stuff
  34. IDirect3DDevice9*     Device       = 0;
  35. D3DCAPS9              caps         = NULL;   
  36. D3DPRESENT_PARAMETERS d3dpp        = NULL;
  37. IDirect3D9*           d3d9         = NULL;   
  38. int vp;


  39. // FUNCTIONS //////////////////////////////////////////////
  40. LRESULT CALLBACK WindowProc(HWND hwnd,
  41.                                                     UINT msg,
  42.                             WPARAM wparam,
  43.                             LPARAM lparam)
  44. {
  45. // this is the main message handler of the system
  46. PAINTSTRUCT                ps;                // used in WM_PAINT
  47. HDC                                hdc;        // handle to a device context


  48. // what is the message
  49. switch(msg)
  50.         {       
  51.         case WM_CREATE:
  52.         {
  53.                 // do initialization stuff here
  54.         // return success
  55.                 return(0);
  56.                 } break;
  57.    
  58.         case WM_PAINT:
  59.                 {
  60.                 // simply validate the window
  61.                hdc = BeginPaint(hwnd,&ps);         
  62.         
  63.         // end painting
  64.         EndPaint(hwnd,&ps);

  65.         // return success
  66.                 return(0);
  67.                    } break;

  68.         case WM_DESTROY:
  69.                 {

  70.                 // kill the application, this sends a WM_QUIT message
  71.                 PostQuitMessage(0);

  72.         // return success
  73.                 return(0);
  74.                 } break;

  75.         default:break;

  76.     } // end switch

  77. // process any messages that we didn't take care of
  78. return (DefWindowProc(hwnd, msg, wparam, lparam));

  79. } // end WinProc

  80. ///////////////////////////////////////////////////////////

  81. int Game_Main(void *parms = NULL, int num_parms = 0)
  82. {

  83. if (KEYDOWN(VK_ESCAPE))
  84.    SendMessage(hwnd_app,WM_CLOSE,0,0);


  85. return(1);

  86. } // end Game_Main

  87. ////////////////////////////////////////////////////////////

  88. int Game_Init(void *parms = NULL, int num_parms = 0)
  89. {


  90. d3d9=Direct3DCreate9(D3D_SDK_VERSION);


  91. d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&caps);


  92. if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
  93.         vp=D3DCREATE_HARDWARE_VERTEXPROCESSING;
  94. else
  95.         vp=D3DCREATE_SOFTWARE_VERTEXPROCESSING;


  96. d3dpp.BackBufferWidth=SCREEN_WIDTH;
  97. d3dpp.BackBufferHeight=SCREEN_HEIGHT;
  98. d3dpp.BackBufferFormat=D3DFMT_R5G6B5;
  99. d3dpp.BackBufferCount=1;
  100. d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE;
  101. d3dpp.MultiSampleQuality=0;
  102. d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
  103. d3dpp.hDeviceWindow=hwnd_app;
  104. d3dpp.Windowed=true;
  105. d3dpp.EnableAutoDepthStencil=true;
  106. d3dpp.AutoDepthStencilFormat=D3DFMT_D24S8;
  107. d3dpp.Flags=0;
  108. d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT;
  109. d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;

  110. hr=d3d9->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd_app,vp,&d3dpp,&Device);
  111. if(FAILED(hr))
  112. {
  113.         d3dpp.AutoDepthStencilFormat=D3DFMT_D16;

  114.         hr=d3d9->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd_app,vp,&d3dpp,&Device);
  115. }


  116. return(1);

  117. } // end Game_Init

  118. /////////////////////////////////////////////////////////////

  119. int Game_Shutdown(void *parms = NULL, int num_parms = 0)
  120. {

  121. if (d3d9)
  122.    {
  123.    d3d9->Release();
  124.    d3d9 = NULL;
  125.    }

  126. return(1);

  127. } // end Game_Shutdown

  128. // WINMAIN ////////////////////////////////////////////////
  129. int WINAPI WinMain(        HINSTANCE hinstance,
  130.                                         HINSTANCE hprevinstance,
  131.                                         LPSTR lpcmdline,
  132.                                         int ncmdshow)
  133. {

  134. WNDCLASSEX winclass; // this will hold the class we create
  135. HWND           hwnd;         // generic window handle
  136. MSG                   msg;                 // generic message
  137. HDC        hdc;      // graphics device context

  138. // first fill in the window class stucture
  139. winclass.cbSize         = sizeof(WNDCLASSEX);
  140. winclass.style                        = CS_DBLCLKS | CS_OWNDC |
  141.                           CS_HREDRAW | CS_VREDRAW;
  142. winclass.lpfnWndProc        = WindowProc;
  143. winclass.cbClsExtra                = 0;
  144. winclass.cbWndExtra                = 0;
  145. winclass.hInstance                = hinstance;
  146. winclass.hIcon                        = LoadIcon(NULL, IDI_APPLICATION);
  147. winclass.hCursor                = LoadCursor(NULL, IDC_ARROW);
  148. winclass.hbrBackground        = (HBRUSH)GetStockObject(BLACK_BRUSH);
  149. winclass.lpszMenuName        = NULL;
  150. winclass.lpszClassName        = WINDOW_CLASS_NAME;
  151. winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

  152. // save hinstance in global
  153. hinstance_app = hinstance;

  154. // register the window class
  155. if (!RegisterClassEx(&winclass))
  156.         return(0);

  157. // create the window
  158. if (!(hwnd = CreateWindowEx(NULL,                  // extended style
  159.                             WINDOW_CLASS_NAME,     // class
  160.                                                     "DirectDraw Initialization Demo", // title
  161.                                                     WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  162.                                                      0,0,          // initial x,y
  163.                                                     400,300,  // initial width, height
  164.                                                     NULL,          // handle to parent
  165.                                                     NULL,          // handle to menu
  166.                                                     hinstance,// instance of this application
  167.                                                     NULL)))        // extra creation parms
  168. return(0);

  169. // save main window handle
  170. hwnd_app = hwnd;

  171. // initialize game here
  172. Game_Init();

  173. // enter main event loop
  174. while(TRUE)
  175.         {
  176.     // test if there is a message in queue, if so get it
  177.         if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  178.            {
  179.            // test if this is a quit
  180.        if (msg.message == WM_QUIT)
  181.            break;
  182.        
  183.            // translate any accelerator keys
  184.            TranslateMessage(&msg);

  185.            // send the message to the window proc
  186.            DispatchMessage(&msg);
  187.            } // end if
  188.    
  189.        // main game processing goes here
  190.        Game_Main();
  191.       
  192.         } // end while

  193. // closedown game here
  194. Game_Shutdown();

  195. // return to Windows like this
  196. return(msg.wParam);

  197. } // end WinMain
复制代码

4

主题

137

帖子

311

积分

中级会员

Rank: 3Rank: 3

积分
311
发表于 2009-7-16 16:07:00 | 显示全部楼层

Re:各位帮帮忙,这玩意弄的我快哭了!!

初始化类型不匹配。。
这两个都是结构体。。NULL 的定义式 define NULL 0

11

主题

650

帖子

651

积分

高级会员

Rank: 4

积分
651
发表于 2009-7-16 16:18:00 | 显示全部楼层

Re:各位帮帮忙,这玩意弄的我快哭了!!

模仿ddraw 我? 买本dx9的书又不少块肉 或者 sdk总可以吧

52

主题

103

帖子

103

积分

注册会员

Rank: 2

积分
103
 楼主| 发表于 2009-7-16 17:08:00 | 显示全部楼层

Re:各位帮帮忙,这玩意弄的我快哭了!!

DX9就看过,但他很多代码都是用类和C++写的,有些地方看不懂,不知道各位可不可以推荐几本入门的书?另外可不可以解释下SDK里面的代码,那几个FONT.H,D3DAPP.H之类的头文件是拿来干什么用的啊,谢谢!!

22

主题

309

帖子

353

积分

中级会员

Rank: 3Rank: 3

积分
353
QQ
发表于 2009-7-17 00:16:00 | 显示全部楼层

Re:各位帮帮忙,这玩意弄的我快哭了!!

这个错误和dx9没关系吧..
你是看不懂英文还是没学过C?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-19 18:13

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表