Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 17:49

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Help]D3D9 DrawPrimitive problem

Discussion on [Help]D3D9 DrawPrimitive problem within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
Lazeboy's Avatar
 
elite*gold: 0
Join Date: Jun 2008
Posts: 451
Received Thanks: 410
[Help]D3D9 DrawPrimitive problem

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
Lazeboy is offline  
Old 03/27/2013, 21:21   #2




 
Omdi's Avatar
 
elite*gold: 93616
Join Date: Apr 2010
Posts: 13,737
Received Thanks: 14,990
Use these render states and 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);
Omdi is offline  
Old 03/28/2013, 00:09   #3
 
Lazeboy's Avatar
 
elite*gold: 0
Join Date: Jun 2008
Posts: 451
Received Thanks: 410
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
Lazeboy is offline  
Old 03/28/2013, 00:14   #4
 
Dr. Coxxy's Avatar
 
elite*gold: 0
Join Date: Feb 2011
Posts: 1,206
Received Thanks: 736
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);
Dr. Coxxy is offline  
Old 03/28/2013, 01:34   #5
 
Lazeboy's Avatar
 
elite*gold: 0
Join Date: Jun 2008
Posts: 451
Received Thanks: 410
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);
Lazeboy is offline  
Reply


Similar Threads Similar Threads
[D3D9 Bases] Sprited D3D9 Base with many functions
02/20/2012 - WarRock Hacks, Bots, Cheats & Exploits - 1 Replies
Hey, I found a site where a free D3D Base is and it has much functions.. and if you have a question, they help you with teamviewer! ♥ and if wr-cheats is down, you can download the newest sirosix public there. Venom Hacks - Unreal Portal
[HOW TO]fix d3d9.dll problem
09/21/2011 - S4 League Hacks, Bots, Cheats & Exploits - 2 Replies
:D HI GUYS! I WILL SHOW YOU ON HOW TO FIX D3D9.DLL PROBLEM :D 1.GO TO START MENU 2.OPEN RUN 3.TYPE dxdiag, and go to directx files 4.OPEN S4_LAUNCHER 5.PLAY THE GAME!! (VERY EASY) (I DISCOVERED THIS MYSELF) :)) S4 LAUNCHER AND BYPASS :) http://www.elitepvpers.com/forum/s4-league-hacks- bots-cheats-exploits/1346103-releas-xtrap-bypass.h tml
D3D9 Problem
07/31/2011 - WarRock - 7 Replies
hey ich habe schon mehrere No menu hacks gemach "nicht alle hier gepostet" und habe mir nun ne D3D9 base besorgt da ich nun Menu hacks machen will. Ja ich weiß es ist dreist aber kann mir einer sagen wo ich Den Tietel ändern kan . sprich dies : http://img4.fotos-hochladen.net/uploads/screenngpy npvsurihm.png
d3d9.dll problem
07/20/2011 - Wolfteam - 7 Replies
Hey leute mein freund kann nicht WTIS spielen daher immer kommt wolfteam cant find d3d9.dll und er hat schon die in dem WTIS ordner die datai erstetzt was kann er noch machen LG
D3D9 Base Problem
06/07/2011 - WarRock - 2 Replies
Moin erst mal sry für diesen Thread hier ...;) aber da ich nicht mehr weiter weiß würde ich gerne um Hilfe bitte da ich die D3D9 Base von Blacklegend heruntergeladen habe kommt immer dieser fehler wie bekomme ich diesen fehler weg bitte?



All times are GMT +2. The time now is 17:49.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.