Sign in to follow this  
jdub

[SlimDX]Full Screen Program Screws up

Recommended Posts

This program works when in Windowed mode(Of course I have to set some Present Parameters differently and comment out a couple of form properties) but when I try to run it in full, It is frozen and does nothing:
       static void Main()
        {
            Form form = new Form ();
            form.ClientSize = new Size ( 600, 600 );
            form.Text = "Test Form";
            form.Visible = true;
            form.TopMost = true;
            form.FormBorderStyle = FormBorderStyle.None;
            form.WindowState = FormWindowState.Maximized;

            d3d = new Direct3D ();
            
            PresentParameters PresentParams = new PresentParameters ();
            PresentParams.BackBufferHeight = form.ClientRectangle.Height;
            PresentParams.BackBufferWidth = form.ClientRectangle.Width;
            PresentParams.DeviceWindowHandle = form.Handle;
            PresentParams.SwapEffect = SwapEffect.Discard;
            PresentParams.Windowed = false;
            PresentParams.BackBufferCount = 2;
            PresentParams.BackBufferFormat = Format.A16B16G16R16;
            
            UnTransformedVertex[] triVerts = new UnTransformedVertex[3];
            triVerts[0].Position = new Vector3 ( 10.0f, 130.0f, 30.0f );
            triVerts[0].Color = Color.Green.ToArgb ();
            triVerts[1].Position = new Vector3 ( 1.0f, 20.0f, 30.0f );
            triVerts[1].Color = Color.Blue.ToArgb ();
            triVerts[2].Position = new Vector3 ( 3.0f, 3.0f, 3.0f );
            triVerts[2].Color = Color.Red.ToArgb ();

            d3dDevice = new Device ( d3d, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, PresentParams );

            triangleBuff = new VertexBuffer ( d3dDevice, System.Runtime.InteropServices.Marshal.SizeOf(triVerts[0]) * 3, Usage.WriteOnly, VertexFormat.None, Pool.Managed );

            DataStream stream = triangleBuff.Lock ( 0, 0, LockFlags.None );
            
            
            stream.WriteRange ( triVerts );
            triangleBuff.Unlock ();

            Matrix ProjectionMat = Matrix.PerspectiveFovLH ( 0.85123f, 640 / 480, 2, 300 );
            Matrix CameraLookAt = Matrix.LookAtLH ( new Vector3 ( 100, 100, 100 ), Vector3.Zero, new Vector3 ( 0, 1, 0 ) );
            

            d3dDevice.SetTransform ( TransformState.View, CameraLookAt );
            d3dDevice.SetTransform ( TransformState.World, Matrix.Identity );
            d3dDevice.SetTransform ( TransformState.Projection, ProjectionMat );

            d3dDevice.SetRenderState ( RenderState.Lighting, false );

            Application.Idle += new EventHandler(Program.OnIdle);

            Application.Run (form);
            
            d3dDevice.Dispose ();
            d3d.Dispose ();
            form.Dispose ();
        }

        public static void OnIdle( object obj, EventArgs eventArgs)
        {
            Message msg;
            UnTransformedVertex vert = new UnTransformedVertex ();

            while (!PeekMessage ( out msg, IntPtr.Zero, 0, 0, 0 ))
            {
                d3dDevice.Clear ( ClearFlags.ZBuffer,  Color.Blue.ToArgb(), 1.0f, 0 );
                d3dDevice.BeginScene ();

                d3dDevice.SetStreamSource ( 0, triangleBuff, 0, System.Runtime.InteropServices.Marshal.SizeOf(vert) );
                d3dDevice.VertexFormat = VertexFormat.Position | VertexFormat.Diffuse  ;
                d3dDevice.DrawPrimitives ( PrimitiveType.TriangleList, 0, 1);

                d3dDevice.EndScene ();
                d3dDevice.Present ();
            }
        }
    }

Got any ideas? thanks jdub.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this