Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Direct3D overlapping shapes

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
SwaggaJackin'
Master Cheater
Reputation: 2

Joined: 06 Nov 2009
Posts: 312

PostPosted: Thu Dec 22, 2011 3:05 pm    Post subject: Direct3D overlapping shapes Reply with quote

I've currently written an overlay that will display a HUD for me. I'm having an issue with drawing boxes however, here is the code I use to draw a box with an outline, where 'device' is my direct3D (DirectX9) device:

Code:


private void mainloop()
{
   while (true) {
      render();
   }
}

private void render()
{
   device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0), 1f, 0);
   device.RenderState.ZBufferEnable = false;
   device.RenderState.Lighting = false;
   device.RenderState.CullMode = Cull.None;
   device.Transform.Projection = Matrix.OrthoOffCenterLH(0, this.Width, this.Height, 0, 0, 1);

   device.BeginScene();
   device.VertexFormat = CustomVertex.TransformedColored.Format;
   draw();
   device.EndScene();
   device.Present();

}

private void draw_box(int x1, int x2, int y1, int y2, int fill, int outl)
{
            CustomVertex.TransformedColored[] box = new CustomVertex.TransformedColored[6];
            CustomVertex.TransformedColored[] outl = new CustomVertex.TransformedColored[8];
     
            for (i = 0; i <= 7; i++) {
                    if (i < 6) {
                            box(i).Color = fill;
                    }
                    outl(i).Color = outll;
            }
     
            box(0).Position = new Vector4(x1, y1, 0, 1);
            box(1).Position = new Vector4(x2, y1, 0, 1);
            box(2).Position = new Vector4(x1, y2, 0, 1);
            box(3).Position = new Vector4(x1, y2, 0, 1);
            box(4).Position = new Vector4(x2, y2, 0, 1);
            box(5).Position = new Vector4(x2, y1, 0, 1);
     
            outl(0).Position = new Vector4(x1, y1, 0, 1);
            outl(1).Position = new Vector4(x2, y1, 0, 1);
            outl(2).Position = new Vector4(x2, y1, 0, 1);
            outl(3).Position = new Vector4(x2, y2, 0, 1);
            outl(4).Position = new Vector4(x2, y2, 0, 1);
            outl(5).Position = new Vector4(x1, y2, 0, 1);
            outl(6).Position = new Vector4(x1, y2, 0, 1);
            outl(7).Position = new Vector4(x1, y1, 0, 1);
     
            device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, box);
            device.DrawUserPrimitives(PrimitiveType.LineList, 4, outl);
}

private void draw()
{
            draw_box(300, 400, 300, 400, 0x20ff0000, Color.Black.ToArgb);
            draw_box(300, 350, 350, 450, 0x600cff00, Color.Black.ToArgb);
}


The box is drawn the way I want it, however, when the boxes overlap, the 2nd box will draw over the first:



Now I made both a transparent color and the outline is opaque. How do I make it so the first box is transparent and the one underneath can be seen?

I assumed I had to make 2 direct3d devices and have the 2nd box on the 2nd device, however this causes flickering when I call present() for both devices.

How can I solve this? Thanks.
Back to top
View user's profile Send private message
SwaggaJackin'
Master Cheater
Reputation: 2

Joined: 06 Nov 2009
Posts: 312

PostPosted: Sun Dec 25, 2011 12:36 am    Post subject: Reply with quote

Solved. Had to enable alpha blending.

Code:

device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.BothSourceAlpha;
device.RenderState.DestinationBlend = Blend.InvBlendFactor;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites