游戏开发论坛

 找回密码
 立即注册
搜索
12
返回列表 发新帖
楼主: BLACKNIAOR13

做游戏一定要DirectX吗 。windows GDI 行不

[复制链接]

67

主题

390

帖子

392

积分

中级会员

Rank: 3Rank: 3

积分
392
发表于 2010-12-26 21:07:00 | 显示全部楼层

Re:做游戏一定要DirectX吗 。windows GDI 行不

这要看你做的游戏类型,
现在很多商业棋牌类游戏都是用GDI做的,很少用DX,正如6楼所说的,一点压力没有
如果你不是做这种小型的游戏,而是做像仙剑1那种规模的游戏,那就得用DX了.

362

主题

3023

帖子

3553

积分

论坛元老

Rank: 8Rank: 8

积分
3553
发表于 2011-1-8 16:20:00 | 显示全部楼层

Re:做游戏一定要DirectX吗 。windows GDI 行不

gdi需要封装,否则根本不能用。(事实上ddraw最好也封装起来,起码是ddraw中需要借助于gdi的那些)

btw, 参考下我这里 http://bbs.gameres.com/showthread.asp?threadid=160055

btw2, 其实如果gdi能满足需要的话,可以用.NET,里头东西都是现成的。

362

主题

3023

帖子

3553

积分

论坛元老

Rank: 8Rank: 8

积分
3553
发表于 2011-1-8 16:28:00 | 显示全部楼层

Re:做游戏一定要DirectX吗 。windows GDI 行不

