Discussion:
Why does the methode "CreateOffscreenPlainSurface" fail?
(too old to reply)
Michael Schwarz
2006-03-05 12:08:45 UTC
Permalink
I try to learn DirectX with C++ at the momment and i dont know why the
function "CreateOffscreenPlainSurface" allways fails in the src below. I did
cut out the message handler and the windows creation. Please can somebody
explain me why the function fails and how i can get it to work.

#include <d3d9.h>
#include <d3dx9.h>

IDirect3D9* g_pD3D = NULL;
IDirect3DDevice9* g_pd3dDevice = NULL;
IDirect3DSurface9* g_Surface = NULL;

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferCount = 1;

g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice);

D3DXIMAGE_INFO Info;
D3DXGetImageInfoFromFile("image.bmp", &Info);

if(FAILED(g_pd3dDevice->CreateOffscreenPlainSurface(Info.Width,
Info.Height, Info.Format, D3DPOOL_DEFAULT, &g_Surface, NULL)))
{
MessageBox(hWnd,"Could not create Surface","",MB_OK);
return E_FAIL;
}
}

thx in advance

Michael
Wessam Bahnassi
2006-03-05 12:13:15 UTC
Permalink
Mostly the format that your image is stored in is not supported by your
graphics card directly (I guess it's D3DFMT_R8G8B8 which isn't commonly
supported). But don't feel bad about it!
I suggest that you specify a constant format for the surface that is
guarenteed to work (D3DFMT_A8R8G8B8 as an example). Then use the function
D3DXLoadSurfaceFromFile() to load your color data onto the surface no matter
what format is the file in. Of course, this is not the best practice as
you'll see when you get more advanced with D3D...
--
Wessam Bahnassi
Microsoft DirectX MVP,
Lead Programmer
In|Framez
--
In|Structurez Arabic Gamedev Community
www.instructurez.com
Post by Michael Schwarz
I try to learn DirectX with C++ at the momment and i dont know why the
function "CreateOffscreenPlainSurface" allways fails in the src below. I
did cut out the message handler and the windows creation. Please can
somebody explain me why the function fails and how i can get it to work.
#include <d3d9.h>
#include <d3dx9.h>
IDirect3D9* g_pD3D = NULL;
IDirect3DDevice9* g_pd3dDevice = NULL;
IDirect3DSurface9* g_Surface = NULL;
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferCount = 1;
g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice);
D3DXIMAGE_INFO Info;
D3DXGetImageInfoFromFile("image.bmp", &Info);
if(FAILED(g_pd3dDevice->CreateOffscreenPlainSurface(Info.Width,
Info.Height, Info.Format, D3DPOOL_DEFAULT, &g_Surface, NULL)))
{
MessageBox(hWnd,"Could not create Surface","",MB_OK);
return E_FAIL;
}
}
thx in advance
Michael
Loading...