Jump to content
  • Advertisement

shamexln

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

110 Neutral

About shamexln

  • Rank
    Newbie
  1.  m_spD3DDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1); but i shifting to D3D11. which can i replace D3DFVF_XYZRHW in d3d11?  
  2. Within Microsoft sample, it does work. the background color is  changed with second parameter.(Full-Screen)   But in my code, it doesn't work(background of control (static control))   I fill width and height of the DXGI_SWAP_CHAIN_DESC with the width and height of the static control. But doesn't work.  m_spContext->ClearRenderTargetView(m_spRenderTargetView, Colors::Lime); m_spDXGISwapChain->Present(0,0);  
  3. I'm porting D3D9 to D3D11 There are some function in code ################################################################## struct SCREEN_VERTEX  { D3DXVECTOR4 pos; D3DXVECTOR2 tex; };       // Ensure that we're directly mapping texels to pixels by offset by 0.5     // For more info see the doc page titled "Directly Mapping Texels to Pixels" float fWidth5 = (float)m_d3dPresentParam.BackBufferWidth - 0.5f; float fHeight5 = (float)m_d3dPresentParam.BackBufferHeight - 0.5f;       // Draw the quad     SCREEN_VERTEX svQuad[4];       svQuad[0].pos = D3DXVECTOR4(-0.5f, -0.5f, 0.5f, 1.0f);     svQuad[0].tex = D3DXVECTOR2(0, 0);       svQuad[1].pos = D3DXVECTOR4(fWidth5, -0.5f, 0.5f, 1.0f);     svQuad[1].tex = D3DXVECTOR2(1, 0);       svQuad[2].pos = D3DXVECTOR4(-0.5f, fHeight5, 0.5f, 1.0f);     svQuad[2].tex = D3DXVECTOR2(0, 1);       svQuad[3].pos = D3DXVECTOR4(fWidth5, fHeight5, 0.5f, 1.0f);     svQuad[3].tex = D3DXVECTOR2(1, 1);   m_spD3DDevice->SetTexture(0, pTexture);     m_spD3DDevice->SetRenderState(D3DRS_ZENABLE, FALSE);     m_spD3DDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);     m_spD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, svQuad, sizeof(SCREEN_VERTEX));     m_spD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE); m_spD3DDevice->SetTexture(0, NULL); ##################################################################   Because of D3DFVF_XYZRHW , the vertex is the Transformed vertex position. How can i do with it in HLSL. for example in HLSL struct VS_INPUT { float4 Pos: POSITION;  // maybe POSITIONT };   struct PS_INPUT { float4 Pos: SV_POSITION; };   PS_INTPUT VS(VS_INPUT input) { PS_INPUT output = (PS_INPUT)0; out.Pos = input.Pos; return output; }   float4 PS(PS_INPUT input):SV_Target { return float4(1.0f, 1.0f,1.0f,1.0f);   } ?
  4. There is VSShader and PSShader code ----------------------------------------------------------------------   cbuffer cbNeverChanges : register( b0 ) {     matrix View; };   cbuffer cbChangeOnResize : register( b1 ) {     matrix Projection; };   cbuffer cbChangesEveryFrame : register( b2 ) {     matrix World; };     //-------------------------------------------------------------------------------------- struct VS_INPUT {     float4 Pos : POSITION;   };   struct PS_INPUT {     float4 Pos : SV_POSITION;   };     //-------------------------------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------------------------------- PS_INPUT VS( VS_INPUT input ) {     PS_INPUT output = (PS_INPUT)0;       output.Pos = mul( output.Pos, View );     output.Pos = mul( output.Pos, Projection );            return output; }   //-------------------------------------------------------------------------------------- // Pixel Shader //-------------------------------------------------------------------------------------- float4 PS( PS_INPUT input) : SV_Target {   return float4( 1.0f, 1.0f, 1.0f, 1.0f );    // Yellow, with Alpha = 1     }   ----------------------------------------------------------------------
  5. Sorry for my poor english. I'm shifting  D3D9 to D3D11.   There are code with D3D9 --------------------------------------------------------------------------------------------- HSASSERT(pTexture != NULL); ON_ERROR_RETURN(pTexture == NULL, E_INVALIDARG);   struct SCREEN_VERTEX  { D3DXVECTOR4 pos; D3DXVECTOR2 tex;   };       // Ensure that we're directly mapping texels to pixels by offset by 0.5     // For more info see the doc page titled "Directly Mapping Texels to Pixels" float fWidth5 = (float)m_d3dPresentParam.BackBufferWidth - 0.5f; float fHeight5 = (float)m_d3dPresentParam.BackBufferHeight - 0.5f;       // Draw the quad     SCREEN_VERTEX svQuad[4];       svQuad[0].pos = D3DXVECTOR4(-0.5f, -0.5f, 0.5f, 1.0f);     svQuad[0].tex = D3DXVECTOR2(0, 0);           svQuad[1].pos = D3DXVECTOR4(fWidth5, -0.5f, 0.5f, 1.0f);     svQuad[1].tex = D3DXVECTOR2(1, 0);         svQuad[2].pos = D3DXVECTOR4(-0.5f, fHeight5, 0.5f, 1.0f);     svQuad[2].tex = D3DXVECTOR2(0, 1);         svQuad[3].pos = D3DXVECTOR4(fWidth5, fHeight5, 0.5f, 1.0f);     svQuad[3].tex = D3DXVECTOR2(1, 1);     m_spD3DDevice->SetTexture(0, pTexture);     m_spD3DDevice->SetRenderState(D3DRS_ZENABLE, FALSE); m_spD3DDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);       m_spD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, svQuad, sizeof(SCREEN_VERTEX));     m_spD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE); m_spD3DDevice->SetTexture(0, NULL); ------------------------------------------------------------------------------------------   I shift it with D3D11 as below bit doesn't work. Would you tell me what's the problem with it? it will crash because of out of memory.(I think I released memory already) ---------------------------------------------------------------------------------------- // Compile the vertex shader ID3DBlob* pVSBlob = nullptr; hr = CompileShaderFromFile( L"R:\\AddInApps\\AIT\\AITLibrary\\Src\\LibPreview\\Tutorial02.fx", "VS", "vs_4_0", &pVSBlob ); HSASSERT(SUCCEEDED(hr)); ON_ERROR_RETURN(FAILED(hr), hr);   // Create the vertex shader hr = m_spD3DDevice->CreateVertexShader( pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), nullptr, &m_spD3D11VertexShader ); HSASSERT(SUCCEEDED(hr)); ON_ERROR_RETURN(FAILED(hr), hr);   // Define the input layout D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, //{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE( layout );   // Create the input layout hr = m_spD3DDevice->CreateInputLayout( layout, numElements, pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), &m_spD3D11InputLayout ); pVSBlob->Release(); HSASSERT(SUCCEEDED(hr)); ON_ERROR_RETURN(FAILED(hr), hr);   // Set the input layout m_spD3D11DeviceContext->IASetInputLayout( m_spD3D11InputLayout ); m_spD3D11InputLayout->Release();   // Compile the pixel shader ID3DBlob* pPSBlob = nullptr; hr = CompileShaderFromFile( L"R:\\AddInApps\\AIT\\AITLibrary\\Src\\LibPreview\\Tutorial02.fx", "PS", "ps_4_0", &pPSBlob ); HSASSERT(SUCCEEDED(hr)); ON_ERROR_RETURN(FAILED(hr), hr);   // Create the pixel shader hr = m_spD3DDevice->CreatePixelShader( pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), nullptr, &m_spD3D11PixelShader ); pPSBlob->Release(); HSASSERT(SUCCEEDED(hr)); ON_ERROR_RETURN(FAILED(hr), hr); }   // Set ViewPort { float width = (FLOAT)m_d3dDXGISwapChainDesc.BufferDesc.Width; float height = (FLOAT)m_d3dDXGISwapChainDesc.BufferDesc.Height; // Setup the viewport D3D11_VIEWPORT vp; vp.Width = (FLOAT)width; vp.Height = (FLOAT)height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; m_spD3D11DeviceContext->RSSetViewports( 1, &vp ); }   // Create Vertex Buffer     // Ensure that we're directly mapping texels to pixels by offset by 0.5 // For more info see the doc page titled "Directly Mapping Texels to Pixels" float fWidth5 = (float)m_d3dDXGISwapChainDesc.BufferDesc.Width - 0.5f; float fHeight5 = (float)m_d3dDXGISwapChainDesc.BufferDesc.Height - 0.5f;   // Draw the quad SCREEN_VERTEX svQuad[4];   svQuad[0].pos = XMFLOAT4(-0.5f, -0.5f, 0.5f, 1.0f); //svQuad[0].tex = XMFLOAT2(0, 0);   svQuad[1].pos = XMFLOAT4(fWidth5, -0.5f, 0.5f, 1.0f); //svQuad[1].tex = XMFLOAT2(1, 0);   svQuad[2].pos = XMFLOAT4(-0.5f, fHeight5, 0.5f, 1.0f); //svQuad[2].tex = XMFLOAT2(0, 1);   svQuad[3].pos = XMFLOAT4(fWidth5, fHeight5, 0.5f, 1.0f); //svQuad[3].tex = XMFLOAT2(1, 1);   D3D11_BUFFER_DESC bd; ZeroMemory( &bd, sizeof(bd) ); bd.Usage = D3D11_USAGE_DEFAULT; bd.ByteWidth = sizeof( SCREEN_VERTEX ) * 4; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; D3D11_SUBRESOURCE_DATA InitData; ZeroMemory( &InitData, sizeof(InitData) ); InitData.pSysMem = svQuad; hr = m_spD3DDevice->CreateBuffer( &bd, &InitData, &m_spD3D11VertexBuffer ); HSASSERT(SUCCEEDED(hr)); ON_ERROR_RETURN(FAILED(hr), hr);   // Set vertex buffer UINT stride = sizeof( SCREEN_VERTEX ); UINT offset = 0; m_spD3D11DeviceContext->IASetVertexBuffers( 0, 1, &m_spD3D11VertexBuffer, &stride, &offset ); m_spD3D11VertexBuffer->Release();   // Set primitive topology m_spD3D11DeviceContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);     // Create the constant buffers bd.Usage = D3D11_USAGE_DEFAULT;     bd.ByteWidth = sizeof(CBNeverChanges);     bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;     bd.CPUAccessFlags = 0;     hr = m_spD3DDevice->CreateBuffer( &bd, nullptr, &m_spD3D11CBNeverChanges );     if( FAILED( hr ) )         return hr;          bd.ByteWidth = sizeof(CBChangeOnResize);     hr = m_spD3DDevice->CreateBuffer( &bd, nullptr, &m_spD3D11CBChangeOnResize );     if( FAILED( hr ) )         return hr;          bd.ByteWidth = sizeof(CBChangesEveryFrame);     hr = m_spD3DDevice->CreateBuffer( &bd, nullptr, &m_spD3D11CBChangesEveryFrame );     if( FAILED( hr ) )         return hr;     hr = this->OnResetD3DDevice(); HSASSERT(SUCCEEDED(hr)); ON_ERROR_RETURN(FAILED(hr), hr);   // Render a triangle         CBNeverChanges cbNeverChanges; XMFLOAT4X4 tmpView = m_camera.GetViewMatrix(); m_View = XMLoadFloat4x4(&tmpView);     cbNeverChanges.mView = XMMatrixTranspose( m_View );     m_spD3D11DeviceContext->UpdateSubresource( m_spD3D11CBNeverChanges, 0, nullptr, &cbNeverChanges, 0, 0 );       // Initialize the projection matrix XMFLOAT4X4 tmpProjection = m_camera.GetProjMatrix();     m_Projection = XMLoadFloat4x4(&tmpProjection);     CBChangeOnResize cbChangesOnResize;     cbChangesOnResize.mProjection = XMMatrixTranspose( m_Projection );     m_spD3D11DeviceContext->UpdateSubresource( m_spD3D11CBChangeOnResize, 0, nullptr, &cbChangesOnResize, 0, 0 );     m_spD3D11DeviceContext->VSSetConstantBuffers( 0, 1, &m_spD3D11CBNeverChanges );     m_spD3D11DeviceContext->VSSetConstantBuffers( 1, 1, &m_spD3D11CBChangeOnResize );       m_spD3D11DeviceContext->VSSetShader( m_spD3D11VertexShader, nullptr, 0 ); m_spD3D11DeviceContext->PSSetShader( m_spD3D11PixelShader, nullptr, 0 );     m_spD3D11DeviceContext->Draw( 4, 0 ); m_spD3D11VertexShader->Release(); m_spD3D11PixelShader->Release(); m_spD3D11CBNeverChanges->Release(); m_spD3D11CBChangeOnResize->Release(); m_spD3D11CBChangesEveryFrame->Release();   } ----------------------------------------------------------------------------------------
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!