|
2 registered members (3run, AndrewAMD),
667
guests, and 1
spider. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
directx - render to surface
#136289
06/13/07 17:50
06/13/07 17:50
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2002
Posts: 7,441
|
i would like to render some triangles to a texture. maybe someone knows how to use the directx render to surface functions (i guess that's what you have to use?) and could post a short code snippet? it would save me a lot of trial and error time. 
|
|
|
Re: directx - render to surface
[Re: ventilator]
#136290
06/14/07 07:22
06/14/07 07:22
|
Joined: Jul 2000
Posts: 27,967 Frankfurt
jcl

Chief Engineer
|

Chief Engineer
Joined: Jul 2000
Posts: 27,967
Frankfurt
|
This is the engine function (simplified) that renders to a texture: Code:
LPDIRECT3DTEXTURE9 pTarget; D3DXCreateTexture(d3dDev, width,height, 1,D3DUSAGE_RENDERTARGET,format, D3DPOOL_DEFAULT,&pTarget));
LPDIRECT3DSURFACE pRenderTarget; pTarget->GetSurfaceLevel(0,&pRenderTarget); d3dDev->SetRenderTarget(0,pRenderTarget)); SAFE_RELEASE(pRenderTarget);
|
|
|
Re: directx - render to surface
[Re: jcl]
#136293
06/14/07 15:57
06/14/07 15:57
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2002
Posts: 7,441
|
it works but so far i only have seen the result in a jpg.  D3DXSaveSurfaceToFile("test.jpg", D3DXIFF_JPG, pRenderTarget, 0, 0); can i also directly render to 3dgs bitmaps that way? or does it always have to be a new texture with D3DUSAGE_RENDERTARGET? ... it would be nice if all of the defines and enums of d3d9types.h were available in lite-c.
|
|
|
Re: directx - render to surface
[Re: jcl]
#136295
06/15/07 08:50
06/15/07 08:50
|
Joined: May 2002
Posts: 7,441
ventilator
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2002
Posts: 7,441
|
hm... the bitmap stays black. here is my example: (i only want to render to the bitmap once and not every frame.) Code:
LPDIRECT3DDEVICE9 device = (LPDIRECT3DDEVICE9)pd3ddev; LPDIRECT3DSURFACE9 pPreviousRenderTarget; device->GetRenderTarget(0, &pPreviousRenderTarget); LPDIRECT3DTEXTURE9 pTargetTexture; D3DXCreateTexture(device, 512, 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTargetTexture); ((LPDIRECT3DTEXTURE9)mybmap->d3dtex)->Release(); ((LPDIRECT3DTEXTURE9)mybmap->d3dtex) = pTargetTexture; mybmap->flags = 1<<15 | 1<<27;
LPDIRECT3DSURFACE9 pRenderTarget; pTargetTexture->GetSurfaceLevel(0, &pRenderTarget); device->SetRenderTarget(0, pRenderTarget); device->Clear(0, 0, D3DCLEAR_TARGET, 0x00000000, 1, 0); // draw here device->SetRenderState(D3DRS_LIGHTING, FALSE); device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE); device->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); DVERTEX v[3];
v[0].x = 0; v[0].y = 0; v[0].z = 0; v[0].rhw = 1; v[0].color = D3DCOLOR_RGBA(255, 255, 255, 0); v[1].x = 512; v[1].y = 0; v[1].z = 0; v[1].rhw = 1; v[1].color = D3DCOLOR_RGBA(255, 255, 255, 0); v[2].x = 512; v[2].y = 512; v[2].z = 0; v[2].rhw = 1; v[2].color = D3DCOLOR_RGBA(255, 255, 255, 0); device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, (LPVOID)v, sizeof(DVERTEX)); D3DXSaveSurfaceToFile("test.jpg", D3DXIFF_JPG, pRenderTarget, 0, 0); SAFE_RELEASE(pRenderTarget); device->SetRenderTarget(0, pPreviousRenderTarget); SAFE_RELEASE(pPreviousRenderTarget);
|
|
|
Re: directx - render to surface
[Re: ventilator]
#136296
06/15/07 13:31
06/15/07 13:31
|
Joined: Aug 2006
Posts: 652 Netherlands
bstudio
User
|
User
Joined: Aug 2006
Posts: 652
Netherlands
|
D3DXSaveSurfaceToFile("test.jpg", D3DXIFF_JPG, pRenderTarget, 0, 0);
seems you save your surface to a bmap, and you color your primitive black, so yeah your surface will stay black.
BASIC programmers never die, they GOSUB and don't RETURN.
|
|
|
|