首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OLE控件在Direct3D中的渲染方法

OLE控件在Direct3D中的渲染方法

作者头像
逍遥剑客
发布2019-02-20 12:44:09
8780
发布2019-02-20 12:44:09
举报

Windows上的图形绘制是基于GDI的, 而Direct3D并不是, 所以, 要在3D窗口中显示一些Windows中的控件会有很多问题

那么, 有什么办法让GDI绘制的内容在3D中显示出来?反正都是图像, 总有办法实现的嘛!

前段时间在研究浏览器在游戏中的嵌入, 基本的思路就是在后台打开一个浏览窗口, 然后把它显示的内容拷贝到一张纹理上, 再把纹理在D3D中绘制出来, 至于事件处理就要另做文章了.

所以, 其它的Windows里的GDI绘制的东西都可以这样来实现! 最初我是GetDC, 然后GetPixel逐像素拷贝, 慢得我想死..... 后来发现了BitBlt这一速度很快的复制方法, 才有了实用价值:

1. 取得控件的DC: GetDC(hWnd) 2. 取得Texture的DC: IDirect3DSurface9::GetDC 3. 用BitBlt拷贝过去

BOOL BitBlt(   HDC hdcDest, // handle to destination DC int nXDest,  // x-coord of destination upper-left corner int nYDest,  // y-coord of destination upper-left corner int nWidth,  // width of destination rectangle int nHeight, // height of destination rectangle   HDC hdcSrc,  // handle to source DC int nXSrc,   // x-coordinate of source upper-left corner int nYSrc,   // y-coordinate of source upper-left corner   DWORD dwRop  // raster operation code );

如果是OLE控件那就更简单啦:

WINOLEAPI OleDraw(    IUnknown * pUnk,    //Pointer to the view object to be drawn   DWORD dwAspect,     //How the object is to be represented   HDC hdcDraw,        //Device context on which to draw   LPCRECT lprcBounds  //Pointer to the rectangle in which the object  // is drawn );

比如我有一个IWebBrowser2的指针, 想把它显示的内容拷贝到纹理上, 可以这么干:

    IDirect3DSurface9* pSurface = NULL; this->mTexture->GetSurfaceLevel(0, &pSurface); if (NULL != pSurface)     {         HDC hdcTexture;         HRESULT hr = pSurface->GetDC(&hdcTexture); if(FAILED(hr)) return;         ::SetMapMode(hdcTexture, MM_TEXT);         ::OleDraw(pBrowser, DVASPECT_CONTENT, hdcTexture, &rect);         pSurface->ReleaseDC(hdcTexture);         pSurface->Release();     }

Show一下:

不光是浏览器啦, 任何OLE控件都可以, 可以发挥你的想像力:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2008年03月15日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档