Hi, i tried many times searched and used many methods
It did'nt work
The one on right is what i want to see
Full test code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SharpDX.Direct3D9;
using System.Threading;
using SharpDX;
namespace GridDrawTest
{
public partial class Form2 : Form
{
public struct CUSTOMVERTEX
{
public float x, y, z, rhw;
public int color;
public CUSTOMVERTEX(float x, float y, float z, float rhw, int c)
{
this.x = x;
this.y = y;
this.z = z;
this.rhw = rhw;
color = c;
}
}
RenderManager Mgr;
VertexBuffer bfr;
public Form2()
{
InitializeComponent();
pictureBox2.Image = new Bitmap(RenderWidth, RenderHeight);
Mgr = new RenderManager(pictureBox1.Handle/*Handle*/,RenderWidth,RenderHeight);
int numberoftiles = (RenderWidth / TileWidth) * (RenderHeight / TileHeight);
bfr = new VertexBuffer(Mgr.Device, numberoftiles * 4, Usage.None, VertexFormat.PositionRhw | VertexFormat.Diffuse, Pool.Default);
DataStream st = bfr.Lock(0, 0, LockFlags.None);
Graphics myImageGraphics = Graphics.FromImage(pictureBox2.Image);
for (int x = 0; x < RenderWidth / TileWidth; x++)
{
for (int y = 0; y < RenderHeight / TileHeight; y++)
{
int tx = x * (TileWidth);
int ty = y * (TileHeight);
System.Drawing.Rectangle r = new System.Drawing.Rectangle(tx,ty,TileWidth,TileHeight);
myImageGraphics.DrawRectangle(new Pen(System.Drawing.Color.Red), r);
byte[] b = new byte[] { 0/*Blue*/, 0/*Green*/, 255/*Red*/ , 0/*useless*/ };
int bgr = BitConverter.ToInt32(b,0);
CUSTOMVERTEX[] cv = new CUSTOMVERTEX[] {
new CUSTOMVERTEX(r.Right, r.Y, 0, 1f, bgr),
new CUSTOMVERTEX(r.X, r.Top, 0, 1f, bgr),
new CUSTOMVERTEX(r.Left, r.Y, 0, 1f, bgr),
new CUSTOMVERTEX(r.X, r.Bottom, 0, 1f, bgr),
};
st.WriteRange(cv);
primitiveCount += 4;
}
}
myImageGraphics.Dispose();
bfr.Unlock();
Mgr.OnDraw += new SharpDX.Action(Mgr_OnDraw);
Thread render = new Thread(new ThreadStart(delegate{
while (true)
{
if (ActiveForm == this)
Mgr.Render();
}
}));
render.Start();
}
int primitiveCount = 0;
void Mgr_OnDraw()
{
Mgr.Device.Clear(ClearFlags.Target, new ColorBGRA(this.BackColor.ToArgb()), 0f, 1);
Mgr.Device.SetStreamSource(0, bfr, 0, 20/*sizeof(CUSTOMVERTEX)*/);
Mgr.Device.VertexFormat = VertexFormat.Diffuse | VertexFormat.PositionRhw;
Mgr.Device.DrawPrimitives(PrimitiveType.LineStrip, 0, primitiveCount);
}
int RenderWidth = 200;
int RenderHeight = 200;
int TileWidth = 32;
int TileHeight = 32;
private void Form2_Load(object sender, EventArgs e)
{
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Environment.Exit(0);
}
}
}