CreateDevice Fehler



  • void InitD3D(HWND &hWnd)
    {
    	if(!(g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
    	{
    		throw Exception("DirectX Create Error");
    	}
    
    	D3DPRESENT_PARAMETERS d3dpp;
    	memset(&d3dpp, 0, sizeof(D3DPRESENT_PARAMETERS));
    
    	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    	d3dpp.BackBufferCount = 1;
    	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	d3dpp.BackBufferHeight = 600;
    	d3dpp.BackBufferWidth = 800;
    	d3dpp.EnableAutoDepthStencil = TRUE;
    	d3dpp.Flags = 0;
    	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    	d3dpp.hDeviceWindow = hWnd;
    	d3dpp.MultiSampleQuality = D3DMULTISAMPLE_NONE;
    	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.Windowed = FALSE;
    
    	HRESULT hResult = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice);
    	switch(hResult)
    	{
    		case D3D_OK: return;
    		case D3DERR_DEVICELOST: throw Exception("DEVICELOST");
    		case D3DERR_INVALIDCALL: throw  Exception("INVALIDCALL");
    		case D3DERR_NOTAVAILABLE: throw Exception("NOTAVAILABLE");
    		case D3DERR_OUTOFVIDEOMEMORY: throw Exception("OUTOFVIDEOMEMORY");
    		default: throw Exception("Unknown");
    	}
    }
    

    Wenn das ausgeführt wird kommt immer nur die Exception: INVALIDCALL. Die übergebenen Parameter sind aber korrekt und getestet. Bei einem andern Projekt funktionieren die einwandfrei. Also langsam komm ich ins grübeln was hier schiefläuft.



  • Versuch mal

    d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
    

    anstatt

    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    


  • Hab ich auch schon. Hier mal der gesamte Code. Das eigentümlich daran ist, das selbst das Registrieren der Windowsklasse nicht mehr geht. Ich hab das dumpfe gefühl das hier gar nix mehr geht, zumindestens bei diesem projekt???

    #include <windows.h>
    #include <d3d9.h>
    #include "Exception.h"
    #pragma comment(lib, "d3d9.lib")
    
    //Prototypen
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    void InitD3D(HWND &hWnd);
    void CleanUp();
    void Render();
    
    IDirect3D9 *g_pD3D = NULL;
    IDirect3DDevice9 *g_pD3DDevice = NULL;
    bool bRun = true;
    
    //Funktionen
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrecInstance, PSTR szCmdLine, int iCmdShow)
    {
    	HWND hWnd;
    	MSG msg;
    	WNDCLASSEX wc;
    
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = NULL;
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "D3D9";
    	wc.hIconSm = NULL;
    
    	if(!RegisterClassEx(&wc));
    	{
    		MessageBox(NULL,"Registrieren Fehlgeschlagen","ERROR",MB_OK);
    		return 0;
    	}
    
    	hWnd = CreateWindowEx(WS_EX_APPWINDOW, "D3D9", "DirectX9", WS_POPUP | WS_SYSMENU, CW_USEDEFAULT, 0, 10, 10, NULL, NULL, hInstance, NULL);
    	if(!hWnd)
    	{
    		MessageBox(NULL,"Fenster konnte nicht erstellt werden.","ERROR",MB_OK);
    		return 0;
    	}
    
    	try
    	{
    		InitD3D(hWnd);
    
    		while(bRun)
    		{
    			while(PeekMessage(&msg,NULL,0,0,PM_REMOVE) != 0)
    			{
    				TranslateMessage(&msg);
    				DispatchMessage(&msg);
    			}
    			Render();
    		}
    	}
    	catch(Exception& error)
    	{
    		MessageBox(hWnd,error.GetError().c_str(),"ERROR",MB_OK);
    	}
    	//CleanUp();
    	return int(msg.wParam);
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message)
    	{	
    		case WM_PAINT:
    		{
    			return 0;
    		}
    
    		case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			return DefWindowProc(hWnd, message, wParam, lParam);
    		}
    
    		case WM_KEYDOWN:
    		{
    			switch(wParam)
    			{
    				case VK_ESCAPE:
    				{
    					bRun = false;
    					DestroyWindow(hWnd);
    				}
    			}
    		}
    
    	}
    	return DefWindowProc(hWnd, message, wParam, lParam);
    }
    
    void InitD3D(HWND &hWnd)
    {
    	if(!(g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
    	{
    		throw Exception("INTERFACE ERROR");
    	}
    
    	D3DPRESENT_PARAMETERS d3dpp;
    	memset(&d3dpp, 0, sizeof(D3DPRESENT_PARAMETERS));
    
    	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    	d3dpp.BackBufferCount = 1;
    	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	d3dpp.BackBufferHeight = 600;
    	d3dpp.BackBufferWidth = 800;
    	d3dpp.EnableAutoDepthStencil = TRUE;
    	d3dpp.Flags = 0;
    	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
    	d3dpp.hDeviceWindow = NULL;
    	d3dpp.MultiSampleQuality = D3DMULTISAMPLE_NONE;
    	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.Windowed = FALSE;
    
    	HRESULT hResult = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice);
    	switch(hResult)
    	{
    		case D3D_OK: return;
    		case D3DERR_DEVICELOST: throw Exception("DEVICELOST");
    		case D3DERR_INVALIDCALL: throw  Exception("INVALIDCALL");
    		case D3DERR_NOTAVAILABLE: throw Exception("NOTAVAILABLE");
    		case D3DERR_OUTOFVIDEOMEMORY: throw Exception("OUTOFVIDEOMEMORY");
    		default: throw Exception("Unknown");
    	}
    }
    
    void CleanUp()
    {
    	if(g_pD3DDevice != NULL)
    	{
    		g_pD3DDevice->Release();
    	}
    	if(g_pD3D != NULL)
    	{
    		g_pD3D->Release();
    	}
    }
    
    void Render()
    {
    	if(NULL == g_pD3DDevice)
    	{
    		throw Exception("D3DDEVICE NOT AVAILABLE");
    	}
    	if(FAILED(g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0F, 0)))
    	{
    		throw Exception("Clear Error");
    	}
    	/*if(SUCCEEDED(g_pD3DDevice->BeginScene()))
    	{
    		//Rendern der Szene Objekte
    		g_pD3DDevice->EndScene();
    	}*/
    	if(FAILED(g_pD3DDevice->Present(NULL, NULL, NULL, NULL)))
    	{
    		throw Exception("Present Error");
    	}
    }
    

Anmelden zum Antworten