DirectX 8.0 Graphics Problem

Started by
1 comment, last by Zipster 23 years, 2 months ago
I have the following code:
  
char* D3DInit(LPDIRECT3D8 lpD3D, LPDIRECT3DDEVICE8 lpD3DD, HWND hWnd)
{	
	if(FAILED(lpD3D = Direct3DCreate8(D3D_SDK_VERSION)))
		return "Unable to create D3D object";

	D3DDISPLAYMODE d3ddm;
	if(FAILED(lpD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
		return 0;
	
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed   = true;
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
	d3dpp.BackBufferFormat = d3ddm.Format;

	if(FAILED(lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                  &d3dpp, &lpD3DD)))
		return "Unable to create device";

	return NULL;
}

void D3DShutdown(LPDIRECT3D8 lpD3D, LPDIRECT3DDEVICE8 lpD3DD)
{
    if( lpD3DD != NULL)
        lpD3DD->Release();
    if( lpD3D != NULL)
        lpD3D->Release();
}

void D3DRender(LPDIRECT3D8 lpD3D, LPDIRECT3DDEVICE8 lpD3DD)
{
	//lpD3DD->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,0,63,0), 0, 0 );


}
  
When i execute my code (dont worry about WinMain() such. I have already determined that there is nothing wrong there) AS is above (Clear() commented out), it runs fine, and i get a blank window. ok. thats good. So now what happens when i uncomment Clear(). Crash. The program runs, sets the mode, but once Clear() is executed it just leaves the application nice and smoothly. its really confusing me as to why its doing this, especially since its copied straight from an online tuturial. Any ideas? I''ll post the other code if you need it, but i dont think youll find anything there. Its just standard Win32 code! Creating windows, etc.
Advertisement
Ok, I found the error. It seems that my D3D pointers were getting messed up when I was passing them as paramters through the funcitons. When i made them global variables and didn''t pass them throught the functions it worked. The wierd thing is I don''t know why the variables passing didn''t work! LPDIRECT3D8 and such are pointers by nature, so what did i do wrong? Passing that by a pointer won''t do because member functions of the interfaces can''t use a pointer to the interface (**IDirect3D8, which won''t work for member functions)

So how could I successfully pass the variables through the functions?
This could be really silly, but maybe you need to pass the pointers by reference instead of by value?

- This could have messed things up?
- Flanders -

This topic is closed to new replies.

Advertisement