Example #1
0
        public void DrawTexturedOverlay(Camera camera, Texture2D texture, Color color, float innerFactor, float outerFactor, Vector2 offset)
        {
            Vector2 viewportSize = camera.ViewportSize;
            float   num          = viewportSize.X / viewportSize.Y;
            Vector2 vector       = new Vector2(0f, 0f);
            Vector2 vector2      = new Vector2(viewportSize.X, 0f);
            Vector2 vector3      = new Vector2(viewportSize.X, viewportSize.Y);
            Vector2 vector4      = new Vector2(0f, viewportSize.Y);
            Vector2 p            = new Vector2(viewportSize.X / 2f, viewportSize.Y / 2f);

            offset.X = MathUtils.Remainder(offset.X, 1f);
            offset.Y = MathUtils.Remainder(offset.Y, 1f);
            Vector2         vector5         = new Vector2(0f, 0f) + offset;
            Vector2         vector6         = new Vector2(num, 0f) + offset;
            Vector2         vector7         = new Vector2(num, 1f) + offset;
            Vector2         vector8         = new Vector2(0f, 1f) + offset;
            Vector2         texCoord        = new Vector2(num / 2f, 0.5f) + offset;
            Color           color2          = color * outerFactor;
            Color           color3          = color * innerFactor;
            TexturedBatch2D texturedBatch2D = m_primitivesRenderer2D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None, null, BlendState.Additive, SamplerState.PointWrap);
            int             count           = texturedBatch2D.TriangleVertices.Count;

            texturedBatch2D.QueueTriangle(vector, vector2, p, 0f, vector5, vector6, texCoord, color2, color2, color3);
            texturedBatch2D.QueueTriangle(vector2, vector3, p, 0f, vector6, vector7, texCoord, color2, color2, color3);
            texturedBatch2D.QueueTriangle(vector3, vector4, p, 0f, vector7, vector8, texCoord, color2, color2, color3);
            texturedBatch2D.QueueTriangle(vector4, vector, p, 0f, vector8, vector5, texCoord, color2, color2, color3);
            texturedBatch2D.TransformTriangles(camera.ViewportMatrix, count);
            texturedBatch2D.Flush();
        }
        public void Draw(PrimitivesRenderer2D primitivesRenderer, float depth, Matrix matrix, Color color)
        {
            TexturedBatch2D texturedBatch2D = primitivesRenderer.TexturedBatch(m_texture, useAlphaTest: false, 0, DepthStencilState.None, null, null, SamplerState.PointClamp);
            int             count           = texturedBatch2D.TriangleVertices.Count;

            foreach (Particle particle in m_particles)
            {
                if (particle.Active)
                {
                    DrawParticle(texturedBatch2D, particle, depth, color);
                }
            }
            texturedBatch2D.TransformTriangles(matrix, count);
        }
