D3D Alpha Blend Boxes

Posts 115 of 18 · Page 1 of 2
D3D Alpha Blend Boxes
As some of you know I am working on a D3d Menu in Delphi, Anyway I am more interested about the AlphaBlending of D3DCOLOR as its 8bits(4Bytes) each byte representing A(alpha)R(red)G(green)B(blue) Problem is the Alpha tranperancy doesn't seem to be working lets say we had $FFFF0000 as the color this should be full Red with no transparent, If we Did $78FF0000 this should be just under 50% transparency, Question is why doesn't My box drawn have transparency??

This Demo menu below uses $78 for the Alpha Color and as you can see there is no transparency, I should be able to see the combat arms logo through the box.. Any Help or advice would be really nice

No Transparency:
Code:
pDevice->Clear(...);
does not support transparency. You have to use a sprite or draw a few primitives yourself.
Holy. Shit. You. Did. It.
Yeah I think I have to try the load Image from resource method, Found an example in C++ on GDeception, Which means more porting code over to Delphi and hoping it works

Thanks mmbob for the info
@depature, I'll PM you my textured quad class/wrapper when I get home. Supports alpha, rotation (in all axis) etc...

Should be easy to port over to Delphi
Quote Originally Posted by freedompeace View Post
@depature, I'll PM you my textured quad class/wrapper when I get home. Supports alpha, rotation (in all axis) etc...

Should be easy to port over to Delphi
hmm, arent them all?
Quote Originally Posted by topblast View Post


hmm, arent them all?
Aren't what all?

@Departure, sorry for the delay, still haven't been home :P
that is what i use for 2D textures

[highlight=c++]struct tVertex
{
float X, Y, Z, RHW;
float IU, IV;
enum FVF
{
FVF_Flags = (D3DFVF_XYZRHW | D3DFVF_TEX1)
};

};[/highlight]
Well I just ported Hans DrawBox which supports Alpha blending, but I get all weird shit in the test9.exe environment, can someone confirm his function still works???

Hans DrawBox:
Code:
void DrawBox(pD3DdeviceX pDevice, int x, int y, int w, int h, D3DCOLOR col)
{
	struct {
		float x,y,z,rhw;
		DWORD dwColor;
	} qV[4] = { { (float)x    , (float)(y+h), 0.0f, 0.0f, col},
				{ (float)x    , (float)y    , 0.0f, 0.0f, col},
				{ (float)(x+w), (float)(y+h), 0.0f, 0.0f, col},
				{ (float)(x+w), (float)y    , 0.0f, 0.0f, col} };

	pDevice->SetPixelShader(NULL);
    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    pDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
    pDevice->SetTexture(0, NULL);
    pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,qV,sizeof(qV[0]));
}


Mine Ported to Delphi:
[highlight=delphi]
procedure DrawBox(const iXleft, iYtop, iWidth, iHight: Integer; d3dARGB : D3DCOLOR);
type
tVertex = packed record
x, y, z, rhw: Single;
Color: D3DCOLOR;
end;
procedure AssignVertex(var Vertex: tVertex; x, y, z, rhw: Single; Color: D3DCOLOR);
begin
Vertex.x:= x; Vertex.y:= y; Vertex.z:= z; Vertex.rhw:= rhw;
Vertex.Color:= Color;
end;
var
qV: array[0..3] of tVertex;
begin

AssignVertex(qV[0], iXLeft, iYtop + iHight, 0.0, 0.0, d3dARGB);
AssignVertex(qV[1], iXLeft, iYtop, 0.0, 0.0, d3dARGB);
AssignVertex(qV[2], iXLeft + iWidth, iYtop + iHight, 0.0, 0.0, d3dARGB);
AssignVertex(qV[3], iXLeft + iWidth, iYtop, 0.0, 0.0, d3dARGB);

GetDevice.SetPixelShader(Nil);
GetDevice.SetRenderState(D3DRS_ALPHABLENDENABLE,1) ;
GetDevice.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ INVSRCALPHA);
GetDevice.SetTexture(0, Nil);
GetDevice.DrawPrimitiveUP(D3DPT_LINESTRIP,2,qV,Siz eOf(qV[0]));
//Old DrawRetangle
//GetDevice.Clear(1,@D3DRectangle, D3DCLEAR_TARGET, d3dARGB, 0, 0);
end;
[/highlight]
What does it look like in the environment?
Never mind Its fixed...

here is working Transparent box in Delphi

DrawBox:
[highlight=delphi]
procedure DrawBox(const iXleft, iYtop, iWidth, iHight: Integer; d3dARGB : D3DCOLOR);
type
tStruct = packed record
x, y, z, rhw: Single;
Color: dWord;
end;
procedure AssignVertex(var Vertex: tStruct; x, y, z, rhw: Single; Color: dWord);
begin
Vertex.x:= x; Vertex.y:= y; Vertex.z:= z; Vertex.rhw:= rhw;
Vertex.Color:= Color;
end;
var
qV: array[0..3] of tStruct;
begin

AssignVertex(qV[0], iXLeft, iYtop + iHight, 0.0, 0.0, d3dARGB);
AssignVertex(qV[1], iXLeft, iYtop, 0.0, 0.0, d3dARGB);
AssignVertex(qV[2], iXLeft + iWidth, iYtop + iHight, 0.0, 0.0, d3dARGB);
AssignVertex(qV[3], iXLeft + iWidth, iYtop, 0.0, 0.0, d3dARGB);

GetDevice.SetPixelShader(Nil);
GetDevice.SetRenderState(D3DRS_ALPHABLENDENABLE,1) ;
GetDevice.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ INVSRCALPHA);
GetDevice.SetTexture(0, Nil);
GetDevice.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,qV ,SizeOf(qV[0]));
end;
[/highlight]


