示例#1
0
        static void Main(string[] args)
        {
            using (Program program = new Program())
                using (TMOForm form = new TMOForm())
                    if (program.InitializeApplication(form))
                    {
                        Console.WriteLine("Test succeeded.");

                        /*
                         * // While the form is still valid, render and process messages
                         * while (form.Created)
                         * {
                         *  Application.DoEvents();
                         * }
                         */
                    }
                    else
                    {
                        Console.WriteLine("Test failed.");
                    }
        }
示例#2
0
        public bool InitializeApplication(TMOForm form)
        {
            PresentParameters pp = new PresentParameters();

            try
            {
                // Set up the structure used to create the D3DDevice. Since we are now
                pp.Windowed               = true;
                pp.SwapEffect             = SwapEffect.Discard;
                pp.BackBufferFormat       = Format.X8R8G8B8;
                pp.BackBufferCount        = 1;
                pp.EnableAutoDepthStencil = true;
                pp.AutoDepthStencilFormat = DepthFormat.D16;

                int ret, quality;
                if (Manager.CheckDeviceMultiSampleType((int)Manager.Adapters.Default.Adapter, DeviceType.Hardware, pp.BackBufferFormat, pp.Windowed, MultiSampleType.FourSamples, out ret, out quality))
                {
                    pp.MultiSample        = MultiSampleType.FourSamples;
                    pp.MultiSampleQuality = quality - 1;
                }

                // Create the D3DDevice
                device = new Device(0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, pp);
            }
            catch (DirectXException ex)
            {
                Console.WriteLine("Error: " + ex);
                return(false);
            }
            string effect_file = @"toonshader.cgfx";

            if (!File.Exists(effect_file))
            {
                Console.WriteLine("File not found: " + effect_file);
                return(false);
            }
            string compile_error;

            effect = Effect.FromFile(device, effect_file, null, ShaderFlags.None, null, out compile_error);
            if (compile_error != null)
            {
                Console.WriteLine(compile_error);
                return(false);
            }

            Console.WriteLine("Parameters:");
            int nparam = effect.Description.Parameters;

            for (int i = 0; i < nparam; i++)
            {
                EffectHandle param = effect.GetParameter(null, i);
                DumpParameter(param, i);
            }

            Console.WriteLine("Techniques:");
            int ntech = effect.Description.Techniques;

            for (int i = 0; i < ntech; i++)
            {
                EffectHandle tech = effect.GetTechnique(i);
                DumpTechnique(tech, i);
            }

            Console.WriteLine("Valid techniques:");
            {
                EffectHandle tech = null;
                while ((tech = effect.FindNextValidTechnique(tech)) != null)
                {
                    TechniqueDescription td = effect.GetTechniqueDescription(tech);
                    Console.WriteLine("\t{0}", td.Name);
                }
            }
            return(true);
        }