Solved Make transparant background

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,747
40,528
317
hai! i a new member :)
i wan't to make a new d3d menu, but i need source/coding for my background to transparant
pliss help me!

this my project d3d menu :
https://prntscr.com/a779wo
Are you using IDirect3DDevice9::Clear for the background rectangle? If so that method doesn't support alpha values.
You need to use sprites or vertex buffers. Try something like this:
C++:
void DrawFilledBox(UINT X, UINT Y, UINT W, UINT H, DWORD dwColour, IDirect3DDevice9 * pDevice;)
{
	if (!pDevice)
		return;

	CUSTOM_VERTEX cV[4] = //set up vertices
	{
		{
			static_cast<float>(X), static_cast<float>(Y + H), 0.0f, 1.0f, dwColour
		},
		{
			static_cast<float>(X), static_cast<float>(Y), 0.0f, 1.0f, dwColour
		},
		{
			static_cast<float>(X + W), static_cast<float>(Y + H), 0.0f, 1.0f, dwColour
		},
		{
			static_cast<float>(X + W), static_cast<float>(Y), 0.0f, 1.0f, dwColour
		}
	};

	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, cV, sizeof(CUSTOM_VERTEX));
}
Before you draw you need to set some specific renderstates:
C++:
//Buffers
DWORD dwOldAlphaBlendEnable, dwOldSrcBlend, dwOldDestBlend, dwOldCullmode;
IDirect3DPixelShader9 * pOldPixelShader;

void StartDrawing(IDirect3DDevice9 * pDevice)
{
        //Save old states
	pDevice->GetRenderState(D3DRS_ALPHABLENDENABLE, &dwOldAlphaBlendEnable);
	pDevice->GetRenderState(D3DRS_SRCBLEND, &dwOldSrcBlend);
	pDevice->GetRenderState(D3DRS_DESTBLEND, &dwOldDestBlend);
	pDevice->GetRenderState(D3DRS_CULLMODE, &dwOldCullmode);
	pDevice->GetPixelShader(&pOldPixelShader);

        //Set new states
	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	pDevice->SetPixelShader(nullptr);

	pDevice->SetFVF(CUSTOM_FVF);
	pDevice->SetTexture(0, nullptr);
}

And when you finished drawing you need to set the old/saved renderstates:
C++:
void EndDrawing(IDirect3DDevice9 * pDevice)
{
	if (!pDevice)
		return;
        //Set old states
	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, dwOldAlphaBlendEnable);
	pDevice->SetRenderState(D3DRS_SRCBLEND, dwOldSrcBlend);
	pDevice->SetRenderState(D3DRS_DESTBLEND, dwOldDestBlend);
	pDevice->SetRenderState(D3DRS_CULLMODE, dwOldCullmode);
	pDevice->SetPixelShader(pOldPixelShader);
}
Edit:
I forgot some definitions:
C++:
#define CUSTOM_FVF (D3DFVF_DIFFUSE | D3DFVF_XYZRHW | D3DFVF_TEX1)

struct CUSTOM_VERTEX
{
	float x, y, z, rhw;
	DWORD dwColour;
};
 
Last edited:

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,298
37,938
269
If you're drawing rects, does your colour not have an alpha? I'm pretty sure it does
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods