SwaggaJackin' Master Cheater
Reputation: 2
Joined: 06 Nov 2009 Posts: 312
|
Posted: Thu Dec 22, 2011 3:05 pm Post subject: Direct3D overlapping shapes |
|
|
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.
|
|