Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello,

I'm busy with creating an eye that follows movements.

Like this example -
http://hackaday.com/2011/10/27/vigos-stare-follows-you-wherever-you-go/[^]

Everything works great.

But now I want to add a picture on it. Like the example.

Not as background but as front so that it looks like that the eye is in the picture.

My question is how can I do that.

Thanks a lot for helping
Posted
Updated 2-Nov-11 5:03am
v2

1 solution

I have found the problem.
This is the solution. (you don't find any solutions for this problem).

private Device device;
private Texture texture;
private Material material;
private Sprite sprite;
Surface s;
SurfaceDescription desc;
public Form1()
{
    InitializeComponent();
    this.SetStyle(ControlStyles.AllPaintingInWmPaint |
    ControlStyles.Opaque, true);
}

public void InitializeDevice()
{
    PresentParameters presentParams = new PresentParameters();
    presentParams.Windowed = true;
    presentParams.SwapEffect = SwapEffect.Discard;
    presentParams.AutoDepthStencilFormat = DepthFormat.D16;
    presentParams.EnableAutoDepthStencil = true;
    device = new Device(0, DeviceType.Hardware, this,
    CreateFlags.SoftwareVertexProcessing, presentParams);
    sprite = new Sprite(device);
    device.RenderState.Lighting = false;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
    device.RenderState.AlphaBlendEnable = true;
    device.RenderState.AlphaTestEnable = false;
    device.RenderState.SourceBlend = Blend.SourceAlpha;
    device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
    device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
    device.BeginScene();
    sprite.Begin(SpriteFlags.AlphaBlend);
    sprite.Draw2D(texture, new Point(0,0),0, new Point(0,0),
    Color.White); // you must set the color as white
    device.RenderState.AlphaBlendEnable = false;
    sprite.End();
    device.EndScene();
    device.Present();
    this.Invalidate();
}
public void LoadTexturesAndMaterials()
{
    material = new Material();
    material.Diffuse = Color.White;
    material.Specular = Color.LightGray;
    material.SpecularSharpness = 15.0F;
    device.Material = material;
    string path = Application.StartupPath;
    texture = TextureLoader.FromFile(device, @path + "\\image.png"
    // add this when you give a color on the transparent part.
    //like Fuchsia.
    /*, 1024, 768, 1, 0, Format.Unknown, Pool.Default, Filter.Linear,
    Filter.Linear,Color.Fuchsia.ToArgb()*/);
    s = texture.GetSurfaceLevel(0);
    desc = s.Description;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900