Surface correct POOL ?

Started by
6 comments, last by ArgusMaker 12 years, 9 months ago
[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?


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);
[/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
Advertisement

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?


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);



edit: problem solved! xD

On the other hand D3DPOOL_DEFAULT allows you to draw on the surface but disables the capability to render the surface to the screen...


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
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?



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);
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).

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

[font="Segoe UI"][color="#2a2a2a"]So how do you explain the memory access error for the second line?
[/font] IDirect3DTexture9* texture;
DX::g_pd3dDevice->CreateTexture(w,h,0,D3DUSAGE_RENDERTARGET,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&texture,NULL);
You're not initializing your variables:

IDirect3DTexture9 *texture = NULL;

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

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


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

More than likely g_pd3dDevice is null or an invalid (uninitialised) pointer.
problem solved, thanks to all biggrin.gif

This topic is closed to new replies.

Advertisement