关于声音,对于wav一般用directsound(vb6里面的ds库异常方便),如果怕麻烦,或者需要播放非wav,那就用directshow,代码异常简单:

  1. class CMedia
  2. {
  3. private:
  4.         IGraphBuilder *m_pGraphBuilder;
  5.         IMediaControl *m_pMediaControl;
  6.         IMediaPosition *m_pMediaPosition;
  7.         IBasicAudio *m_pBasicAudio;
  8.         IBasicVideo *m_pBasicVideo;
  9.         IVideoWindow *m_pVideoWindow;
  10.         bool m_bPlaying;
  11. public:
  12.         CMedia()
  13.         {
  14.                 m_pGraphBuilder=null;
  15.                 m_pMediaControl=null;
  16.                 m_pMediaPosition=null;
  17.                 m_pBasicAudio=null;
  18.                 m_pBasicVideo=null;
  19.                 m_pVideoWindow=null;
  20.                 m_bPlaying=false;
  21.         }
  22. protected:
  23.         virtual ~CMedia(){}
  24. public:
  25.         bool IsOpened()
  26.         {
  27.                 return m_pGraphBuilder!=null;
  28.         }
  29.         bool IsPlaying()
  30.         {
  31.                 return m_bPlaying;
  32.         }
  33.         void Open(const std::wstring &filename)
  34.         {
  35.                 CoInitialize(NULL);
  36.                 CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,(void**)&m_pGraphBuilder);
  37.                 m_pGraphBuilder->QueryInterface(IID_IMediaControl,(void**)&m_pMediaControl);
  38.                 m_pGraphBuilder->QueryInterface(IID_IMediaPosition,(void**)&m_pMediaPosition);
  39.                 m_pGraphBuilder->QueryInterface(IID_IBasicAudio,(void**)&m_pBasicAudio);
  40.                 m_pGraphBuilder->QueryInterface(IID_IBasicVideo,(void**)&m_pBasicVideo);
  41.                 m_pGraphBuilder->QueryInterface(IID_IVideoWindow,(void**)&m_pVideoWindow);
  42.                 m_pMediaControl->RenderFile((BSTR)filename.c_str());
  43.                 m_bPlaying=false;
  44.         }
  45.         void Close()
  46.         {
  47.                 m_bPlaying=false;
  48.                 SafeRelease(m_pVideoWindow);
  49.                 SafeRelease(m_pBasicVideo);
  50.                 SafeRelease(m_pBasicAudio);
  51.                 SafeRelease(m_pMediaPosition);
  52.                 SafeRelease(m_pMediaControl);
  53.                 SafeRelease(m_pGraphBuilder);
  54.                 CoUninitialize();
  55.         }
  56.         void Play()
  57.         {
  58.                 if(!m_pMediaControl)return;
  59.                 if(0==(m_pMediaControl->Run()))return;
  60.                 m_bPlaying=true;
  61.         }
  62.         void Pause()
  63.         {
  64.                 if(!m_pMediaControl)return;
  65.                 if(0==(m_pMediaControl->Pause()))return;
  66.                 m_bPlaying=false;
  67.         }
  68.         void Stop()
  69.         {
  70.                 if(!m_pMediaControl)return;
  71.                 if(0==(m_pMediaControl->Stop()))return;
  72.                 m_bPlaying=false;
  73.         }
  74.         void Seek(double pos)
  75.         {
  76.                 if(!m_pMediaPosition)return;
  77.                 m_pMediaPosition->put_CurrentPosition(pos);
  78.         }
  79.         double GetDuration()
  80.         {
  81.                 double ret=0;
  82.                 if(!m_pMediaPosition)return 0;
  83.                 m_pMediaPosition->get_Duration(&ret);
  84.                 return ret;
  85.         }
  86.         double GetCrrtPos()
  87.         {
  88.                 double ret=0;
  89.                 if(!m_pMediaPosition)return 0;
  90.                 m_pMediaPosition->get_CurrentPosition(&ret);
  91.                 return ret;
  92.         }
  93.         double GetRate()
  94.         {
  95.                 double ret=0;
  96.                 if(!m_pMediaPosition)return 0;
  97.                 m_pMediaPosition->get_Rate(&ret);
  98.                 return ret;
  99.         }
  100.         void SetRate(double rate)
  101.         {
  102.                 if(!m_pMediaPosition)return;
  103.                 m_pMediaPosition->put_Rate(rate);
  104.         }
  105.         int GetVolume()
  106.         {
  107.                 int ret=0;
  108.                 if(!m_pBasicAudio)return 0;
  109.                 m_pBasicAudio->get_Volume(&ret);
  110.                 return ret;
  111.         }
  112.         void SetVolume(int vol)
  113.         {
  114.                 if(!m_pBasicAudio)return;
  115.                 m_pBasicAudio->put_Volume(vol);
  116.         }
  117.         void GetVideoSize(int *w,int *h)
  118.         {
  119.                 if(!m_pBasicVideo)return;
  120.                 m_pBasicVideo->GetVideoSize(w,h);
  121.         }
  122.         void GetDestPos(int *l,int *t,int *w,int *h)
  123.         {
  124.                 if(!m_pBasicVideo)return;
  125.                 m_pBasicVideo->GetDestinationPosition(l,t,w,h);
  126.         }
  127.         void SetDestPos(int l,int t,int w,int h)
  128.         {
  129.                 if(!m_pBasicVideo)return;
  130.                 m_pBasicVideo->SetDestinationPosition(l,t,w,h);
  131.         }
  132.         void GetSrcPos(int *l,int *t,int *w,int *h)
  133.         {
  134.                 if(!m_pBasicVideo)return;
  135.                 m_pBasicVideo->GetSourcePosition(l,t,w,h);
  136.         }
  137.         void SetSrcPos(int l,int t,int w,int h)
  138.         {
  139.                 if(!m_pBasicVideo)return;
  140.                 m_pBasicVideo->SetSourcePosition(l,t,w,h);
  141.         }
  142.         int GetVideoWndStyle()
  143.         {
  144.                 int ret=0;
  145.                 if(!m_pVideoWindow)return 0;
  146.                 m_pVideoWindow->get_WindowStyle(&ret);
  147.                 return ret;
  148.         }
  149.         void SetVideoWndStyle(int style)
  150.         {
  151.                 if(!m_pVideoWindow)return;
  152.                 m_pVideoWindow->put_WindowStyle(style);
  153.         }
  154.         HWND GetVideoWndOwner()
  155.         {
  156.                 HWND ret=(HWND)null;
  157.                 if(!m_pVideoWindow)return (HWND)null;
  158.                 m_pVideoWindow->get_Owner((OAHWND*)(&ret));
  159.                 return ret;
  160.         }
  161.         void SetVideoWndOwner(HWND hwnd)
  162.         {
  163.                 if(!m_pVideoWindow)return;
  164.                 m_pVideoWindow->put_Owner((OAHWND)hwnd);
  165.         }
  166.         void GetVideoWndPos(int *l,int *t,int *w,int *h)
  167.         {
  168.                 if(!m_pVideoWindow)return;
  169.                 m_pVideoWindow->GetWindowPosition(l,t,w,h);
  170.         }
  171.         void SetVideoWndPos(int l,int t,int w,int h)
  172.         {
  173.                 if(!m_pVideoWindow)return;
  174.                 m_pVideoWindow->SetWindowPosition(l,t,w,h);
  175.         }

  176. };
复制代码

77

主题

485

帖子

486

积分

中级会员

Rank: 3Rank: 3

积分
486
发表于 2011-1-12 22:50:00 | 显示全部楼层

Re:做游戏一定要DirectX吗 。windows GDI 行不

Bitblt先绘一张黑白的图,再绘一张原图.
异或显示出一张透明的图.
而DX只要设置一个透明的颜色,就能显示出透明的图.
GDI要图更多,而且显示还慢.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-6-3 06:04

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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