background image

Started by
2 comments, last by Evil Steve 17 years, 10 months ago
Hi, I'm trying to draw a background image in direct3d8 Basically I want to draw an image and then render the scene ontop of that. Now my problem is that I dont know how to go about accessing the backbuffer and setting indivisual pixels. Rendering a quad is not really an option because the image needs to be on the background pixel exact. And the image is not power of two. -CProgrammer
Advertisement
Hey, to access the back buffer you would call GetBackBuffer like this:

LPDIRECT3DSURFACE8 g_pBackBuffer;g_pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_pBackBuffer);


Now you will need to create an image surface and load your bmp file like this:

LPDIRECT3DSURFACE8 g_pBackground;g_pD3DDevice->CreateImageSurface(imagewidth, imageheight, D3DFMT_X8R8G8B8, &g_pBackground);D3DXLoadSurfaceFromFile(&g_pBackground, NULL, NULL, "background.bmp", NULL, D3DX_DEFAULT, 0, NULL);


Then to render your image you use CopyRects like this:

g_pD3DDevice->CopyRects(g_pBackground, NULL, 0, g_pBackBuffer, NULL);


You should take a look at each of those functions in detail to see what most of the parameters are. Good luck.
Hey, to access the back buffer you would call GetBackBuffer like this:

LPDIRECT3DSURFACE8 g_pBackBuffer;g_pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_pBackBuffer);


Now you will need to create an image surface and load your bmp file like this:

LPDIRECT3DSURFACE8 g_pBackground;g_pD3DDevice->CreateImageSurface(imagewidth, imageheight, D3DFMT_X8R8G8B8, &g_pBackground);D3DXLoadSurfaceFromFile(&g_pBackground, NULL, NULL, "background.bmp", NULL, D3DX_DEFAULT, 0, NULL);


Then to render your image you use CopyRects like this:

g_pD3DDevice->CopyRects(g_pBackground, NULL, 0, g_pBackBuffer, NULL);


You should take a look at each of those functions in detail to see what most of the parameters are. Good luck.

EDIT: Ooops didnt relize i posted twice, sorry.
Locking the backbuffer is a BAD idea. You'll utterly kill your frame rate. I'd advise breaking the image into 256x256 tiles (larger if possible) and rendering several quads to the backbuffer.

This topic is closed to new replies.

Advertisement