I need some help setting up child windows with D3D
I''m coding my first map editor, and I''m somewhat new to all of this. So my code is based on the D3D tutorials. here''s setup code.
This is in Win Main:
// Register the window class
WNDCLASSEX wc;
wc.lpfnWndProc = MsgProc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpszClassName = "Map Editor";
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra=0L;
wc.cbWndExtra=0L;
wc.hInstance=GetModuleHandle(NULL);
wc.hbrBackground = (HBRUSH) GetStockObject (GRAY_BRUSH);
RegisterClassEx( &wc );
// Create the application''s window
HWND hWnd = CreateWindow( "Map Editor", "Map Editor",
WS_OVERLAPPEDWINDOW, 100, 100, RESWIDTH+RESWIDTH/6, RESHEIGHT+RESHEIGHT/8,
GetDesktopWindow(), NULL, wc.hInstance, NULL );
wc.style = CS_CLASSDC;
wc.lpfnWndProc = ControlProc;
wc.lpszClassName = "Render Window";
RegisterClassEx( &wc );
// Create the Render screen
HWND RenderhWnd = CreateWindow( "Render Window",NULL,
WS_CHILDWINDOW | WS_VISIBLE, 0, 0, RESWIDTH, RESHEIGHT,
hWnd, (HMENU)2, wc.hInstance, NULL );
All of that seems to work, but then InitD3D fails, this is the InitD3D function
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
{
MessageBox(hWnd,"error calling Direct3DCreate8","error",MB_OK);
return E_FAIL;
}
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
D3DDISPLAYMODE d3ddm;
if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferCount = 1;
d3dpp.hDeviceWindow= hWnd;
// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
MessageBox(hWnd,"error creating D3D device","error",MB_OK);
return E_FAIL;
}
// Turn off culling, so we see the front and back of the triangle
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off D3D lighting, since we are providing our own vertex colors
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
return S_OK;
}
The create device function fails.
I don''t know what I''m doing wrong, this is sort of just hacked up from "Proggramming Windows" and the D3D tutorials. If anyone can help me I''d appreciate it.
If the method fails, the return value can be one of the following values.
D3DERR_INVALIDCALL
D3DERR_NOTAVAILABLE
D3DERR_OUTOFVIDEOMEMORY
If you get the return code, you can figure out a bit more on why it fails. Hope this helps!
"I kinda think, therefore, I kinda... am?"
D3DERR_INVALIDCALL
D3DERR_NOTAVAILABLE
D3DERR_OUTOFVIDEOMEMORY
If you get the return code, you can figure out a bit more on why it fails. Hope this helps!
"I kinda think, therefore, I kinda... am?"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement