DXUT Problem mit Mesh
-
Hallo!
Nachdem ich mich ein bisschen in DXUT eingelesen habe folgte ich meinem Tutorial im Buch "Spieleprogrammierung mit DX11 und C++" von Susanne Widgard.
Ich habe das Problem das mein Mesh nicht angezeigt wird.
#include "DXUT.h" #include "SDKmisc.h" #include "DXUTCamera.h" #include "SDKMesh.h" //variables ID3D11VertexShader* g_pVertexShader11=NULL; ID3D11PixelShader* g_pPixelShader11=NULL; ID3D11Buffer* g_pcbVSPerObject11=NULL; ID3D11Buffer* g_pcbVSPerFrame11=NULL; CModelViewerCamera g_Camera; ID3D11InputLayout* g_pLayout11=NULL; ID3D11SamplerState* g_pSamLinear = NULL; CDXUTSDKMesh g_Mesh; //shader-structures #pragma pack(push) struct CB_VS_PER_OBJECT { D3DXMATRIX m_mWorldViewProjection; D3DXMATRIX m_mWorld; D3DXVECTOR4 m_MaterialAmbientColor; D3DXVECTOR4 m_MaterialDiffuseColor; }; struct CB_VS_PER_FRAME { D3DXVECTOR3 m_vLightDir; float m_fTime; D3DXVECTOR4 m_LightDiffuse; }; #pragma pack(pop) //-------------------------------------------------------------------------------------- // Reject any D3D11 devices that aren't acceptable by returning false //-------------------------------------------------------------------------------------- bool CALLBACK IsD3D11DeviceAcceptable( const CD3D11EnumAdapterInfo *AdapterInfo, UINT Output, const CD3D11EnumDeviceInfo *DeviceInfo, DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext ) { return true; } //-------------------------------------------------------------------------------------- // Called right before creating a D3D9 or D3D11 device, allowing the app to modify the device settings as needed //-------------------------------------------------------------------------------------- bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext ) { return true; } //-------------------------------------------------------------------------------------- // Create any D3D11 resources that aren't dependant on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; //search hlsl file WCHAR str[MAX_PATH]; DXUTFindDXSDKMediaFileCch(str,MAX_PATH,L"SimpleSample.hlsl"); DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders. // Setting this flag improves the shader debugging experience, but still allows // the shaders to be optimized and to run exactly the way they will run in // the release configuration of this program. dwShaderFlags |= D3DCOMPILE_DEBUG; #endif //compile hlsl file ID3DBlob* pVertexShaderBuffer=NULL; D3DX11CompileFromFile(str,NULL,NULL,"RenderSceneVS","vs_4_0_level_9_1",dwShaderFlags,0,NULL,&pVertexShaderBuffer,NULL,NULL); ID3DBlob* pPixelShaderBuffer=NULL; D3DX11CompileFromFile(str,NULL,NULL,"RenderScenePS","ps_4_0_level_9_1",dwShaderFlags,0,NULL,&pPixelShaderBuffer,NULL,NULL); pd3dDevice->CreateVertexShader(pVertexShaderBuffer->GetBufferPointer(),pVertexShaderBuffer->GetBufferSize(),NULL,&g_pVertexShader11); pd3dDevice->CreatePixelShader(pPixelShaderBuffer->GetBufferPointer(),pPixelShaderBuffer->GetBufferSize(),NULL,&g_pPixelShader11); //vertex layout const D3D11_INPUT_ELEMENT_DESC layout[]= { {"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0}, {"NORMAL",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0}, {"TEXCOORD",0,DXGI_FORMAT_R32G32B32_FLOAT,0,24,D3D11_INPUT_PER_VERTEX_DATA,0}, }; V_RETURN(pd3dDevice->CreateInputLayout(layout,ARRAYSIZE(layout),pVertexShaderBuffer->GetBufferPointer(),pVertexShaderBuffer->GetBufferSize(),&g_pLayout11)); //set constants //buffer D3D11_BUFFER_DESC cbDesc; ZeroMemory(&cbDesc,sizeof(cbDesc)); cbDesc.Usage=D3D11_USAGE_DYNAMIC; cbDesc.BindFlags=D3D11_BIND_CONSTANT_BUFFER; cbDesc.CPUAccessFlags=D3D11_CPU_ACCESS_WRITE; cbDesc.ByteWidth=sizeof(CB_VS_PER_OBJECT); V_RETURN(pd3dDevice->CreateBuffer(&cbDesc,NULL,&g_pcbVSPerObject11)); cbDesc.ByteWidth=sizeof(CB_VS_PER_FRAME); V_RETURN(pd3dDevice->CreateBuffer(&cbDesc,NULL,&g_pcbVSPerFrame11)); //camera D3DXVECTOR3 vecEye(0.0f,0.0f,-5.0f); D3DXVECTOR3 vecAt(0.0f,0.0f,-0.0f); g_Camera.SetViewParams(&vecEye,&vecAt); //models g_Mesh.Create(pd3dDevice,L"earth\\earth.sdkmesh",true); //release blobs SAFE_RELEASE(pVertexShaderBuffer); SAFE_RELEASE(pPixelShaderBuffer); return S_OK; } //-------------------------------------------------------------------------------------- // Create any D3D11 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { float fAspectRatio = (float)pBackBufferSurfaceDesc->Width/(float)pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams(D3DX_PI/4,fAspectRatio,0.1f,1000.0f); g_Camera.SetWindow(pBackBufferSurfaceDesc->Width,pBackBufferSurfaceDesc->Height); g_Camera.SetButtonMasks(MOUSE_LEFT_BUTTON,MOUSE_WHEEL,MOUSE_MIDDLE_BUTTON); return S_OK; } //-------------------------------------------------------------------------------------- // Handle updates to the scene. This is called regardless of which D3D API is used //-------------------------------------------------------------------------------------- void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext ) { g_Camera.FrameMove(fElapsedTime); } //-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { //clear float ClearColor[4]={0.176f,0.196f,0.667f,0.0f}; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView(pRTV,ClearColor); // If the settings dialog is being shown, then render it instead of rendering the app's scene D3DXMATRIX mWorld = *g_Camera.GetWorldMatrix(); D3DXMATRIX mView = *g_Camera.GetViewMatrix(); D3DXMATRIX mProj = *g_Camera.GetProjMatrix(); D3DXMATRIX mWorldViewProjection = mWorld * mView * mProj; HRESULT hr; D3D11_MAPPED_SUBRESOURCE MappedResource; V(pd3dImmediateContext->Map(g_pcbVSPerObject11,0,D3D11_MAP_WRITE_DISCARD,0,&MappedResource)); CB_VS_PER_OBJECT* pVSPerObject = (CB_VS_PER_OBJECT*) MappedResource.pData; //matrix D3DXMatrixTranspose(&pVSPerObject->m_mWorldViewProjection,&mWorldViewProjection); D3DXMatrixTranspose(&pVSPerObject->m_mWorld,&mWorld); //material pVSPerObject->m_MaterialAmbientColor=D3DXVECTOR4(0.3f,0.3f,0.3f,1.0f); pVSPerObject->m_MaterialDiffuseColor=D3DXVECTOR4(0.7f,0.7f,0.7f,1.0f); pd3dImmediateContext->VSSetConstantBuffers(0,1,&g_pcbVSPerObject11); pd3dImmediateContext->Unmap(g_pcbVSPerObject11,0); //light pd3dImmediateContext->Map(g_pcbVSPerFrame11,0,D3D11_MAP_WRITE_DISCARD,0,&MappedResource); CB_VS_PER_FRAME* pVSPerFrame=(CB_VS_PER_FRAME*) MappedResource.pData; pVSPerFrame->m_vLightDir=D3DXVECTOR3(0,0.707f,-0.707f); pVSPerFrame->m_LightDiffuse=D3DXVECTOR4(1.f,1.f,1.f,1.f); pd3dImmediateContext->VSSetConstantBuffers(1,1,&g_pcbVSPerFrame11); pd3dImmediateContext->Unmap(g_pcbVSPerFrame11,0); pd3dImmediateContext->IASetInputLayout(g_pLayout11); pd3dImmediateContext->VSSetShader(g_pVertexShader11,NULL,0); pd3dImmediateContext->PSSetShader(g_pPixelShader11,NULL,0); //models g_Mesh.Render(pd3dImmediateContext,0); } //-------------------------------------------------------------------------------------- // Release D3D11 resources created in OnD3D11ResizedSwapChain //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11ReleasingSwapChain( void* pUserContext ) { } //-------------------------------------------------------------------------------------- // Release D3D11 resources created in OnD3D11CreateDevice //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11DestroyDevice( void* pUserContext ) { g_Mesh.Destroy(); SAFE_RELEASE(g_pVertexShader11); SAFE_RELEASE(g_pPixelShader11); SAFE_RELEASE(g_pcbVSPerObject11); SAFE_RELEASE(g_pcbVSPerFrame11); SAFE_RELEASE(g_pLayout11); } //-------------------------------------------------------------------------------------- // Handle messages to the application //-------------------------------------------------------------------------------------- LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ) { g_Camera.HandleMessages(hWnd,uMsg,wParam,lParam); return 0; } //-------------------------------------------------------------------------------------- // Handle key presses //-------------------------------------------------------------------------------------- void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext ) { } //-------------------------------------------------------------------------------------- // Handle mouse button presses //-------------------------------------------------------------------------------------- void CALLBACK OnMouse( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext ) { } //-------------------------------------------------------------------------------------- // Call if device was removed. Return true to find a new device, false to quit //-------------------------------------------------------------------------------------- bool CALLBACK OnDeviceRemoved( void* pUserContext ) { return true; } //-------------------------------------------------------------------------------------- // Initialize everything and go into a render loop //-------------------------------------------------------------------------------------- int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ) { // Enable run-time memory check for debug builds. #if defined(DEBUG) | defined(_DEBUG) _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif // DXUT will create and use the best device (either D3D9 or D3D11) // that is available on the system depending on which D3D callbacks are set below // Set general DXUT callbacks DXUTSetCallbackFrameMove( OnFrameMove ); DXUTSetCallbackKeyboard( OnKeyboard ); DXUTSetCallbackMouse( OnMouse ); DXUTSetCallbackMsgProc( MsgProc ); DXUTSetCallbackDeviceChanging( ModifyDeviceSettings ); DXUTSetCallbackDeviceRemoved( OnDeviceRemoved ); // Set the D3D11 DXUT callbacks. Remove these sets if the app doesn't need to support D3D11 DXUTSetCallbackD3D11DeviceAcceptable( IsD3D11DeviceAcceptable ); DXUTSetCallbackD3D11DeviceCreated( OnD3D11CreateDevice ); DXUTSetCallbackD3D11SwapChainResized( OnD3D11ResizedSwapChain ); DXUTSetCallbackD3D11FrameRender( OnD3D11FrameRender ); DXUTSetCallbackD3D11SwapChainReleasing( OnD3D11ReleasingSwapChain ); DXUTSetCallbackD3D11DeviceDestroyed( OnD3D11DestroyDevice ); // Perform any application-level initialization here DXUTInit( true, true, NULL ); // Parse the command line, show msgboxes on error, no extra command line params DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen DXUTCreateWindow( L"EmptyProject11" ); // Only require 10-level hardware DXUTCreateDevice( D3D_FEATURE_LEVEL_10_0, true, 640, 480 ); DXUTMainLoop(); // Enter into the DXUT render loop // Perform any application-level cleanup here return DXUTGetExitCode(); }
Ich hoffe jemand kann mir helfen denn ich bin echt schon am verzweifeln. Vergleiche mit dem Tutorial bringen mich auch nicht weiter.
Die SimpleSample.hlsl ist von der CD aus dem Buch und funktioniert bei einem vorherigen Bsp super.
-
verkleiner dein Problem mal auf das Minimale. So schaut sich da sniemand durch.
-
Ich glaube ich habe das Problem gefunden. Ich dachte das Beispiel im Buch wäre schon zu Ende nur ist es das noch nicht. Das heißt das ist kein vollständiger sourcecode.
/closed
-
Hallo!
Habe noch immer das Problem dass mein Mesh nicht angezeigt wird.
Hier der wichtigste Code:HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; //search hlsl file WCHAR str[MAX_PATH]; DXUTFindDXSDKMediaFileCch(str,MAX_PATH,L"SimpleSample.hlsl"); DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) // Set the D3DCOMPILE_DEBUG flag to embed debug information in the shaders. // Setting this flag improves the shader debugging experience, but still allows // the shaders to be optimized and to run exactly the way they will run in // the release configuration of this program. dwShaderFlags |= D3DCOMPILE_DEBUG; #endif //compile hlsl file ID3DBlob* pVertexShaderBuffer=NULL; D3DX11CompileFromFile(str,NULL,NULL,"RenderSceneVS","vs_4_0_level_9_1",dwShaderFlags,0,NULL,&pVertexShaderBuffer,NULL,NULL); ID3DBlob* pPixelShaderBuffer=NULL; D3DX11CompileFromFile(str,NULL,NULL,"RenderScenePS","ps_4_0_level_9_1",dwShaderFlags,0,NULL,&pPixelShaderBuffer,NULL,NULL); pd3dDevice->CreateVertexShader(pVertexShaderBuffer->GetBufferPointer(),pVertexShaderBuffer->GetBufferSize(),NULL,&g_pVertexShader11); pd3dDevice->CreatePixelShader(pPixelShaderBuffer->GetBufferPointer(),pPixelShaderBuffer->GetBufferSize(),NULL,&g_pPixelShader11); //vertex layout const D3D11_INPUT_ELEMENT_DESC layout[]= { {"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0}, {"NORMAL",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0}, {"TEXCOORD",0,DXGI_FORMAT_R32G32B32_FLOAT,0,24,D3D11_INPUT_PER_VERTEX_DATA,0}, }; V_RETURN(pd3dDevice->CreateInputLayout(layout,ARRAYSIZE(layout),pVertexShaderBuffer->GetBufferPointer(),pVertexShaderBuffer->GetBufferSize(),&g_pLayout11)); //set constants //buffer D3D11_BUFFER_DESC cbDesc; ZeroMemory(&cbDesc,sizeof(cbDesc)); cbDesc.Usage=D3D11_USAGE_DYNAMIC; cbDesc.BindFlags=D3D11_BIND_CONSTANT_BUFFER; cbDesc.CPUAccessFlags=D3D11_CPU_ACCESS_WRITE; cbDesc.ByteWidth=sizeof(CB_VS_PER_OBJECT); V_RETURN(pd3dDevice->CreateBuffer(&cbDesc,NULL,&g_pcbVSPerObject11)); cbDesc.ByteWidth=sizeof(CB_VS_PER_FRAME); V_RETURN(pd3dDevice->CreateBuffer(&cbDesc,NULL,&g_pcbVSPerFrame11)); //camera D3DXVECTOR3 vecEye(0.0f,0.0f,-5.0f); D3DXVECTOR3 vecAt(0.0f,0.0f,0.0f); g_Camera.SetViewParams(&vecEye,&vecAt); //models g_Mesh.Create(pd3dDevice,L"earth.sdkmesh",true); //release blobs SAFE_RELEASE(pVertexShaderBuffer); SAFE_RELEASE(pPixelShaderBuffer); return S_OK; } //-------------------------------------------------------------------------------------- // Create any D3D11 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { float fAspectRatio = pBackBufferSurfaceDesc->Width/(float)pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams(D3DX_PI/4,fAspectRatio,0.1f,1000.0f); g_Camera.SetWindow(pBackBufferSurfaceDesc->Width,pBackBufferSurfaceDesc->Height); g_Camera.SetButtonMasks(MOUSE_LEFT_BUTTON,MOUSE_WHEEL,MOUSE_MIDDLE_BUTTON); return S_OK; } //-------------------------------------------------------------------------------------- // Handle updates to the scene. This is called regardless of which D3D API is used //-------------------------------------------------------------------------------------- void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext ) { g_Camera.FrameMove(fElapsedTime); } //-------------------------------------------------------------------------------------- // Render the scene using the D3D11 device //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime, float fElapsedTime, void* pUserContext ) { //clear float ClearColor[4]={0.176f,0.196f,0.667f,0.0f}; ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView(); pd3dImmediateContext->ClearRenderTargetView(pRTV,ClearColor); D3DXMATRIX mWorld = *g_Camera.GetWorldMatrix(); D3DXMATRIX mView = *g_Camera.GetViewMatrix(); D3DXMATRIX mProj = *g_Camera.GetProjMatrix(); D3DXMATRIX mWorldViewProjection = mWorld * mView * mProj; HRESULT hr; D3D11_MAPPED_SUBRESOURCE MappedResource; V(pd3dImmediateContext->Map(g_pcbVSPerObject11,0,D3D11_MAP_WRITE_DISCARD,0,&MappedResource)); CB_VS_PER_OBJECT* pVSPerObject = (CB_VS_PER_OBJECT*) MappedResource.pData; //matrix D3DXMatrixTranspose(&pVSPerObject->m_mWorldViewProjection,&mWorldViewProjection); D3DXMatrixTranspose(&pVSPerObject->m_mWorld,&mWorld); //material pVSPerObject->m_MaterialAmbientColor=D3DXVECTOR4(0.3f,0.3f,0.3f,1.0f); pVSPerObject->m_MaterialDiffuseColor=D3DXVECTOR4(0.7f,0.7f,0.7f,1.0f); pd3dImmediateContext->Unmap(g_pcbVSPerObject11,0); //light pd3dImmediateContext->Map(g_pcbVSPerFrame11,0,D3D11_MAP_WRITE_DISCARD,0,&MappedResource); CB_VS_PER_FRAME* pVSPerFrame=(CB_VS_PER_FRAME*) MappedResource.pData; pVSPerFrame->m_vLightDir=D3DXVECTOR3(0.0f,0.707f,-0.707f); pVSPerFrame->m_LightDiffuse=D3DXVECTOR4(1.0f,1.0f,1.0f,1.0f); pd3dImmediateContext->Unmap(g_pcbVSPerFrame11,0); pd3dImmediateContext->IASetInputLayout(g_pLayout11); pd3dImmediateContext->VSSetConstantBuffers(0,1,&g_pcbVSPerObject11); pd3dImmediateContext->VSSetConstantBuffers(1,1,&g_pcbVSPerFrame11); pd3dImmediateContext->VSSetShader(g_pVertexShader11,NULL,0); pd3dImmediateContext->PSSetShader(g_pPixelShader11,NULL,0); //models g_Mesh.Render(pd3dImmediateContext,0); }
Leider kann man das nicht mehr weiter kürzen da ich selbst das Problem nicht weiter eingrenzen kann. Bei diesem Code wird der Hintergrund zwar in der richtigen Farbe angezeigt jedoch sehe ich nirgends das Mesh "earth.sdkmesh".
Bitte um Hilfe!
-
Was sagt die Ausgabe der Debug Runtime? Alle HRESULTs geprueft?
-
Die Ausgabe der debug runtime gibt lediglich eine warning, dass das standard sampler state verwendet wird. Die hresults muss ich noch prüfen jedoch müsste sonst ja eh ein fehler in der ebug runtime ausgegeben werden oder?
-
habe jetzt noch einmal die hresults gecheckt und hr ist immer auf S_OK