CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  专题开发/技术/项目 >  游戏开发

用DirectX8.0的DirectX Graphics怎样显示24位真彩位图?

楼主truof(深黑色)2003-06-03 08:55:54 在 专题开发/技术/项目 / 游戏开发 提问

如果比较简单,能不能给些代码? 问题点数:70、回复次数:2Top

1 楼DarthVader(mm咋就那么白呢 唉 还是当黑炭吧)回复于 2003-06-03 14:43:33 得分 70

DirectX8.0   SDK的Sample:  
  ...  
  //-----------------------------------------------------------------------------  
  //   Name:   CSurface::ReDrawBitmapOnSurface()  
  //   Desc:   Load   a   bitmap   from   a   file   or   resource   into   a   DirectDraw   surface.  
  //               normaly   used   to   re-load   a   surface   after   a   restore.  
  //-----------------------------------------------------------------------------  
   
  HRESULT   CSurface::DrawBitmap(   TCHAR*   strBMP,    
                                                              DWORD   dwDesiredWidth,   DWORD   dwDesiredHeight     )  
  {  
          HBITMAP   hBMP;  
          HRESULT   hr;  
   
          if(   m_pdds   ==   NULL   ||   strBMP   ==   NULL   )  
                  return   E_INVALIDARG;  
   
          //     Try   to   load   the   bitmap   as   a   resource,   if   that   fails,   try   it   as   a   file  
          hBMP   =   (HBITMAP)   LoadImage(   GetModuleHandle(NULL),   strBMP,    
                                                                  IMAGE_BITMAP,   dwDesiredWidth,   dwDesiredHeight,    
                                                                  LR_CREATEDIBSECTION   );  
          if(   hBMP   ==   NULL   )  
          {  
                  hBMP   =   (HBITMAP)   LoadImage(   NULL,   strBMP,   IMAGE_BITMAP,    
                                                                          dwDesiredWidth,   dwDesiredHeight,    
                                                                          LR_LOADFROMFILE   |   LR_CREATEDIBSECTION   );  
                  if(   hBMP   ==   NULL   )  
                          return   E_FAIL;  
          }  
   
          //   Draw   the   bitmap   on   this   surface  
          if(   FAILED(   hr   =   DrawBitmap(   hBMP,   0,   0,   0,   0   )   )   )  
          {  
                  DeleteObject(   hBMP   );  
                  return   hr;  
          }  
   
          DeleteObject(   hBMP   );  
   
          return   S_OK;  
  }  
   
  //-----------------------------------------------------------------------------  
  //   Name:   CSurface::DrawBitmap()  
  //   Desc:   Draws   a   bitmap   over   an   entire   DirectDrawSurface,   stretching   the    
  //               bitmap   if   nessasary  
  //-----------------------------------------------------------------------------  
   
  HRESULT   CSurface::DrawBitmap(   HBITMAP   hBMP,    
                                                              DWORD   dwBMPOriginX,   DWORD   dwBMPOriginY,    
                                                              DWORD   dwBMPWidth,   DWORD   dwBMPHeight   )  
  {  
          HDC                         hDCImage;  
          HDC                         hDC;  
          BITMAP                   bmp;  
          DDSURFACEDESC2   ddsd;  
          HRESULT                 hr;  
   
          if(   hBMP   ==   NULL   ||   m_pdds   ==   NULL   )  
                  return   E_INVALIDARG;  
   
          //   Make   sure   this   surface   is   restored.  
          if(   FAILED(   hr   =   m_pdds->Restore()   )   )  
                  return   hr;  
   
          //   Get   the   surface.description  
          ddsd.dwSize     =   sizeof(ddsd);  
          m_pdds->GetSurfaceDesc(   &ddsd   );  
   
          if(   ddsd.ddpfPixelFormat.dwFlags   ==   DDPF_FOURCC   )  
                  return   E_NOTIMPL;  
   
          //   Select   bitmap   into   a   memoryDC   so   we   can   use   it.  
          hDCImage   =   CreateCompatibleDC(   NULL   );  
          if(   NULL   ==   hDCImage   )  
                  return   E_FAIL;  
   
          SelectObject(   hDCImage,   hBMP   );  
   
          //   Get   size   of   the   bitmap  
          GetObject(   hBMP,   sizeof(bmp),   &bmp   );  
   
          //   Use   the   passed   size,   unless   zero  
          dwBMPWidth     =   (   dwBMPWidth     ==   0   )   ?   bmp.bmWidth     :   dwBMPWidth;            
          dwBMPHeight   =   (   dwBMPHeight   ==   0   )   ?   bmp.bmHeight   :   dwBMPHeight;  
   
          //   Stretch   the   bitmap   to   cover   this   surface  
          if(   FAILED(   hr   =   m_pdds->GetDC(   &hDC   )   )   )  
                  return   hr;  
   
          //   This   is   the   secret   of   scalability!!    
          StretchBlt(   hDC,   0,   0,    
                                  ddsd.dwWidth,   ddsd.dwHeight,    
                                  hDCImage,   dwBMPOriginX,   dwBMPOriginY,  
                                  dwBMPWidth,   dwBMPHeight,   SRCCOPY   );  
   
          if(   FAILED(   hr   =   m_pdds->ReleaseDC(   hDC   )   )   )  
                  return   hr;  
   
          DeleteDC(   hDCImage   );  
   
          return   S_OK;  
  }  
   
  ...  
  //-----------------------------------------------------------------------------  
  //   Name:   CDisplay::ShowBitmap()  
  //   Desc:   Create   a   bitmap   surface   and   show   it   via   Present   method  
  //-----------------------------------------------------------------------------  
   
  HRESULT   CDisplay::ShowBitmap(   HBITMAP   hbm,   LPDIRECTDRAWPALETTE   pPalette   )  
  {  
          if(   NULL   ==   m_pddsFrontBuffer   ||     NULL   ==   m_pddsBackBuffer   )  
                  return   E_POINTER;  
   
          //   Set   the   palette   before   loading   the   bitmap  
          if(   pPalette   )  
                  m_pddsFrontBuffer->SetPalette(   pPalette   );  
   
          CSurface   backBuffer;  
          backBuffer.Create(   m_pddsBackBuffer   );  
   
          if(   FAILED(   backBuffer.DrawBitmap(   hbm,   0,   0,   0,   0   )   )   )  
                  return   E_FAIL;  
   
          return   Present();  
  }Top

2 楼DarthVader(mm咋就那么白呢 唉 还是当黑炭吧)回复于 2003-06-03 15:01:19 得分 0

CSurface是一个SDK里面的类  
  呵呵Top

相关问题

  • directx 图像显示
  • 图片显示
  • 显示图形
  • 图像显示???
  • 图片显示
  • 显示位图
  • 位图显示
  • 图形显示
  • 图片显示
  • 显示图片

关键词

  • null
  • strbmp
  • hbmp
  • dwdesiredwidth
  • dwdesiredheight
  • hbitmap
  • lr
  • bitmap
  • load

得分解答快速导航

  • 帖主:truof
  • DarthVader

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo