Exemple #1
0
        internal void DoRender(D3DState state)
        {
            Transforms t = state.graphics.Transform;

            // should project normal on t to get the Up/right vector

            state.graphics.RenderState.SourceBlend      = Direct3D.Blend.SourceAlpha;
            state.graphics.RenderState.DestinationBlend = Direct3D.Blend.InvSourceAlpha;
            state.graphics.RenderState.AlphaBlendEnable = true;

            if (Render != null)
            {
                Render(state);
            }
        }
Exemple #2
0
        public void DoCreate(Control pc)
        {
            state           = new D3DState();
            control         = pc;
            pc.SizeChanged += new EventHandler(PSI_DirectFrame_SizeChanged);
            //paused = false;
            if (!InitializeGraphics())
            {
                MessageBox.Show("Error while initializing Direct3D");
            }
            ThreadStart ts        = new ThreadStart(RunThread);
            Thread      runthread = new Thread(ts);

            runthread.Start();
            paused = false;
        }
Exemple #3
0
        public bool InitializeGraphics()
        {
            try
            {
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed   = true;
                presentParams.SwapEffect = SwapEffect.Discard;
                state          = new D3DState();
                state.graphics = new Direct3D.Device(0, DeviceType.Hardware, control,
                                                     Direct3D.CreateFlags.SoftwareVertexProcessing, 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);
            }
        }
Exemple #4
0
 internal void DoMouse(D3DState state, int x, int y, int b)
 {
 }