Directx9表面纹理
Directx9 surface to texture
我想捕获我的Backbuffer到我的LPDIRECT3DSURFACE9,然后将表面复制到我的IDirect3DTexture9,最后使用该纹理作为我的对象皮肤。我写了代码,但只收到黑色像素。
IDirect3DTexture9* texture;
LPDIRECT3DSURFACE9 pd3dsBack = NULL;
void init()//init point
{
D3DXCreateTexture(g_pd3dDevice, 640, 480, D3DUSAGE_DYNAMIC,
0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
}
void render()//render point
{
g_pd3dDevice->BeginScene();
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, 0);
//my scene (1) 3d objects codes for draw.
g_pd3dDevice->EndScene();
//now try to get back-buffer into surface
g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pd3dsBack);
//i add this Save section to ensure the backbuffer data received complete and work.(it was ok and save complete true picture of Scene(1) ).
D3DXSaveSurfaceToFileA("BackbufferImage.BMP", D3DXIFF_BMP, pd3dsBack, NULL, NULL);
//this line put surface into my texture ; if u think this way is false please give me a simple code to fill texture by surface.
texture->GetSurfaceLevel(0, &pd3dsBack);
pd3dsBack->Release();//release my surface
//scene(2)
g_pd3dDevice->BeginScene();
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE(1.0f, 0.0f, 0.0f, 1.0f), 1.0f, 0);
//now render my scene(2) and useing the texture object for draw it as skin of my 3d object
g_pd3dDevice->SetTexture(0, texture);
g_pd3dDevice->EndScene();
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}
你可以试试这样
LPDIRECT3DDEVICE9 l_Device= RenderManager()->GetDirectXDevice();
LPDIRECT3DSURFACE9 l_RenderTarget, l_Surface;
m_Texture->GetSurfaceLevel(0,&l_Surface);
l_Device->GetRenderTarget(IdStage,&l_RenderTarget);
l_Device->StretchRect(l_RenderTarget,NULL, l_Surface,NULL,D3DTEXF_NONE);
l_RenderTarget->Release();
其中IdStage是当前要复制的渲染目标,在你的情况下,它将是0
m_Texture是一个DirectX纹理,你想从backbuffer接收副本
One Another way:
步骤1: 获取返回缓冲区作为表面:
LPDIRECT3DSURFACE9 pBackBuffer;
GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer)
步骤2:创建一个空的纹理
LPDIRECT3DTEXTURE9 textureMap
D3DXCreateTexture(device, width, height, D3DX_DEFAULT, D3DUSAGE_RENDERTARGET,
D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT,&textureMap);
注意:如果你想要alpha通道,那么使用D3DFMT_A8R8G8B8格式。
步骤3:获取指向空纹理顶部表面的指针
LPDIRECT3DSURFACE9 pTexSurface;
textureMap->GetSurfaceLevel(0, &pTexSurface);
第4步:表面到表面复制(缓冲区表面到空表面)
StretchRect(pBBsurface, NULL, pTexSurface, NULL, D3DTEXF_NONE);
步骤5:合成纹理与后缓冲内容
textureMap
相关文章:
- OpenInventor从9.8升级到10.4.2后,GLSL纹理返回零
- SFML纹理像播放器
- OpenGL大的3D纹理(>2GB)非常慢
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- 着色器纹理值与创建纹理时写入的值不同
- OpenGL将纹理四边形渲染为(0,0)
- 宽度为奇数的16位纹理为片状
- 使用 CUDA 和纹理进行图像减法
- 在不使用统一的情况下将纹理传递给 GLSL 着色器?
- 如何在C++中为表面制作邻接矩阵
- 从 FBO 渲染时在表面上重复纹理
- 从SDL调色板表面(SDL_PIXELFORMAT_INDEX8)创建OpenGL纹理
- SDL 表面到OpenGL纹理
- SDL2 尝试裁剪纹理或表面
- SDL2 渲染复制多个纹理与单个表面
- 如何将SDL TTF表面转换为具有透明背景的GL纹理
- SDL2 纹理的像素格式和表面颜色遮罩
- SDL2 -添加表面到表面,纹理到纹理或两者之间的东西
- 如何从原始位图数据到SDL表面或纹理
- Directx9表面纹理