コード例 #1
0
        /// <summary>
        /// Enumerates D3D devices for a particular adapter.
        /// </summary>
        private static void EnumerateDevices(EnumAdapterInformation adapterInfo, ArrayList adapterFormatList)
        {
            // Ignore any exceptions while looking for these device types
            DirectXException.IgnoreExceptions();
            // Enumerate each Direct3D device type
            for (uint i = 0; i < deviceTypeArray.Length; i++)
            {
                // Create a new device information object
                EnumDeviceInformation deviceInfo = new EnumDeviceInformation();

                // Store the type
                deviceInfo.DeviceType = deviceTypeArray[i];

                // Try to get the capabilities
                deviceInfo.Caps = Manager.GetDeviceCaps((int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType);

                // Get information about each device combination on this device
                EnumerateDeviceCombos(adapterInfo, deviceInfo, adapterFormatList);

                // Do we have any device combinations?
                if (deviceInfo.deviceSettingsList.Count > 0)
                {
                    // Yes, add it
                    adapterInfo.deviceInfoList.Add(deviceInfo);
                }
            }
            // Turn exception handling back on
            DirectXException.EnableExceptions();
        }
コード例 #2
0
        /// <summary>
        /// Print information about the provided exception
        /// </summary>
        /// <param name="ex">Exception instance</param>
        /// <param name="calling">Name of the method which returned the exception</param>
        /// <param name="isFatal">Flag to indicate whether the given error is fatal</param>
        public void ShowException(Exception ex, string calling, bool isFatal)
        {
            string output = null;

            if (calling != null)
            {
                output = "An error occurred while calling \"" + calling + "\"\n\n";
            }
            else
            {
                output = "An error occurred while executing the tutorial\n\n";
            }

            output += "Message: " + ex.Message + "\n";

            if (ex is DirectXException)
            {
                // DirectX-specific info
                DirectXException dex = (DirectXException)ex;
                output += "HRESULT: " + dex.ErrorString + " (" + dex.ErrorCode.ToString("X") + ")\n";
            }

            output += "Source: " + ex.Source + "\n";

            if (isFatal)
            {
                output += "\nThe application will now exit\n";
            }

            MessageBox.Show(this, output, "DirectPlay Tutorial", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
コード例 #3
0
    } // construtor

    // [---
    public void initGfx()
    {
      // <b>
      // Cria o dispositivo DirectDraw.Device
      device = new Device();

      // Configurando o nível de configuração: tela cheia exclusiva
      device.SetCooperativeLevel(this, CooperativeLevelFlags.FullscreenExclusive);

      // Verifica configuração atual do vídeo e reaplica-o em tela cheia
      SurfaceDescription video_atual_descricao = device.DisplayMode;
      xtela = video_atual_descricao.Width;
      ytela = video_atual_descricao.Height;
      device.SetDisplayMode(xtela, ytela, 32, 0, false);

      // Configura a superfície primária ( a tela )
      SurfaceDescription tela_descricao = new SurfaceDescription();

      // Define a superfície como primária, isto é, representa a memória
      // de vídeo imediata
      tela_descricao.SurfaceCaps.PrimarySurface = true;

      // A 'tela ' vai receber o backbuffer virado sobre ela
      tela_descricao.SurfaceCaps.Flip = true;

      // Complex quer dizer que a superfície vai conter outras
      // outras superfícies (backbuffers)
      tela_descricao.SurfaceCaps.Complex = true;
      tela_descricao.BackBufferCount = 1;

      // Cria a superfície primária ( a tela )
      tela = new Surface(tela_descricao, device);


      // Obtém o backbuffer a partir da superfície primária
      SurfaceCaps caps = new SurfaceCaps();
      caps.BackBuffer = true;
      backBuffer = tela.GetAttachedSurface(caps);

      // Ignore as exceções geradas
      DirectXException.IgnoreExceptions();

      inicializarSprite();

      // Define posição inicial da sprite
      xcol = 320;
      ylin = 240;

      inicializarTeclado();
      // </b>

    } // initGfx()
コード例 #4
0
        /// <summary>
        /// Print information about the provided exception
        /// </summary>
        /// <param name="ex">Exception instance</param>
        /// <param name="calling">Name of the method which returned the exception</param>
        public void ShowException(Exception ex, string calling)
        {
            string output = ex.Message + "\n\n";

            if (ex.GetType().DeclaringType == Type.GetType("System.DirectX.DirectXException"))
            {
                // DirectX-specific info
                DirectXException dex = (DirectXException)ex;
                output += "HRESULT: " + dex.ErrorString + " (" + dex.ErrorCode.ToString("X") + ")\n";
            }

            output += "Calling: " + calling + "\n";
            output += "Source: " + ex.Source + "\n";
            MessageBox.Show(this, output, "ActionBasic Sample Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
コード例 #5
0
 public static void Error(Exception ex)
 {
     if (ex is DirectXException)
     {
         DirectXException exception = (DirectXException)ex;
         Trace("Error Code -> {0}", exception.get_ErrorCode());
         Trace("Error String -> {0}", exception.get_ErrorString());
     }
     Trace("Type -> {0}", ex.GetType());
     Trace("Message -> {0}", ex.Message);
     Trace("Source -> {0}", ex.Source);
     Trace("Target -> {0}", ex.TargetSite);
     Trace("Inner -> {0}", ex.InnerException);
     Trace("Stack ->");
     Trace(ex.StackTrace);
 }
コード例 #6
0
        /// <summary>
        /// Alert the user of a DirectX exception.
        /// </summary>
        /// <param name="e">Exception thrown.</param>
        /// <param name="displayMessageBox">Whether or not to display a message box warning.</param>
        private void ThrowException(DirectXException e, bool displayMessageBox)
        {
            string message = "";

            message += "Error: " + e.Message + "\n";
            message += "\nDirectX Error Message: " + e.ErrorString + "\n";
            message += "\nSource: " + e.Source;

            if (displayMessageBox)
            {
                MessageBox.Show(message,
                                "Voyage.Terraingine.DXViewport.Viewport.InitializeDevice()",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Debug.WriteLine(message);
        }
コード例 #7
0
ファイル: CubeMap.cs プロジェクト: sjk7/DX90SDK
        /// <summary>
        /// Called once per frame, the call is the entry point for 3d
        ///  rendering. This function sets up render states, clears the
        ///  viewport, and renders the scene.
        /// </summary>
        protected override void Render()
        {
            // Begin the scene
            device.BeginScene();

            // Ignore any exceptions during rendering
            DirectXException.IgnoreExceptions();
            // Render the scene, including the teapot
            RenderScene(viewMatrix, projectionMatrix, true);

            // Output statistics
            drawingFont.DrawText(2, 1, System.Drawing.Color.Yellow, frameStats);
            drawingFont.DrawText(2, 21, System.Drawing.Color.Yellow, deviceStats);

            // We're done ignoring them
            DirectXException.EnableExceptions();
            // End the scene.
            device.EndScene();
        }
コード例 #8
0
ファイル: StencilDepth.cs プロジェクト: sjk7/DX90SDK
        /// <summary>
        /// Called once per frame, the call is the entry point for 3d rendering. This
        /// function sets up render states, clears the viewport, and renders the scene.
        /// </summary>
        protected override void Render()
        {
            // Clear the viewport
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.Blue.ToArgb(), 1.0f, 0);

            device.BeginScene();

            // Ignore exceptions during rendering
            DirectXException.IgnoreExceptions();

            if (showDepthComplexity)
            {
                SetStatesForRecordingDepthComplexity();
            }


            device.Transform.World = worldMatrix;
            if (drawHelicopter)
            {
                fileObject[0].Render(device);
            }
            else
            {
                fileObject[1].Render(device);
            }

            // Show the depth complexity of the scene
            if (showDepthComplexity)
            {
                ShowDepthComplexity();
            }

            // Output statistics
            font.DrawText(2, 1, System.Drawing.Color.Yellow, frameStats);
            font.DrawText(2, 20, System.Drawing.Color.Yellow, deviceStats);

            // Turn exceptions back on
            DirectXException.EnableExceptions();

            device.EndScene();
        }
コード例 #9
0
ファイル: Billboard.cs プロジェクト: sjk7/DX90SDK
        /// <summary>
        /// The device exists, but may have just been Reset().  Resources in
        /// Pool.Default and any other device state that persists during
        /// rendering should be set here.  Render states, matrices, textures,
        /// etc., that don't change during rendering can be set once here to
        /// avoid redundant state setting during Render() or FrameMove().
        /// </summary>
        protected override void RestoreDeviceObjects(System.Object sender, System.EventArgs e)
        {
            DirectXException.IgnoreExceptions();
            if ((treeVertexBuffer == null) || (treeVertexBuffer.Disposed))
            {
                // Create a quad for rendering each tree
                treeVertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColoredTextured), NumberTrees * 4, device, Usage.WriteOnly, CustomVertex.PositionColoredTextured.Format, Pool.Default);

                treeVertexBuffer.Created += new System.EventHandler(this.CreateTreeData);
                this.CreateTreeData(treeVertexBuffer, null);
            }

            // Restore the device objects for the meshes and fonts
            terrainMesh.RestoreDeviceObjects(device, null);
            skyBoxMesh.RestoreDeviceObjects(device, null);

            // Set the transform matrices (view and world are updated per frame)
            Matrix matProj;
            float  fAspect = device.PresentationParameters.BackBufferWidth / (float)device.PresentationParameters.BackBufferHeight;

            matProj = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1.0f, 100.0f);
            device.Transform.Projection = matProj;

            // Set up the default texture states
            device.TextureState[0].ColorOperation = TextureOperation.Modulate;
            device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
            device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
            device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
            device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
            device.SamplerState[0].MinFilter      = TextureFilter.Linear;
            device.SamplerState[0].MagFilter      = TextureFilter.Linear;
            device.SamplerState[0].MipFilter      = TextureFilter.Linear;
            device.SamplerState[0].AddressU       = TextureAddress.Clamp;
            device.SamplerState[0].AddressV       = TextureAddress.Clamp;

            device.RenderState.DitherEnable  = true;
            device.RenderState.ZBufferEnable = true;
            device.RenderState.Lighting      = false;
            DirectXException.EnableExceptions();
        }
コード例 #10
0
ファイル: Viewport.cs プロジェクト: stormont/terraingine
        /// <summary>
        /// Alert the user of a DirectX exception.
        /// </summary>
        /// <param name="e">Exception thrown.</param>
        /// <param name="displayMessageBox">Whether or not to display a message box warning.</param>
        private void ThrowException( DirectXException e, bool displayMessageBox )
        {
            string message = "";

            message += "Error: " + e.Message + "\n";
            message += "\nDirectX Error Message: " + e.ErrorString + "\n";
            message += "\nSource: " + e.Source;

            if ( displayMessageBox )
            {
                MessageBox.Show( message,
                    "Voyage.Terraingine.DXViewport.Viewport.InitializeDevice()",
                    MessageBoxButtons.OK, MessageBoxIcon.Error );
            }

            Debug.WriteLine( message );
        }
コード例 #11
0
ファイル: StencilMirror.cs プロジェクト: sjk7/DX90SDK
        /// <summary>
        /// Renders the mirrored scene
        /// </summary>
        private void RenderMirror()
        {
            // Turn depth buffer off, and stencil buffer on
            device.RenderState.StencilEnable      = true;
            device.RenderState.StencilFunction    = Compare.Always;
            device.RenderState.ReferenceStencil   = 0x1;
            device.RenderState.StencilMask        = unchecked ((int)0xffffffff);
            device.RenderState.StencilWriteMask   = unchecked ((int)0xffffffff);
            device.RenderState.StencilZBufferFail = StencilOperation.Keep;
            device.RenderState.StencilFail        = StencilOperation.Keep;
            device.RenderState.StencilPass        = StencilOperation.Replace;

            // Make sure no pixels are written to the z-buffer or frame buffer
            device.RenderState.ZBufferWriteEnable = false;
            device.RenderState.AlphaBlendEnable   = true;
            device.RenderState.SourceBlend        = Blend.Zero;
            device.RenderState.DestinationBlend   = Blend.One;

            // Draw the reflecting surface into the stencil buffer
            device.SetTexture(0, null);
            device.Transform.World = mirrorMatrix;
            device.VertexFormat    = MirrorVertex.Format;
            device.SetStreamSource(0, mirrorVertexBuffer, 0);
            device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

            // Save the view matrix
            Matrix matViewSaved = device.Transform.View;

            // Reflect camera in X-Z plane mirror
            Matrix matView, matReflect = new Matrix();
            Plane  plane = Plane.FromPointNormal(new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            matReflect.Reflect(plane);
            matView = Matrix.Multiply(matReflect, matViewSaved);
            device.Transform.View = matView;

            // Set a clip plane, so that only objects above the water are reflected, we don't care about any errors
            DirectXException.IgnoreExceptions();
            device.ClipPlanes[0].Plane   = plane;
            device.ClipPlanes[0].Enabled = true;
            DirectXException.EnableExceptions();

            // Setup render states to a blended render scene against mask in stencil
            // buffer. An important step here is to reverse the cull-order of the
            // polygons, since the view matrix is being relected.
            device.RenderState.ZBufferWriteEnable = true;
            device.RenderState.StencilFunction    = Compare.Equal;
            device.RenderState.StencilPass        = StencilOperation.Keep;
            device.RenderState.SourceBlend        = Blend.DestinationColor;
            device.RenderState.DestinationBlend   = Blend.Zero;
            device.RenderState.CullMode           = Cull.Clockwise;

            // Clear the zbuffer (leave frame- and stencil-buffer intact)
            device.Clear(ClearFlags.ZBuffer, 0, 1.0f, 0);

            // Render the scene
            RenderScene();

            // Restore render states
            device.RenderState.CullMode         = Cull.CounterClockwise;
            device.RenderState.StencilEnable    = false;
            device.RenderState.AlphaBlendEnable = false;
            device.ClipPlanes.DisableAll();
            device.Transform.View = matViewSaved;
        }