Original Post
I don't understand why this texture that I am trying to draw won't come up. All I get is a screen of black. I checked the values of the vertices in the debug window and the triangle should be in view: (These are the functions where I set up my vertices)
public void Init3D()
{
d3d = new Direct3D ();
PresentParameters pparams = new PresentParameters ();
pparams.BackBufferHeight = this.Height;
pparams.BackBufferWidth = this.Width;
pparams.DeviceWindowHandle = this.Handle;
pparams.SwapEffect = SwapEffect.Discard;
pparams.Windowed = true;
pparams.BackBufferFormat = Format.Unknown;
device = new Device ( d3d, 0, DeviceType.Hardware, this.Handle, CreateFlags.HardwareVertexProcessing, pparams );
texture = Texture.FromFile ( device, "C:\\Projects\\Jareds_CS_Projects\\SlimDxGame\\Resources\\image.png" );
vertBuffer = new VertexBuffer ( device,
D3DX.GetFVFVertexSize ( TexturedVertex.FVFFormat ) * 4,
Usage.None, VertexFormat.None,
Pool.Default );
DataStream stream = vertBuffer.Lock ( 0, 0, LockFlags.None );
Vector3 Position = new Vector3 (5, 5, 5);
Vector2 Size = new Vector2 ( 1, 1 );
TexturedVertex[] verts = new TexturedVertex[4]
{
new TexturedVertex( new Vector3(Position.X, Position.Y, Position.Z), Color.White.ToArgb(), 0.0f, 0.0f ), //upper left
new TexturedVertex( new Vector3(Position.X + Size.X, Position.Y, Position.Z), Color.White.ToArgb(), 0.0f, 1.0f), //upper right
new TexturedVertex( new Vector3(Position.X, Position.Y + Size.Y, Position.Z), Color.White.ToArgb(), 1.0f, 0.0f ), //bottom left
new TexturedVertex( new Vector3(Position.X + Size.X, Position.Y + Size.Y, Position.Z), Color.White.ToArgb(), 1.0f, 1.0f)
};
stream.WriteRange ( verts );
vertBuffer.Unlock ();
SetUpCamera ();
}
public void Render()
{
device.Viewport = new Viewport ( 0, 0, this.Width, this.Height, 1, 100 );
device.VertexFormat = TexturedVertex.FVFFormat;
device.Clear ( ClearFlags.ZBuffer | ClearFlags.Target, Color.Black.ToArgb (), 1.0f, 0 );
device.BeginScene ();
Matrix projection = Matrix.PerspectiveFovLH ( 0.785398163f, 640 / 480, 1, 10 );
device.SetTransform ( TransformState.Projection, projection );
Matrix view = Matrix.LookAtLH ( Vector3.Zero, new Vector3 ( 5, 5, 5 ), new Vector3 ( 0, 1, 0 ) );
device.SetTransform ( TransformState.View, view );
device.SetTransform ( TransformState.World, Matrix.AffineTransformation ( 10f, Vector3.Zero, Quaternion.RotationYawPitchRoll ( 0f, 0f, 0f ), new Vector3 ( 1, 1, 1 ) ) );
device.SetTexture ( 0, texture );
device.SetRenderState ( RenderState.Lighting, false );
device.SetStreamSource ( 0, vertBuffer, 0, D3DX.GetFVFVertexSize ( TexturedVertex.FVFFormat ) );
device.DrawPrimitives ( PrimitiveType.TriangleStrip, 0, 2 );
device.EndScene ();
device.Present ();
}