[Help]D3D9 DrawPrimitive problem

03/27/2013 17:15 Lazeboy#1
Hey,
i try to draw shapes with DrawPrimitive or DrawPrimitiveUP. I already searched long time in the web but i can not find any solution. Thats why i post here.
So lets start:
if i inject my dll in the test enviroment everything(menu, test-recangle, and some test of sprite involving) works but if i inject in "Fiesta" a game using Directx9 i only see the Text and Sprites. I read many codes and some of them was completely shit and some of them did it the same way i do.
Here my code:
Code:
#define D3DFVF_CUSTOMVERTEX2 (D3DFVF_XYZRHW| D3DFVF_DIFFUSE | D3DFVF_TEX1)
struct D3DVERTEX2
{
	float x;
	float y;
	float z;
	float rhw;
	D3DCOLOR color;
	float u,v;
};


void DrawFillRect(IDirect3DDevice9* dev, float x, float y, float width, float height, DWORD dwColor)
	{
                LPDIRECT3DVERTEXBUFFER9 pTriangleVB = NULL;
		VOID* pData;

		//Rectangle
		D3DVERTEX2 vertices[4];
		vertices[0].x = x;
		vertices[0].y = y;
		vertices[0].z = 1;
		vertices[0].rhw = 1.0f;
		vertices[0].u = 0;
		vertices[0].v = 0;
		vertices[0].color = D3DCOLOR_XRGB(255,0,0);
		vertices[1].x = x+width;
		vertices[1].y = y;
		vertices[1].z = 1;
		vertices[1].rhw = 1.0f;
		vertices[1].u = 0;
		vertices[1].v = 0;
		vertices[1].color = D3DCOLOR_XRGB(255,0,0);
		vertices[2].x = x;
		vertices[2].y = y+height;
		vertices[2].z = 1;
		vertices[2].rhw = 1.0f;
		vertices[2].u = 0;
		vertices[2].v = 0;
		vertices[2].color = D3DCOLOR_XRGB(255,0,0);
		vertices[3].x = x+width;
		vertices[3].y = y+height;
		vertices[3].z = 1;
		vertices[3].rhw = 1.0f;
		vertices[3].u = 0;
		vertices[3].v = 0;
		vertices[3].color = D3DCOLOR_XRGB(255,0,0);


		//dev->SetRenderState(D3DRS_LIGHTING, FALSE);
		dev->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
		//dev->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
		//dev->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
		//dev->SetRenderState(D3DRS_SRCBLENDALPHA, D3DRS_DESTBLENDALPHA);

		HRESULT es = dev->CreateVertexBuffer(sizeof(vertices),
			D3DUSAGE_WRITEONLY,
			D3DFVF_CUSTOMVERTEX2,
			D3DPOOL_MANAGED,
			&pTriangleVB,
			NULL);
		if(es != D3D_OK)
			WriteLog("Create: %x", es);

		pTriangleVB->Lock(0, sizeof(vertices), &pData, 0);
		memcpy(pData, vertices, sizeof(vertices));
		pTriangleVB->Unlock();

		LPDIRECT3DVERTEXBUFFER9 oldBuffer = NULL;
		UINT oldOffset = 0;
		UINT oldStride = 0;
		dev->GetStreamSource(0, &oldBuffer, &oldOffset, &oldStride);
		DWORD oldFVF = 0;
		dev->GetFVF(&oldFVF);
		//WriteLog("%x", oldFVF);
		//WriteLog("%x", D3DFVF_CUSTOMVERTEX2);
		
		dev->SetTexture(0, NULL);
		dev->SetFVF(D3DFVF_CUSTOMVERTEX2);
		dev->SetStreamSource(0, pTriangleVB, 0, sizeof(D3DVERTEX2));
		dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
		dev->SetFVF(oldFVF);
	}
regards Lazeboy
03/27/2013 21:21 Omdi#2
Use these render states and [Only registered and activated users can see links. Click Here To Register...] before rendering ;)
Code:
    m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
    m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR );
    m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR);
    m_pDevice->SetRenderState(D3DRS_LIGHTING, false);
    m_pDevice->SetRenderState(D3DRS_FOGENABLE, false);
    m_pDevice->SetRenderState(D3DRS_STENCILENABLE, false);
