i am trying to get a simple rectangle being rendert in my directx 10 window.
In directx 9 i used following code which worked just fine:
#define D3DFVF ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE )struct vertex{ float x,y,z,rhw; DWORD dwColor;};DWORD _fvf;IDirect3DPixelShader9* tempp;IDirect3DVertexShader9* tempv;HRESULT DrawPrimitiveLine( LPDIRECT3DDEVICE9 pDevice, float fromX, float fromY, float toX, float toY, DWORD dwColor ){ vertex fillline[2] = { { (float)fromX, (float)fromY, 1.0f, 0.0f, dwColor}, { (float)toX, (float)toY, 1.0f, 0.0f, dwColor} }; HRESULT iRet = S_OK; pDevice->GetFVF(&_fvf); pDevice->GetPixelShader(&tempp); pDevice->GetVertexShader(&tempv); pDevice->SetTexture(0, NULL); pDevice->SetPixelShader(NULL); pDevice->SetRenderState(D3DRS_CLIPPING,FALSE); pDevice->SetFVF(D3DFVF); iRet = pDevice->DrawPrimitiveUP(D3DPT_LINESTRIP, 1, fillline, sizeof(vertex)); pDevice->SetVertexShader(tempv); pDevice->SetPixelShader(tempp); pDevice->SetFVF(_fvf); return iRet;}
As you see i dont need any pixelshaders or any advanced stuff (in my view). Just a simple
code which draws stuff at screenPositions i want. Nothing in 3d space either.
Now i converted the code to something like this based on a tutorial from directxtutorial.com
To be honest, i cannot seem to get this to work. Also tried it based on sprites but that doesnt
give me any success either. Could somebody point this out any further?
Effect:
char szEffect[] = "struct DATA""{"" float4 Pos : SV_POSITION;"" float4 Color : COLOR;""};""DATA VS(float4 Pos : POSITION, float4 Col : COLOR)""{"" DATA Data;"" Data.Pos = Pos;"" Data.Color = Col;"" return Data;""}""float4 PS(DATA Data) : SV_TARGET""{"" return Data.Color;""}""technique10 T0""{"" pass P0"" {"" SetVertexShader(CompileShader(vs_4_0, VS()));"" SetGeometryShader(NULL);"" SetPixelShader(CompileShader(ps_4_0, PS()));"" }""}";
class DX10Draw {public: private: //private data bool bInit; ID3D10Device* pDevice; public: //user functions void init(ID3D10Device* pDevice) { if(!bInit) { this->pDevice = pDevice; bInit = true; } } struct VERTEX { D3DXVECTOR3 Position; D3DXCOLOR Color; }; void drawBox(TEXCOLOR texColor, int x, int y, int w, int h) { VERTEX LineVertices[] = { {D3DXVECTOR3(x, y, 1.f), D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)}, {D3DXVECTOR3(x+w, y, 1.f), D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)}, {D3DXVECTOR3(x+w, y+h, 1.f), D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)}, {D3DXVECTOR3(x, y+h, 1.f), D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)}, }; ID3D10Buffer* pBuffer; D3D10_BUFFER_DESC bufferDesc; bufferDesc.Usage = D3D10_USAGE_DYNAMIC; bufferDesc.ByteWidth = sizeof(VERTEX) * 4; bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER; bufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bufferDesc.MiscFlags = 0; pDevice->CreateBuffer(&bufferDesc, NULL, &pBuffer); void* pData; pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pData); memcpy(pData, LineVertices, sizeof(LineVertices)); pBuffer->Unmap(); D3D10_INPUT_ELEMENT_DESC inputLayout[] = { // first input element: position {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0}, // second input element: color {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0} }; ID3D10Effect* pEffect; D3DX10CreateEffectFromMemory(szEffect, sizeof(szEffect), "myEffectName", NULL, NULL, "fx_4_0", 0, 0, pDevice, NULL, NULL, &pEffect, NULL, NULL); ID3D10EffectTechnique* pTechnique; ID3D10EffectPass* pPass; D3D10_PASS_DESC PassDesc; pTechnique = pEffect->GetTechniqueByIndex(0); pPass = pTechnique->GetPassByIndex(0); pPass->GetDesc(&PassDesc); ID3D10InputLayout* pVertexLayout; pDevice->CreateInputLayout(inputLayout, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &pVertexLayout); //from what i have seen i need some effect file for this :S as this func wants some signature to a shader pDevice->IASetInputLayout(pVertexLayout); pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_T RIANGLELIST); UINT stride = sizeof(VERTEX); UINT offset = 0; pDevice->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset); pDevice->Draw(0, 6); }};DX10Draw dx10Draw;
Thanks for any input!!
[Edited by - MedRamBO on August 23, 2010 6:38:48 AM]