Sign in to follow this  

Surface correct POOL ?

This topic is 2346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[s]Hi!
My latest problem concerns rendering surfaces to the backbuffer.
I wrote a very simple code, but when i present my backbuffer nothing appears.
What's wrong?

[code]
IDirect3DSurface9* surface = NULL;
IDirect3DSurface9* backbuffer = NULL;
POINT point;
DX::g_pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backbuffer);
DX::g_pd3dDevice->CreateOffscreenPlainSurface(100,100,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM,&surface,NULL);
DX::g_pd3dDevice->SetRenderTarget(0,surface);
DX::g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255,255),0,0);
DX::g_pd3dDevice->SetRenderTarget(0,DX::BackBuffer);

point.x = 10;
point.y = 10;
DX::g_pd3dDevice->UpdateSurface(surface,NULL,backbuffer,&point);[/code][/s]
edit: problem solved! xD
edit2: a new problem appears! XD
I need a surface where i can draw, but i also need to be able to render that surface to the screen.
If a surface is created in D3DPOOL_SYSTEMMEM it can be rendered to the screen, but you can't draw on it.
On the other hand D3DPOOL_DEFAULT allows you to draw on the surface but disables the capability to render the surface to the screen...
How should i create the surface? Thanks in advance

Share this post


Link to post
Share on other sites
Hidden
[quote name='ArgusMaker' timestamp='1310480664' post='4834308']
Hi!
My latest problem concerns rendering surfaces to the backbuffer.
I wrote a very simple code, but when i present my backbuffer nothing appears.
What's wrong?

[code]
IDirect3DSurface9* surface = NULL;
IDirect3DSurface9* backbuffer = NULL;
POINT point;
DX::g_pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backbuffer);
DX::g_pd3dDevice->CreateOffscreenPlainSurface(100,100,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM,&surface,NULL);
DX::g_pd3dDevice->SetRenderTarget(0,surface);
DX::g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255,255),0,0);
DX::g_pd3dDevice->SetRenderTarget(0,DX::BackBuffer);

point.x = 10;
point.y = 10;
DX::g_pd3dDevice->UpdateSurface(surface,NULL,backbuffer,&point);[/code]
[/quote]

edit: problem solved! xD

Share this post


Link to post
[quote name='ArgusMaker' timestamp='1310480664' post='4834308']
On the other hand D3DPOOL_DEFAULT allows you to draw on the surface but disables the capability to render the surface to the screen...
[/quote]

Sure it does. You just can't use it with UpdateSurface, which is not a rendering function (it's a function for updating the contents of a normal GPU texture with the contents of a CPU-acccesible texture). The normal way to create a render target texture is to create a texture with CreateTexture, specifying D3DPOOL_DEFAULT and D3DUSAGE_RENDERTARGET.

Then you can render it to the backbuffer by...

1. Drawing a quad covering the entire screen with your render target set as the texture
2. Using ID3DXSprite to draw the texture as a screen-sized sprite
3. Using StretchRect to copy it to the backbuffer

Share this post


Link to post
Share on other sites
Ok, thanks, stretchrect works.
I can't use textures due to their size limitations (power of 2). One last thing:
Why this code doesen't fill my surface in red?


[code]
IDirect3DSurface9* surface = NULL;
DX::g_pd3dDevice->CreateOffscreenPlainSurface(w,h,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&surface,NULL);
IDirect3DSurface9* old_rt;
DX::g_pd3dDevice->GetRenderTarget(0,&old_rt);
DX::g_pd3dDevice->SetRenderTarget(0,surface);
DX::g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,0,0),0,0);
DX::g_pd3dDevice->SetRenderTarget(0,old_rt);[/code]

Share this post


Link to post
Share on other sites
Power of 2 restrictions may not apply to rendertargets (I've found a few drivers where - even if they apply to normal textures - you can create a rendertarget texture at the same size as your display) and in any event your hardware may very well support non-power-of-2 anyway (any reasonably modern hardware - less than 5 or so years old - should).

Share this post


Link to post
Share on other sites
[font="Segoe UI"][size="3"][color="#2a2a2a"]So how do you explain the memory access error for the second line?
[/color][/size][/font][size="3"] [/size][code]IDirect3DTexture9* texture;
DX::g_pd3dDevice->CreateTexture(w,h,0,D3DUSAGE_RENDERTARGET,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&texture,NULL);
[/code][size="3"] [/size]

Share this post


Link to post
Share on other sites
You're not initializing your variables:

IDirect3DTexture9 *texture[b] = NULL[/b];

Also be sure to check the HRESULT and if you're still getting failures use the debug runtimes to get additional error info.

Share this post


Link to post
Share on other sites
[quote name='ArgusMaker' timestamp='1310546381' post='4834691']
[font="Segoe UI"][size="3"][color="#2a2a2a"]So how do you explain the memory access error for the second line?
[/color][/size][/font] [code]IDirect3DTexture9* texture;
DX::g_pd3dDevice->CreateTexture(w,h,0,D3DUSAGE_RENDERTARGET,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&texture,NULL);
[/code]
[/quote]More than likely g_pd3dDevice is null or an invalid (uninitialised) pointer.

Share this post


Link to post
Share on other sites

This topic is 2346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this