Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (3run, AndrewAMD), 667 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
directx - render to surface #136289
06/13/07 17:50
06/13/07 17:50
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline 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 Offline

Chief Engineer
jcl  Offline

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] #136291
06/14/07 13:40
06/14/07 13:40
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
thanks! i will try it...

after your snippet i have to call beginscene, then drawprimitiveup and then endscene?

do i have to reset anything afterwards?

what does SAFE_RELEASE do? i didn't find it in the directx documentation.

Re: directx - render to surface [Re: ventilator] #136292
06/14/07 15:38
06/14/07 15:38
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
Yes, you can then call your normal draw functions. Afterwards you need to set the render target back to its original target (use GetRenderTarget and store it before). SAFE_RELEASE is just a Microsoft macro that does something like

if (NULL != x) x->Release();

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 Offline OP
Senior Expert
ventilator  Offline 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: ventilator] #136294
06/15/07 06:19
06/15/07 06:19
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
It must be a new texture. The bmap textures normally don't have D3DUSAGE_RENDERTARGET.

However you can assign the texture to a bmap this way:

1. Release the original d3dtex of the bmap, and set d3dtex to pTarget.
2. Set the bmap flag RENDERTARGET, and reset MANAGED

const long RENDERTARGET = 1<<15; // Texture is allocated as a render target
const long MANAGED = 1<<27; // need not to be restored when device changes

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 Offline OP
Senior Expert
ventilator  Offline 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 Offline
User
bstudio  Offline
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.
Re: directx - render to surface [Re: bstudio] #136297
06/15/07 13:54
06/15/07 13:54
Joined: May 2002
Posts: 7,441
ventilator Offline OP
Senior Expert
ventilator  Offline OP
Senior Expert

Joined: May 2002
Posts: 7,441
no, i draw a white triangle and the white triangle is there in the jpg. i don't want a jpg though, i want the result in a 3dgs bitmap but mybmap stays black in the above example.

Re: directx - render to surface [Re: ventilator] #136298
06/15/07 14:43
06/15/07 14:43
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
mybmap->flags = 1<<15 | 1<<27;

This deletes important flags. Correct is:

mybmap->flags |= 1<<15;
mybmap->flags &= ~(1<<27);

Don't use '=' for flags. It's either '|=' for setting or '&=' for resetting a flag.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1