Primitive Drawing

Started by
6 comments, last by Adam_42 13 years, 8 months ago
Hello,

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]
Advertisement
Use [ source ] tags. It is easier to extract your question, then.
Quote:Original post by phresnel
Use [ source ] tags. It is easier to extract your question, then.


Much better, thank you =) I used "code" before as i remembered that from some other forums.
Now you've nested your question into your sourcecode ;)
Quote:Original post by phresnel
Now you've nested your question into your sourcecode ;)


Fixed :) Hope anybody from this board knows a way to draw 2d lines from a screenpos to another =(
Quote:Could somebody point this out any further?

You have several hundred lines of code in which you're asking people to find an error. However, you haven't begun to debug it yourself.

If your code compiles and links, then basic debugging technique, at a minimum, calls for checking if functions are doing what you expect. Every function call gives some indication of success or failure. I'd suggest starting with that.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Deleted all not needed stuff such as the drawText methods to make all more readable. Basically i am wondering as just nothing comes up. If there would be a rectangle at wrong coords i could see whats going wrong, but i am not sure how to start in here.

I belive i forgot to initialize something but i will log the return values of the device virtual methods when i am bk from work.

Just wondering if anybody ever made a 2d drawing function either line or rectangle and could paste it in.
You might find it works better if you use D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP instead of D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST to draw lines with.

Also have you tried creating the DX10 device with the debug flag? That might produce some useful error messages to help debug the problem.

This topic is closed to new replies.

Advertisement