Jump to content
  • Advertisement
Sign in to follow this  
_Sauce_

Rendering array of pixels directly to backbuffer (DX9)

This topic is 3175 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

I'm trying to render an array of pixels to the backbuffer in directx9 and I'm having a bit of trouble. Here's what I've tried so far:
IDirect3DSurface9 *d3dSurface = NULL;
RECT rect = {0, 0, mWidth, mHeight};

HRESULT hr = D3DXLoadSurfaceFromMemory(d3dSurface, NULL, NULL, mPixels, D3DFMT_R8G8B8, mWidth * sizeof(TrueColorPixel), NULL, &rect, D3DX_DEFAULT, 0);
	
if(FAILED(hr))
{
	DXTrace(__FILE__, __LINE__, hr, _T(__FUNCTION__), TRUE);
}

pDevice->BeginScene();

IDirect3DSurface9 *backBuffer = NULL;

if(SUCCEEDED(pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer)))
{
	pDevice->StretchRect(d3dSurface, NULL, backBuffer, &rect, D3DTEXF_NONE);
}

pDevice->EndScene();

if(d3dSurface)
{
	d3dSurface->Release();
	d3dSurface = NULL;
}

However whenever I run this I get "D3DERR_INVALID_CALL" for D3DXLoadSurfaceFromMemory() - what am I missing here?

Share this post


Link to post
Share on other sites
Advertisement
Yep, I ended up trying IDirect3DDevice9::CreateOffscreenPlainSurface() which worked - I then turned on the debug runtimes and found it didn't like the pixel format, so I changed that to X8R8G8B8 - but now it tells me I'm passing an invalid rect in IDirect3DDevice9::StretchRect() :(

Looking back at my code though, it seems I'm grossly over-complicating the issue - does GetBackBuffer() return the actual backbuffer that I can modify, or does it give me a copy of it?

Share this post


Link to post
Share on other sites
I looked at the documentation for the GetBackBuffer function.

In the remarks it says this:

Calling this method will increase the internal reference count on the IDirect3DSurface9 interface.

So it looks to me that it gives you a pointer to the actual back buffer surface.

Share this post


Link to post
Share on other sites
Okay, so it turns out I really was overcomplicating things (not to mention, forgetting to call present() *facepalm*

pDevice->BeginScene();

IDirect3DSurface9 *backBuffer = NULL;
if(SUCCEEDED(pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer)))
{
RECT rect = {0, 0, mWidth, mHeight};
D3DXLoadSurfaceFromMemory(backBuffer, NULL, NULL, mPixels, D3DFMT_X8R8G8B8,
mWidth * sizeof(TrueColorPixel), NULL, &rect, D3DX_DEFAULT, 0);
}

pDevice->EndScene();

pDevice->Present(NULL, NULL, NULL, NULL);

if(backBuffer)
{
backBuffer->Release();
backBuffer = NULL;
}


works smashingly :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Martin
I wonder how this compares to drawing a number of textures....
It's probably slower, YMMV.

Also, the Debug Runtimes will tell you why something has gone wrong when a D3D function fails, which is extremely useful in debugging.

Share this post


Link to post
Share on other sites
Quote:
Original post by _Sauce_
Yep, I ended up trying IDirect3DDevice9::CreateOffscreenPlainSurface() which worked - I then turned on the debug runtimes and found it didn't like the pixel format, so I changed that to X8R8G8B8


:)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!