Esempio n. 1
0
 void mDevice_DeviceLost(object sender, EventArgs e)
 {
     // set weird values which will indicate that the device's
     // render states need to be set.
     mAlphaBlend     = false;
     mAlphaArgument1 = TextureArgument.Temp;
     mAlphaArgument2 = TextureArgument.Temp;
     mAlphaOperation = TextureOperation.Add;
 }
Esempio n. 2
0
        public override void Begin()
        {
            SDX_Display mDisplay = (SDX_Display)AgateLib.DisplayLib.Display.Impl;

            Set2DDrawState();

            mDisplay.D3D_Device.Device.SetRenderState(RenderState.Lighting, true);
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.Ambient, AmbientLight.ToArgb());
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.ColorVertex, true);

            TextureArgument  arg0 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg0);
            TextureArgument  arg1 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg1);
            TextureArgument  arg2 = (TextureArgument)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorArg2);
            TextureOperation op   = (TextureOperation)mDisplay.D3D_Device.Device.GetTextureStageState(0, TextureStage.ColorOperation);

            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg0, TextureArgument.Current);
            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Current);
            mDisplay.D3D_Device.Device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.Modulate);
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Color1);
            mDisplay.D3D_Device.Device.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Color1);

            Material material = new Material();

            material.Diffuse = new SlimDX.Color4(Color.White.ToArgb());
            material.Ambient = new SlimDX.Color4(Color.White.ToArgb());


            mDisplay.D3D_Device.Device.Material = material;

            int index = 0;

            for (int i = 0; i < Lights.Count; i++)
            {
                var agateLight = Lights[i];

                if (agateLight == null)
                {
                    continue;
                }
                if (agateLight.Enabled == false)
                {
                    continue;
                }

                SlimDX.Direct3D9.Light l = new SlimDX.Direct3D9.Light();

                l.Ambient      = new SlimDX.Color4(agateLight.AmbientColor.ToArgb());
                l.Attenuation0 = agateLight.AttenuationConstant;
                l.Attenuation1 = agateLight.AttenuationLinear;
                l.Attenuation2 = agateLight.AttenuationQuadratic;
                l.Diffuse      = new SlimDX.Color4(agateLight.DiffuseColor.ToArgb());
                l.Type         = LightType.Point;
                l.Direction    = new SlimDX.Vector3(0, 0, 1);
                l.Range        = 100;


                Vector3 pos = agateLight.Position;

                l.Position = new SlimDX.Vector3(pos.X, pos.Y, pos.Z);

                mDisplay.D3D_Device.Device.SetLight(index, l);
                mDisplay.D3D_Device.Device.EnableLight(index, true);

                index++;
            }
        }
Esempio n. 3
0
 private void SetTextureStageState(int stage, TextureStage type, TextureArgument value)
 {
     SetTextureStageState(stage, type, (int)value);
 }
Esempio n. 4
0
        /// <summary>
        /// This is where we do our rendering
        /// Called from UI thread = UI code safe in this function
        /// </summary>
        public override void OnRender(DrawArgs drawArgs)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            // Device shortcuts ;
            Device device = drawArgs.device;

            // Read star catalog and build vertex list if not done yet
            if (StarListVB == null || refWidth != device.Viewport.Width)
            {
                if (StarListVB != null)
                {
                    StarListVB = null;
                }
                if (FlareMesh != null)
                {
                    FlareMesh.Dispose();
                    FlareMesh = null;
                }
                LoadStars();
            }


            if (drawArgs.WorldCamera.Altitude < 10e3)
            {
                return;
            }

            // save world and projection transform
            Matrix origWorld      = drawArgs.device.Transform.World;
            Matrix origProjection = drawArgs.device.Transform.Projection;

            TextureOperation a0 = drawArgs.device.TextureState[0].AlphaOperation;
            TextureArgument  a1 = drawArgs.device.TextureState[0].AlphaArgument1;
            TextureOperation c0 = drawArgs.device.TextureState[0].ColorOperation;
            TextureArgument  c1 = drawArgs.device.TextureState[0].ColorArgument1;
            TextureArgument  c2 = drawArgs.device.TextureState[0].ColorArgument2;


            // Save fog status
            bool origFog = drawArgs.device.RenderState.FogEnable;
            bool islight = drawArgs.device.RenderState.Lighting;

            device.RenderState.FogEnable = false;
            device.RenderState.Lighting  = false;
            // Set new projection (to avoid being clipped) - probably better ways of doing this?
            float aspectRatio = (float)device.Viewport.Width / device.Viewport.Height;

            device.Transform.Projection = Matrix.PerspectiveFovRH((float)drawArgs.WorldCamera.Fov.Radians, aspectRatio, 1, float.MaxValue);

            // This is where we can rotate the star dome to acomodate time and seasons

            device.Transform.World = Matrix.RotationZ(
                (float)(TimeKeeper.CurrentTimeUtc.Hour +
                        TimeKeeper.CurrentTimeUtc.Minute / 60.0 +
                        TimeKeeper.CurrentTimeUtc.Second / 3600.0 +
                        TimeKeeper.CurrentTimeUtc.Millisecond / 3600000.0) / 24.0f * (float)(-2 * Math.PI));


            // Render textured flares if set
            if (showFlares)
            {
                device.SetTexture(0, texture);

                device.TextureState[0].AlphaOperation = TextureOperation.BlendCurrentAlpha;
                device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
                device.TextureState[0].ColorOperation = TextureOperation.AddSmooth;
                device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;

                device.VertexFormat = CustomVertex.PositionTextured.Format;

                FlareMesh.DrawSubset(0);
            }
            drawArgs.device.TextureState[0].AlphaOperation = a0;
            drawArgs.device.TextureState[0].AlphaArgument1 = a1;
            drawArgs.device.TextureState[0].ColorOperation = c0;
            drawArgs.device.TextureState[0].ColorArgument1 = c1;
            drawArgs.device.TextureState[0].ColorArgument2 = c2;

            // draw StarListVB
            device.SetTexture(0, null);
            device.VertexFormat = CustomVertex.PositionColored.Format;
            device.SetStreamSource(0, StarListVB, 0);
            device.DrawPrimitives(PrimitiveType.PointList, 0, StarCount);

            // Restore device states
            drawArgs.device.Transform.World       = origWorld;
            drawArgs.device.Transform.Projection  = origProjection;
            drawArgs.device.RenderState.FogEnable = origFog;
            drawArgs.device.RenderState.Lighting  = islight;
        }
Esempio n. 5
0
 public Result SetTextureStageState(int stage, TextureStage type, TextureArgument textureArgument)
 {
     return(_device.SetTextureStageState(stage, type, textureArgument));
 }