OLE控件在Direct3D中的渲染方法
来源:互联网 发布:作者 网络骑士 编辑:程序博客网 时间:2024/05/15 12:15
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
);
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
);
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();
}
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控件都可以, 可以发挥你的想像力:
- OLE控件在Direct3D中的渲染方法
- 摸爬滚打DirectX11_day03——Direct3D中的渲染五部曲
- direct3d控件
- Direct3D渲染到纹理
- Direct3D 半透明渲染
- Direct3D渲染管线简介
- Direct3D渲染管线
- 读书笔记--Direct3D渲染流水线
- Direct3D 11 渲染状态
- PBRT学习笔记: 颜色在离线渲染中的表示方法
- OLE在PB数据窗口中的实现
- 在RichEdit控件中插入OLE对象(ActiveX控件)
- Direct3D 9,Direct3D 10,Direct3D 11渲染流水线
- Direct3D学习笔记:渲染管线
- Direct3D 11渲染管线总结
- 如何在OLE控件中使用OLE_COLOR数据类型
- 在DELPHI程序中注册OLE/COM控件
- Oracle Objects for OLE 及在VB中的应用
- Flex 发布模式
- ASP生成静态Html文件技术杂谈
- Flex 的MVC 模型
- Dev-cpp下的一个socket的例子
- 制作网页需要学习哪些技术?
- OLE控件在Direct3D中的渲染方法
- java.lang.ClassCastException
- 一个分糖果游戏的解法
- Java混合化现状和RIA趋势分析
- 什么是Java Runtime Environment (JRE)?
- 对Excel进行读写要注意的问题
- 3月15日工作日志-88250
- IA-32架构下启动过程(2)
- 组图:二手新房卖到2800万 杨思敏要悄悄订婚