Ejemplo n.º 1
0
        public bool InitializeGraphics()
        {
            try
            {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed   = true;
                presentParams.SwapEffect = SwapEffect.Discard;
                state = new D3DState();


                state.graphics = new Microsoft.WindowsMobile.DirectX.Direct3D.Device(0, DeviceType.Default, control,
                                                                                     Direct3D.CreateFlags.MultiThreaded
                                                                                     , presentParams);
                //The previous code creates a new graphics device. It’s not going to make a whole lot of
                //sense to you right now, but don’t worry that much about it. Just know that it works, and
                //that I’ll get to it in much more detail in Chapter 7.
                //The next part of the code sets up the event handlers (which are delegates):
                state.graphics.DeviceLost  += new EventHandler(this.InvalidateDeviceObjects);
                state.graphics.DeviceReset += new EventHandler(this.RestoreDeviceObjects);
                state.graphics.Disposing   += new EventHandler(this.DeleteDeviceObjects);
                //	state.graphics.DeviceResizing += new CancelEventHandler( this.EnvironmentResizing );

                /* 2d feature for turning off back culling on badly chosen flat rectangels */
                state.graphics.RenderState.CullMode = Direct3D.Cull.None;

                // yes I want this.
                state.graphics.RenderState.AlphaBlendEnable = true;


                //The first three events handle whenever a device is lost (say, if the user switches to another
                //window), the device is reset for any reason, or the device is disposed of. These first three
                //events are solid events; when they happen, you have to handle them. No ifs, ands, or buts
                //about it—the operating system is telling you something happened and your event handler
                //has to take care of the situation.
                //The final event handles when the graphics device is resized, which is a special kind of
                //event because it can be cancelled. A cancelable event is an event that your program can
                //decide to reject. For example, if the user says he’s going to resize your game window, your
                //program will get the event, but you can tell the operating system, “Nope, it’s not gonna
                //happen!” and the event won’t complete. This behavior is used mostly to prevent forms
                //from closing before the user saves his data in windows applications.
                //The final part of the code returns true for a successful initialization, or catches any
                //DirectXExceptions that may have been thrown and returns false:
                return(true);
            }
            catch (DirectXException)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        //void IReflectorWidget.OnPaint( PaintEventArgs e )
        //{
        //    this.Render();
        //}
        //void IReflectorWidget.OnKeyPress( KeyPressEventArgs e )
        //{
        //    if( (int)e.KeyChar == (int)System.Windows.Forms.Keys.Escape )
        //    {
        //        paused = true;
        //        //this.Close();
        //    }
        //}


        //#region IReflectorCreate Members

        public void DoCreate(Control pc)
        {
            state   = new D3DState();
            control = pc;
            //+= new EventHandler( PSI_DirectFrame_SizeChanged );
            //paused = false;
            screenwidth  = control.Width;
            screenheight = control.Height;
            if (unpause)
            {
                paused = false;
            }

            if (!InitializeGraphics())
            {
                MessageBox.Show("Error while initializing Direct3D");
            }
            ThreadStart ts        = new ThreadStart(RunThread);
            Thread      runthread = new Thread(ts);

            runthread.Start();
            paused = false;
        }