Forgot to change the type when calling DrawPrimitiveUP, I was playing around yesterday before I got hold of hans's Function

Changed
GetDevice.DrawPrimitiveUP(D3DPT_LINESTRIP,2,qV,SizeOf(qV[0]));
to
GetDevice.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,qV,SizeOf(qV[0]));


//Edit

Danmm must be detected in Combat Arms I think its the call to DrawPrimiriveUP
Anyone have suggestions about bypassing the DrawPrimitiveUP Detection? I spent all that time working how to draw a alpha blended box only to have it detected Before I start looking into Sprite's to do the job instead, is there anything I should know about these getting detected? I dont really want to spend the next few hours learning about sprites and coding something to work only to have it detected in combat arms.


//Edit

I have decided not to go with Alpha Blended background for menu, I don't want to hook too many functions, its a recipe for disaster.... But I would like to know what the deal is with everyone hooking Reset and doing font stuff there? can someone please explain the reset stuff incase I need to look into hooking it..
@topblast, @whit

Going from TopBlast's structure and looking at gellins VIP base I came up with this...

Code:
procedure DrawBox(const iXleft, iYtop, iWidth, iHight: Integer; d3dARGB : D3DCOLOR);
type
  tStruct = packed record
    x, y, z, rhw: Single;
    Color: dWord;
    tu,tv: Single;
    VFV: dWord;
end;
procedure AssignVertex(var Vertex: tStruct; x, y, z, rhw: Single; Color: dWord; tu, tv: Single; VFV: dWord);
 begin
   Vertex.x:= x; Vertex.y:= y; Vertex.z:= z;  Vertex.rhw:= rhw;
   Vertex.Color:= Color;
   Vertex.tu:= tu;  Vertex.tv:= tv;
   Vertex.VFV:= VFV;
 end;
var
  qV: array[0..3] of tStruct;
begin

   AssignVertex(qV[0], iXLeft, iYtop, 0.0, 0.0, d3dARGB, 0.0, 0.0, D3DFVF_XYZRHW or D3DFVF_TEX1);
   AssignVertex(qV[1], iXLeft  + iWidth, iYtop, 0.0, 0.0, d3dARGB, 0.0, 0.0, D3DFVF_XYZRHW or D3DFVF_TEX1);
   AssignVertex(qV[2], iXLeft + iWidth, iYtop + iHight, 0.0, 0.0, d3dARGB, 0.0, 0.0, D3DFVF_XYZRHW or D3DFVF_TEX1);
   AssignVertex(qV[3], iXLeft, iYtop  + iHight, 0.0, 0.0, d3dARGB, 0.0, 0.0, D3DFVF_XYZRHW or D3DFVF_TEX1);

   GetDevice.SetPixelShader(Nil);
   GetDevice.SetRenderState(D3DRS_ALPHABLENDENABLE,1);
   GetDevice.SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
   GetDevice.SetTexture(0, Nil);
   GetDevice.DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,qV,SizeOf(tStruct));
end;
It works in the test9 environment, and works up untill the login then it disappears, Also when joining a game with it on it will crash on me, this is normally a good indication of it being detected. Can you recommend a solution?? is it the "DrawPrimitiveUP" thats getting detected? btw I am calling this function from hooked "Present"
I used to have troubles using a DrawBox method like this.
Code:
void FillBox( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* pDevice )
{
	D3DRECT rec = { x, y, x + w, y + h };
	pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
}
void DrawBorder( int x, int y, int w, int h, int px, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
{
	FillBox( x, (y + h - px), w, px,	BorderColor, pDevice );
	FillBox( x, y, px, h,				BorderColor, pDevice );
	FillBox( x, y, w, px,				BorderColor, pDevice );
	FillBox( (x + w - px), y, px, h,	BorderColor, pDevice );
}
void DrawBox( int x, int y, int w, int h, D3DCOLOR BoxColor, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
{
	FillBox( x, y, w, h,		BoxColor, pDevice );
	DrawBorder( x, y, w, h, 1,	BorderColor, pDevice );
}
This works perfectly fine.
When I use DrawPrimitiveUp, the boxes randomly dissapear.
Quote Originally Posted by flameswor10 View Post
I used to have troubles using a DrawBox method like this.
Code:
void FillBox( int x, int y, int w, int h, D3DCOLOR color, IDirect3DDevice9* pDevice )
{
	D3DRECT rec = { x, y, x + w, y + h };
	pDevice->Clear( 1, &rec, D3DCLEAR_TARGET, color, 0, 0 );
}
void DrawBorder( int x, int y, int w, int h, int px, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
{
	FillBox( x, (y + h - px), w, px,	BorderColor, pDevice );
	FillBox( x, y, px, h,				BorderColor, pDevice );
	FillBox( x, y, w, px,				BorderColor, pDevice );
	FillBox( (x + w - px), y, px, h,	BorderColor, pDevice );
}
void DrawBox( int x, int y, int w, int h, D3DCOLOR BoxColor, D3DCOLOR BorderColor, IDirect3DDevice9* pDevice )
{
	FillBox( x, y, w, h,		BoxColor, pDevice );
	DrawBorder( x, y, w, h, 1,	BorderColor, pDevice );
}
This works perfectly fine.
When I use DrawPrimitiveUp, the boxes randomly dissapear.
Yeah I already had this to start with but didn't support Alpha Blending(see first post) I really would have liked Alpha blending of the boxes
Posts 115 of 18 · Page 1 of 2

Post a Reply

Tags for this Thread

None

Need help?