Example #3
0
 public static void Draw()
 {
     if (VrManager.IsVrStarted)
     {
         Point2 point = new Point2(Display.Viewport.Width, Display.Viewport.Height);
         if (MathUtils.Max(point.X, point.Y) == 0)
         {
             point = new Point2(1500, 1000);
         }
         while (MathUtils.Max(point.X, point.Y) < 1024)
         {
             point *= 2;
         }
         if (m_uiRenderTarget == null || m_uiRenderTarget.Width != point.X || m_uiRenderTarget.Height != point.Y)
         {
             Utilities.Dispose(ref m_uiRenderTarget);
             m_uiRenderTarget = new RenderTarget2D(point.X, point.Y, 1, ColorFormat.Rgba8888, DepthFormat.Depth24Stencil8);
         }
         RenderTarget2D renderTarget = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_uiRenderTarget;
             LayoutAndDrawWidgets();
             Display.RenderTarget = VrManager.VrRenderTarget;
             for (VrEye vrEye = VrEye.Left; vrEye <= VrEye.Right; vrEye++)
             {
                 Display.Clear(Color.Black, 1f, 0);
                 DrawVrBackground();
                 DrawVrQuad();
                 Matrix hmdMatrix        = VrManager.HmdMatrix;
                 Matrix m                = Matrix.Invert(VrManager.GetEyeToHeadTransform(vrEye));
                 Matrix m2               = Matrix.Invert(hmdMatrix);
                 Matrix projectionMatrix = VrManager.GetProjectionMatrix(vrEye, 0.1f, 1024f);
                 m_pr3.Flush(m2 * m * projectionMatrix);
                 VrManager.SubmitEyeTexture(vrEye, VrManager.VrRenderTarget);
             }
         }
         finally
         {
             Display.RenderTarget = renderTarget;
         }
         m_pr2.TexturedBatch(m_uiRenderTarget, useAlphaTest: false, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.Opaque, SamplerState.PointClamp).QueueQuad(new Vector2(0f, 0f), new Vector2(m_uiRenderTarget.Width, m_uiRenderTarget.Height), 0f, new Vector2(0f, 0f), new Vector2(1f, 1f), Color.White);
         m_pr2.Flush();
     }
     else
     {
         Utilities.Dispose(ref m_uiRenderTarget);
         LayoutAndDrawWidgets();
     }
 }
 public void Update(float dt)
 {
     if (!DisableTextureAnimation && !m_subsystemTime.FixedTimeStep.HasValue)
     {
         float dt2 = (float)MathUtils.Min(m_subsystemTime.GameTime - m_lastAnimateGameTime, 1.0);
         m_lastAnimateGameTime = m_subsystemTime.GameTime;
         Texture2D blocksTexture = m_subsystemBlocksTexture.BlocksTexture;
         if (m_animatedBlocksTexture == null || m_animatedBlocksTexture.Width != blocksTexture.Width || m_animatedBlocksTexture.Height != blocksTexture.Height || m_animatedBlocksTexture.MipLevelsCount > 1 != SettingsManager.TerrainMipmapsEnabled)
         {
             Utilities.Dispose(ref m_animatedBlocksTexture);
             m_animatedBlocksTexture = new RenderTarget2D(blocksTexture.Width, blocksTexture.Height, (!SettingsManager.TerrainMipmapsEnabled) ? 1 : 4, ColorFormat.Rgba8888, DepthFormat.None);
         }
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         Display.RenderTarget = m_animatedBlocksTexture;
         try
         {
             Display.Clear(new Vector4(Color.Transparent));
             m_primitivesRenderer.TexturedBatch(blocksTexture, useAlphaTest: false, -1, DepthStencilState.None, RasterizerState.CullNone, BlendState.Opaque, SamplerState.PointClamp).QueueQuad(new Vector2(0f, 0f), new Vector2(m_animatedBlocksTexture.Width, m_animatedBlocksTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             AnimateWaterBlocksTexture();
             AnimateMagmaBlocksTexture();
             m_primitivesRenderer.Flush();
             Display.ScissorRectangle = AnimateFireBlocksTexture(dt2);
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
         if (SettingsManager.TerrainMipmapsEnabled && Time.FrameIndex % 2 == 0)
         {
             m_animatedBlocksTexture.GenerateMipMaps();
         }
     }
 }
Example #5
0
 public void UpdateRenderTargets()
 {
     if (m_skinTexture == null || m_componentPlayer.PlayerData.CharacterSkinName != m_skinTextureName)
     {
         m_skinTexture     = CharacterSkinsManager.LoadTexture(m_componentPlayer.PlayerData.CharacterSkinName);
         m_skinTextureName = m_componentPlayer.PlayerData.CharacterSkinName;
         Utilities.Dispose(ref m_innerClothedTexture);
         Utilities.Dispose(ref m_outerClothedTexture);
     }
     if (m_innerClothedTexture == null || m_innerClothedTexture.Width != m_skinTexture.Width || m_innerClothedTexture.Height != m_skinTexture.Height)
     {
         m_innerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentHumanModel.TextureOverride = m_innerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (m_outerClothedTexture == null || m_outerClothedTexture.Width != m_skinTexture.Width || m_outerClothedTexture.Height != m_skinTexture.Height)
     {
         m_outerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentOuterClothingModel.TextureOverride = m_outerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (DrawClothedTexture && !m_clothedTexturesValid)
     {
         m_clothedTexturesValid = true;
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_innerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             int             num             = 0;
             TexturedBatch2D texturedBatch2D = m_primitivesRenderer.TexturedBatch(m_skinTexture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
             texturedBatch2D.QueueQuad(Vector2.Zero, new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             ClothingSlot[] innerSlotsOrder = m_innerSlotsOrder;
             foreach (ClothingSlot slot in innerSlotsOrder)
             {
                 foreach (int clothe in GetClothes(slot))
                 {
                     int          data         = Terrain.ExtractData(clothe);
                     MekClothData clothingData = MekClothingBlock.GetClothingData(data);
                     Color        fabricColor  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (!clothingData.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
             Display.RenderTarget = m_outerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             num             = 0;
             innerSlotsOrder = m_outerSlotsOrder;
             foreach (ClothingSlot slot2 in innerSlotsOrder)
             {
                 foreach (int clothe2 in GetClothes(slot2))
                 {
                     int          data2         = Terrain.ExtractData(clothe2);
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(data2);
                     Color        fabricColor2  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data2));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData2.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (clothingData2.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_outerClothedTexture.Width, m_outerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor2);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
     }
 }
Example #6
0
 public static void Capture(int width, int height, string filename)
 {
     if (GameManager.Project != null)
     {
         using (RenderTarget2D renderTarget2D = new RenderTarget2D(width, height, 1, ColorFormat.Rgba8888, DepthFormat.Depth24Stencil8))
         {
             RenderTarget2D renderTarget = Display.RenderTarget;
             Dictionary <ComponentGui, bool> dictionary = new Dictionary <ComponentGui, bool>();
             ResolutionMode resolutionMode = ResolutionMode.High;
             try
             {
                 if (!SettingsManager.ShowGuiInScreenshots)
                 {
                     foreach (ComponentPlayer componentPlayer in GameManager.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true).ComponentPlayers)
                     {
                         dictionary[componentPlayer.ComponentGui] = componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible;
                         componentPlayer.ComponentGui.ControlsContainerWidget.IsVisible = false;
                     }
                 }
                 resolutionMode = SettingsManager.ResolutionMode;
                 SettingsManager.ResolutionMode = ResolutionMode.High;
                 Display.RenderTarget           = renderTarget2D;
                 ScreensManager.Draw();
                 if (SettingsManager.ShowLogoInScreenshots)
                 {
                     PrimitivesRenderer2D primitivesRenderer2D = new PrimitivesRenderer2D();
                     Texture2D            texture2D            = ContentManager.Get <Texture2D>("Textures/Gui/ScreenCaptureOverlay");
                     Vector2 vector = new Vector2((width - texture2D.Width) / 2, 0f);
                     Vector2 corner = vector + new Vector2(texture2D.Width, texture2D.Height);
                     primitivesRenderer2D.TexturedBatch(texture2D, useAlphaTest: false, 0, DepthStencilState.None).QueueQuad(vector, corner, 0f, new Vector2(0f, 0f), new Vector2(1f, 1f), Engine.Color.White);
                     primitivesRenderer2D.Flush();
                 }
             }
             finally
             {
                 Display.RenderTarget = renderTarget;
                 foreach (KeyValuePair <ComponentGui, bool> item in dictionary)
                 {
                     item.Key.ControlsContainerWidget.IsVisible = item.Value;
                 }
                 SettingsManager.ResolutionMode = resolutionMode;
             }
             if (!Storage.DirectoryExists(ModsManager.baseDir + "/ScreenCapture"))
             {
                 Storage.CreateDirectory(ModsManager.baseDir + "/ScreenCapture");
             }
             string path = Storage.CombinePaths(Storage.GetSystemPath(ModsManager.baseDir + "/ScreenCapture"), filename);
             using (FileStream stream = new FileStream(path, FileMode.Create))
             {
                 byte[] array = new byte[4 * renderTarget2D.Width * renderTarget2D.Height];
                 renderTarget2D.GetData(array, 0, new Rectangle(0, 0, renderTarget2D.Width, renderTarget2D.Height));
                 ByteBuffer src    = ByteBuffer.Wrap(array);
                 Bitmap     bitmap = Bitmap.CreateBitmap(renderTarget2D.Width, renderTarget2D.Height, Bitmap.Config.Argb8888);
                 bitmap.CopyPixelsFromBuffer(src);
                 bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
             }
             Intent intent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
             intent.SetData(Android.Net.Uri.FromFile(new Java.IO.File(path)));
             Window.Activity.SendBroadcast(intent);
         }
     }
 }