03/28/2013 00:09 Lazeboy#3
thx for the help but it does not work. nonetheless state blocks is a very nice function to save and apply renderstates :)
Code:
void DrawFillRect(IDirect3DDevice9* dev, float x, float y, float width, float height, DWORD dwColor)
	{

		LPDIRECT3DVERTEXBUFFER9 pTriangleVB = NULL;
		VOID* pData;

		//Rectangle
		D3DVERTEX vertices[4];
		vertices[0].x = x;
		vertices[0].y = y;
		vertices[0].z = 0;
		vertices[0].rhw = 1.0f;
		vertices[0].color =  dwColor;
		vertices[1].x = x+width;
		vertices[1].y = y;
		vertices[1].z = 0;
		vertices[1].rhw = 1.0f;
		vertices[1].color = dwColor;
		vertices[2].x = x;
		vertices[2].y = y+height;
		vertices[2].z = 0;
		vertices[2].rhw = 1.0f;
		vertices[2].color = dwColor;
		vertices[3].x = x+width;
		vertices[3].y = y+height;
		vertices[3].z = 0;
		vertices[3].rhw = 1.0f;
		vertices[3].color = dwColor;

	
		IDirect3DStateBlock9* pStateBlock = NULL;
		dev->CreateStateBlock(D3DSBT_ALL, &pStateBlock);

		pStateBlock->Capture();


		dev->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
		dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR );
		dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR);
		dev->SetRenderState(D3DRS_LIGHTING, false);
		dev->SetRenderState(D3DRS_FOGENABLE, false);
		dev->SetRenderState(D3DRS_STENCILENABLE, false);

		dev->CreateVertexBuffer(sizeof(vertices),
			D3DUSAGE_WRITEONLY,
			D3DFVF_CUSTOMVERTEX,
			D3DPOOL_MANAGED,
			&pTriangleVB,
			NULL);

		pTriangleVB->Lock(0, sizeof(vertices), &pData, 0);
		memcpy(pData, vertices, sizeof(vertices));
		pTriangleVB->Unlock();

		LPDIRECT3DVERTEXBUFFER9 oldBuffer = NULL;
		UINT oldOffset = 0;
		UINT oldStride = 0;
		dev->GetStreamSource(0, &oldBuffer, &oldOffset, &oldStride);
		DWORD oldFVF = 0;
		dev->GetFVF(&oldFVF);
		//WriteLog("%x", oldFVF);
		//WriteLog("%x", D3DFVF_CUSTOMVERTEX2);

		dev->SetFVF(D3DFVF_CUSTOMVERTEX);
		dev->SetStreamSource(0, pTriangleVB, 0, sizeof(D3DVERTEX));
		dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
		dev->SetFVF(oldFVF);

		pStateBlock->Apply();
	}
ragards Lazeboy
03/28/2013 00:14 Dr. Coxxy#4
try this:

Code:
		StateBlock->Capture();
		
		Device->SetFVF(FVFType);
		Device->SetTexture(0, 0);
		Device->SetVertexShader(0);
		Device->SetPixelShader(0);

		Device->SetRenderState(D3DRS_LIGHTING, FALSE);
		Device->SetRenderState(D3DRS_FOGENABLE, FALSE);
		Device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
		Device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
		Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
		Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
		Device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
		Device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
		Device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); // FALSE

		// setup texture addressing settings
		Device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
		Device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

		// setup colour calculations
		Device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		Device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
		Device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);

		// setup alpha calculations
		Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
		Device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
		Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

		// setup filtering
		Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
		Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

		// disable texture stages we do not need.
		Device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

		// setup scene alpha blending
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

		Device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
		Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		Device->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_INVDESTALPHA);
		Device->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ONE);
03/28/2013 01:34 Lazeboy#5
Quote:
Originally Posted by Dr. Coxxy View Post
try this:

Code:
		StateBlock->Capture();
		
		Device->SetFVF(FVFType);
		Device->SetTexture(0, 0);
		Device->SetVertexShader(0);
		Device->SetPixelShader(0);

		Device->SetRenderState(D3DRS_LIGHTING, FALSE);
		Device->SetRenderState(D3DRS_FOGENABLE, FALSE);
		Device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
		Device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
		Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
		Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
		Device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
		Device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
		Device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE); // FALSE

		// setup texture addressing settings
		Device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
		Device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

		// setup colour calculations
		Device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		Device->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
		Device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);

		// setup alpha calculations
		Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
		Device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
		Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

		// setup filtering
		Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
		Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

		// disable texture stages we do not need.
		Device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

		// setup scene alpha blending
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

		Device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
		Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
		Device->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_INVDESTALPHA);
		Device->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ONE);
thx that works ;) before i post here i tested Cullmode too but it only blinked so i forget it
Code:
dev->SetTexture(0, 0);
dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);