Ejemplo n.º 1
0
        protected override void OnProcess(RenderContext context)
        {
            var graphicsDevice = GraphicsService.GraphicsDevice;

            var source   = context.SourceTexture;
            var target   = context.RenderTarget;
            var viewport = context.Viewport;

            if (TextureHelper.IsFloatingPointFormat(source.Format))
            {
                graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                graphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
            }
            else
            {
                graphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
                graphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
            }

            // Blur source texture.
            var tempFormat   = new RenderTargetFormat(source.Width, source.Height, false, source.Format, DepthFormat.None);
            var blurredImage = GraphicsService.RenderTargetPool.Obtain2D(tempFormat);

            context.RenderTarget = blurredImage;
            context.Viewport     = new Viewport(0, 0, blurredImage.Width, blurredImage.Height);
            Blur.Process(context);

            // Unsharp masking.
            context.RenderTarget = target;
            context.Viewport     = viewport;
            graphicsDevice.SetRenderTarget(context.RenderTarget);
            graphicsDevice.Viewport = context.Viewport;

            _viewportSizeParameter.SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height));
            _sharpnessParameter.SetValue(Sharpness);
            _sourceTextureParameter.SetValue(source);
            _blurredTextureParameter.SetValue(blurredImage);
            _effect.CurrentTechnique.Passes[0].Apply();
            graphicsDevice.DrawFullScreenQuad();

            // Clean-up
            _sourceTextureParameter.SetValue((Texture2D)null);
            _blurredTextureParameter.SetValue((Texture2D)null);
            GraphicsService.RenderTargetPool.Recycle(blurredImage);
        }
Ejemplo n.º 2
0
            public void Fill(Puzzle puzzle)
            {
                Vertices.Clear();
                Edges.Clear();
                Faces.Clear();

                int baseV = 1;
                int baseE = 1;
                int baseF = 1;

                foreach (Cell cell in puzzle.IRPCells)
                {
                    Vector3D[] verts = cell.TextureVertices;
                    for (int i = 0; i < verts.Length; i++)
                    {
                        SurfaceVertex sv = new SurfaceVertex(verts[i]);
                        sv.Index = baseV + i;
                        Vertices.Add(sv);
                    }

                    const int lod    = 3;
                    int[]     facets = TextureHelper.TextureElements(cell.Boundary.NumSides, lod);
                    for (int i = 0; i < facets.Length; i += 3)
                    {
                        SurfaceEdge e1 = new SurfaceEdge(baseV + facets[i], baseV + facets[i + 1]);
                        SurfaceEdge e2 = new SurfaceEdge(baseV + facets[i + 1], baseV + facets[i + 2]);
                        SurfaceEdge e3 = new SurfaceEdge(baseV + facets[i + 2], baseV + facets[i]);
                        e1.Index = baseE + i;
                        e2.Index = baseE + i + 1;
                        e3.Index = baseE + i + 2;
                        Edges.Add(e1);
                        Edges.Add(e2);
                        Edges.Add(e3);

                        SurfaceFace face = new SurfaceFace(e1.Index, e2.Index, e3.Index);
                        face.Index   = baseF + i / 3;
                        face.Reverse = puzzle.MasterCells[cell.IndexOfMaster].Reflected;                                // Reflected doesn't seem to be set on the IRP cell.
                        Faces.Add(face);
                    }

                    baseV += verts.Length;
                    baseE += facets.Length;
                    baseF += facets.Length / 3;
                }
            }
Ejemplo n.º 3
0
 public override void LoadTextures(IEnumerable <TextureItem> items)
 {
     foreach (var item in items)
     {
         foreach (var root in item.Package.PackageRoot.Split(';'))
         {
             var file = Path.Combine(root, item.Name);
             if (File.Exists(file))
             {
                 using (var bmp = Parse(file))
                 {
                     TextureHelper.Create(item.Name, bmp, item.Width, item.Height, item.Flags);
                 }
                 break;
             }
         }
     }
 }
Ejemplo n.º 4
0
        private void OnSaveTextureClicked()
        {
            if (!TextureRef)
            {
                ExplorerCore.LogWarning("Texture is null, maybe it was destroyed?");
                return;
            }

            if (string.IsNullOrEmpty(savePathInput.Text))
            {
                ExplorerCore.LogWarning("Save path cannot be empty!");
                return;
            }

            string path = savePathInput.Text;

            if (!path.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
            {
                path += ".png";
            }

            path = IOUtility.EnsureValidFilePath(path);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Texture2D tex = TextureRef;

            if (!TextureHelper.IsReadable(tex))
            {
                tex = TextureHelper.ForceReadTexture(tex);
            }

            byte[] data = TextureHelper.EncodeToPNG(tex);
            File.WriteAllBytes(path, data);

            if (tex != TextureRef)
            {
                // cleanup temp texture if we had to force-read it.
                GameObject.Destroy(tex);
            }
        }
Ejemplo n.º 5
0
        public static void DrawWireframe(IEnumerable <Face> faces, bool overrideColor, bool drawVertices)
        {
            faces = faces.Where(x => x.Parent == null || !(x.Parent.IsCodeHidden || x.Parent.IsVisgroupHidden || x.Parent.IsRenderHidden2D)).ToList();

            TextureHelper.Unbind();
            GL.Begin(PrimitiveType.Lines);

            foreach (var f in faces)
            {
                if (!overrideColor)
                {
                    GL.Color4(f.Colour);
                }
                foreach (var line in f.GetLines())
                {
                    GLCoordinate(line.Start);
                    GLCoordinate(line.End);
                }
            }

            GL.End();

            if (!drawVertices || !CBRE.Settings.View.Draw2DVertices)
            {
                return;
            }

            GL.PointSize(CBRE.Settings.View.VertexPointSize);
            GL.Begin(PrimitiveType.Points);
            GL.Color4(CBRE.Settings.View.VertexOverrideColour);
            foreach (var f in faces)
            {
                if (!CBRE.Settings.View.OverrideVertexColour)
                {
                    GL.Color4(f.Colour);
                }
                foreach (var line in f.GetLines())
                {
                    GLCoordinate(line.Start);
                    GLCoordinate(line.End);
                }
            }
            GL.End();
        }
Ejemplo n.º 6
0
        public override Texture CreateResource(ResourceManager resourceManager)
        {
            var fileName = FileName;

            if (string.IsNullOrEmpty(fileName))
            {
                throw new InvalidOperationException(string.Format(
                                                        "A valid image file path was not specified for texture \"{0}\".",
                                                        Name));
            }

            var texture = base.CreateResource(resourceManager);
            var image   = CV.LoadImage(fileName, ColorType);

            if (image == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Failed to load image texture \"{0}\" from the specified path: \"{1}\".",
                                                        Name, fileName));
            }

            var width  = Width.GetValueOrDefault();
            var height = Height.GetValueOrDefault();

            if (width > 0 && height > 0 && (image.Width != width || image.Height != height))
            {
                var resized = new IplImage(new Size(width, height), image.Depth, image.Channels);
                CV.Resize(image, resized);
                image = resized;
            }

            var flipMode = FlipMode;

            if (flipMode.HasValue)
            {
                CV.Flip(image, null, flipMode.Value);
            }
            GL.BindTexture(TextureTarget.Texture2D, texture.Id);
            var internalFormat = width > 0 && height > 0 ? (PixelInternalFormat?)null : InternalFormat;

            TextureHelper.UpdateTexture(TextureTarget.Texture2D, internalFormat, image);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            return(texture);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Called by the XNA Framework when importing an texture file to be used as a game asset. This
        /// is the method called by the XNA Framework when an asset is to be imported into an object
        /// that can be recognized by the Content Pipeline.
        /// </summary>
        /// <param name="filename">Name of a game asset file.</param>
        /// <param name="context">
        /// Contains information for importing a game asset, such as a logger interface.
        /// </param>
        /// <returns>Resulting game asset.</returns>
        public override TextureContent Import(string filename, ContentImporterContext context)
        {
            string extension = Path.GetExtension(filename);

            if (extension != null)
            {
                Texture texture = null;
                if (extension.Equals(".DDS", StringComparison.OrdinalIgnoreCase))
                {
                    using (var stream = File.OpenRead(filename))
                        texture = DdsHelper.Load(stream, DdsFlags.ForceRgb | DdsFlags.ExpandLuminance);
                }
                else if (extension.Equals(".TGA", StringComparison.OrdinalIgnoreCase))
                {
                    using (var stream = File.OpenRead(filename))
                        texture = TgaHelper.Load(stream);
                }

                if (texture != null)
                {
#if !MONOGAME
                    // When using the XNA content pipeline, check for MonoGame content.
                    if (!string.IsNullOrEmpty(ContentHelper.GetMonoGamePlatform()))
#endif
                    {
                        // These formats are not (yet) available in MonoGame.
                        switch (texture.Description.Format)
                        {
                        case DataFormat.B5G5R5A1_UNORM: // (16-bit TGA files.)
                        case DataFormat.R8_UNORM:
                        case DataFormat.A8_UNORM:
                            texture = texture.ConvertTo(DataFormat.R8G8B8A8_UNORM);
                            break;
                        }
                    }

                    // Convert DigitalRune Texture to XNA TextureContent.
                    var identity = new ContentIdentity(filename, "DigitalRune");
                    return(TextureHelper.ToContent(texture, identity));
                }
            }

            return(base.Import(filename, context));
        }
Ejemplo n.º 8
0
    // ---------------------------------------------------------------------------------------------------
    // Initialize()
    // ---------------------------------------------------------------------------------------------------
    // Initializes Snake
    // ---------------------------------------------------------------------------------------------------
    public void Initialize()
    {
        print("Snake initialized");

        // clear our Lists
        snakePos.Clear();
        snakeIcon.Clear();

        // initialize our length to start length
        snakeLength = 2;

        // intialize our moveDelay
        moveDelay = 0.5f;

        // add our AudioSource component
        if (!gameObject.GetComponent <AudioSource>())
        {
            // load in our clips
            move1 = Resources.Load("Sounds/Move1 Blip") as AudioClip;
            move2 = Resources.Load("Sounds/Move2 Blip") as AudioClip;
            death = Resources.Load("Sounds/Death") as AudioClip;

            gameObject.AddComponent <AudioSource>();

            // initialize some audio properties
            GetComponent <AudioSource>().playOnAwake = false;
            GetComponent <AudioSource>().loop        = false;
            GetComponent <AudioSource>().clip        = move1;
        }

        // make sure our localScale is correct for a GUItexture
        transform.position   = Vector3.zero;
        transform.rotation   = Quaternion.identity;
        transform.localScale = Vector3.one;

        // define our snake head and tail texture
        snakeIcon.Add(TextureHelper.CreateTexture(20, 20, Color.yellow));
        snakeIcon.Add(TextureHelper.CreateTexture(20, 20, Color.blue));

        // define our snake head and tail GUI Rect
        snakePos.Add(new Rect(Screen.width * 0.5f - 10, Screen.height * 0.5f - 10, snakeIcon[0].width, snakeIcon[0].height));
        snakePos.Add(new Rect(Screen.width * 0.5f - 10 + 20, Screen.height * 0.5f - 10, snakeIcon[1].width, snakeIcon[1].height));
    }
Ejemplo n.º 9
0
        private static Stick ReadIniStick(IniFile.IniSection sec, FileInfo pi)
        {
            if (sec == null)
            {
                return(null);
            }
            var ret = new Stick {
                Offset = sec.ReadPoint("Position"),
                Size   = sec.ReadSize("Size"),
            };
            var axes = sec.ReadPoint("Axes");

            ret.HorizontalAxis = axes.X;
            ret.VerticalAxis   = axes.Y;
            ret.OffsetScale    = 0.15f;
            ret.Bitmap         = (Bitmap)Image.FromFile(System.IO.Path.Combine(pi.DirectoryName, sec.ReadString("File_Stick", "", false)));
            ret.Texture        = TextureHelper.CreateTexture(ret.Bitmap);
            return(ret);
        }
Ejemplo n.º 10
0
        private void SetupTextureViewer()
        {
            if (!this.TextureRef)
            {
                return;
            }

            string name = TextureRef.name;

            if (string.IsNullOrEmpty(name))
            {
                name = "untitled";
            }
            savePathInput.Text = Path.Combine(ConfigManager.Default_Output_Path.Value, $"{name}.png");

            Sprite sprite = TextureHelper.CreateSprite(TextureRef);

            image.sprite = sprite;
        }
Ejemplo n.º 11
0
        protected override void OnProcess(RenderContext context)
        {
            var graphicsDevice   = GraphicsService.GraphicsDevice;
            var renderTargetPool = GraphicsService.RenderTargetPool;

            if (TextureHelper.IsFloatingPointFormat(context.SourceTexture.Format))
            {
                graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
            }
            else
            {
                graphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
            }

            RenderTarget2D rgbLuma = null;

            if (ComputeLuminance)
            {
                var rgbLumaFormat = new RenderTargetFormat(
                    context.SourceTexture.Width,
                    context.SourceTexture.Height,
                    false,
                    context.SourceTexture.Format,
                    DepthFormat.None);
                rgbLuma = renderTargetPool.Obtain2D(rgbLumaFormat);

                graphicsDevice.SetRenderTarget(rgbLuma);
                _viewportSizeParameter.SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height));
                _sourceTextureParameter.SetValue(context.SourceTexture);
                _luminanceToAlphaPass.Apply();
                graphicsDevice.DrawFullScreenQuad();
            }

            graphicsDevice.SetRenderTarget(context.RenderTarget);
            graphicsDevice.Viewport = context.Viewport;
            _viewportSizeParameter.SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height));
            _sourceTextureParameter.SetValue(ComputeLuminance ? rgbLuma : context.SourceTexture);
            _fxaaPass.Apply();
            graphicsDevice.DrawFullScreenQuad();

            _sourceTextureParameter.SetValue((Texture2D)null);
            renderTargetPool.Recycle(rgbLuma);
        }
Ejemplo n.º 12
0
        public TestObject(GraphicsDevice Device)
            : base(Device)
        {
            Rand_ = new Random((int)DateTime.Now.Ticks);

            var Vertices = new[]
            {
                -1f, 1f, 0f, 0f, 0f, 0f, 0f, 1f,  // 0
                1f, 1f, 0f, 1f, 0f, 0f, 0f, 1f,   // 1
                1f, -1f, 0f, 1f, 1f, 0f, 0f, 1f,  // 2
                -1f, -1f, 0f, 0f, 1f, 0f, 0f, 1f  // 3
            };

            var Indices = new[]
            {
                0, 3, 1, // first triangle
                1, 3, 2  // second triangle
            };

            VertexBuffer_ = new VertexBufferObject(VertexBufferFormat.PositionUvNormal, Vertices);
            IndexBuffer_  = new IndexBufferObject(Indices);

            var DirLight = new Light();

            DirLight.Type      = LightType.Direction;
            DirLight.Direction = new Vector3(0.2f, 0.2f, -1f);
            DirLight.Ambient   = new Colorf(0.05f, 0.05f, 0.05f);
            DirLight.Diffuse   = new Colorf(0.4f, 0.4f, 0.4f);
            DirLight.Specular  = new Colorf(0.5f, 0.5f, 0.5f);
            DirLight.Enabled   = true;
            DirLight.UpdateSIMD();

            Shader_           = new ShaderLight();
            Shader_.Lights    = new Light[1];
            Shader_.Lights[0] = DirLight;

            Shader_.TexDiffuse    = TextureHelper.Load("container2.png");
            Shader_.TexSpecular   = TextureHelper.Load("container2_specular.png");
            Shader_.SpecularPower = 32;

            //Camera_ = new Camera(new Vector3(0, 0, 3), new Vector3(0, 0, -1), new Vector3(0, 1, 0), 60.0f, 800.0f / 600.0f, 0.3f, 100.0f);
            Camera_ = new Camera(800, 600);
        }
Ejemplo n.º 13
0
        public void OnFrame()
        {
            if (recordQueue.Count == 0)
            {
                return;
            }
            ulong completed = graphicsDevice.GetInternalCompletedFenceValue();
            int   width     = ReadBackTexture2D.GetWidth();
            int   height    = ReadBackTexture2D.GetHeight();

            while (recordQueue.Count > 0 && recordQueue.Peek().Item1 <= completed)
            {
                var triple = recordQueue.Dequeue();

                var data = ReadBackTexture2D.StartRead <byte>(triple.Item2);
                TextureHelper.SaveToFile(data, width, height, triple.Item3);
                ReadBackTexture2D.StopRead(triple.Item2);
            }
        }
Ejemplo n.º 14
0
        private void SetFrameBuffer(NvGpuVmm Vmm, int FbIndex)
        {
            long VA = MakeInt64From2xInt32(NvGpuEngine3dReg.FrameBufferNAddress + FbIndex * 0x10);

            int Format = ReadRegister(NvGpuEngine3dReg.FrameBufferNFormat + FbIndex * 0x10);

            if (VA == 0 || Format == 0)
            {
                Gpu.Renderer.FrameBuffer.UnbindColor(FbIndex);

                return;
            }

            long Key = Vmm.GetPhysicalAddress(VA);

            FrameBuffers.Add(Key);

            int Width  = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + FbIndex * 0x10);
            int Height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + FbIndex * 0x10);

            float TX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + FbIndex * 8);
            float TY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + FbIndex * 8);

            float SX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + FbIndex * 8);
            float SY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + FbIndex * 8);

            int VpX = (int)MathF.Max(0, TX - MathF.Abs(SX));
            int VpY = (int)MathF.Max(0, TY - MathF.Abs(SY));

            int VpW = (int)(TX + MathF.Abs(SX)) - VpX;
            int VpH = (int)(TY + MathF.Abs(SY)) - VpY;

            GalImageFormat ImageFormat = ImageFormatConverter.ConvertFrameBuffer((GalFrameBufferFormat)Format);

            GalImage Image = new GalImage(Width, Height, ImageFormat);

            long Size = TextureHelper.GetTextureSize(Image);

            Gpu.Renderer.Texture.CreateFb(Key, Size, Image);
            Gpu.Renderer.FrameBuffer.BindColor(Key, FbIndex);

            Gpu.Renderer.FrameBuffer.SetViewport(VpX, VpY, VpW, VpH);
        }
Ejemplo n.º 15
0
        private void RenderStick(Stick stick)
        {
            bool pressed = State != null && stick.PressedTexture != -1 && stick.ButtonId != -1 &&
                           State.Buttons.Count > stick.ButtonId && State.Buttons[stick.ButtonId];
            var   r = pressed ? stick.PressedBounds : stick.Bounds;
            float x = 0.0f, y = 0.0f;

            if (State != null)
            {
                if (stick.HorizontalAxis < State.Axes.Count)
                {
                    x = (float)(State.Axes[stick.HorizontalAxis] * 128.0f);
                }
                if (Math.Abs(x) < stick.Deadzone)
                {
                    x = 0;
                }

                if (stick.VerticalAxis < State.Axes.Count)
                {
                    y = (float)(State.Axes[stick.VerticalAxis] * 128.0f);
                }
                if (Math.Abs(y) < stick.Deadzone)
                {
                    y = 0;
                }
            }
            else
            {
                x = y = 0f;
            }

            SizeF img = GetCorrectedDimensions(new SizeF(SvgDocument.Width, SvgDocument.Height));

            x *= img.Width / _dimensions.Width * stick.OffsetScale;
            y *= img.Height / _dimensions.Height * stick.OffsetScale;
            r.Offset(new PointF(x, y));

            int texture = pressed && stick.PressedTexture != -1 ? stick.PressedTexture : stick.Texture;

            GL.BindTexture(TextureTarget.Texture2D, texture);
            TextureHelper.RenderTexture(r);
        }
Ejemplo n.º 16
0
        public Turret(ContentManager content, Vector2 position, Stage stage, string enemytype)
            : base(content, position, stage, enemytype)
        {
            PlayerSpriteCollection spritecollection;
            Texture2D turrettileset;

            spritecollectionlist = new List <PlayerSpriteCollection>();
            turrettileset        = content.Load <Texture2D>("Sprites/Enemies/Turret");

            spritecollection = new PlayerSpriteCollection();
            spritecollection.Initialize(TextureHelper.SwapColor(turrettileset, new Color(192, 32, 0), new Color(184, 28, 12)), position, 12, Color.White, 1f);
            spritecollectionlist.Add(spritecollection);

            spritecollection = new PlayerSpriteCollection();
            spritecollection.Initialize(TextureHelper.SwapColor(turrettileset, new Color(192, 32, 0), new Color(228, 68, 52)), position, 12, Color.White, 1f);
            spritecollectionlist.Add(spritecollection);

            spritecollection = new PlayerSpriteCollection();
            spritecollection.Initialize(turrettileset, position, 12, Color.White, 1f);
            spritecollectionlist.Add(spritecollection);

            CollisionIsHazardous = false;

            _health           = 15;
            _currentPosition  = 3;
            TimeTargetLocked  = 0.0f;
            _elapsedTime      = 0;
            _currentFrame     = 0;
            _animatingforward = true;

            // RGB colors for blinking animations of turret.
            //R 255 228  184
            //G 140 68   28
            //B 124 52   12

            projectileTexture = content.Load <Texture2D>("Sprites/Projectiles/basicbullet");

            ExplosionAnimation.Initialize(content.Load <Texture2D>("Sprites/Explosion2"), WorldPosition, 5, 150, Color.White, 1f, false, this.CurrentStage);
            ExplosionSound = content.Load <SoundEffect>("Sounds/Explosion2");

            _gun = new EnemyGun(this, projectileTexture);
        }
Ejemplo n.º 17
0
        public void RenderDocument(ViewportBase viewport, Document document)
        {
            if (document.Pointfile == null)
            {
                return;
            }
            var pf  = document.Pointfile;
            var vp2 = viewport as Viewport2D;
            Func <Coordinate, Coordinate> transform = x => x;

            if (vp2 != null)
            {
                transform = vp2.Flatten;
            }

            TextureHelper.Unbind();
            GL.LineWidth(3);
            GL.Begin(PrimitiveType.Lines);

            var r      = 1f;
            var g      = 0.5f;
            var b      = 0.5f;
            var change = 0.5f / pf.Lines.Count;

            foreach (var line in pf.Lines)
            {
                var start = transform(line.Start);
                var end   = transform(line.End);

                GL.Color3(r, g, b);
                GL.Vertex3(start.DX, start.DY, start.DZ);

                r -= change;
                b += change;

                GL.Color3(r, g, b);
                GL.Vertex3(end.DX, end.DY, end.DZ);
            }

            GL.End();
            GL.LineWidth(1);
        }
Ejemplo n.º 18
0
        public override void Render(ViewportBase viewport)
        {
            if (_currentPoint != null)
            {
                var sub      = new Coordinate(40, 40, 40);
                var pointBox = new Box(_currentPoint.CurrentPosition.Location - sub, _currentPoint.CurrentPosition.Location + sub);

                TextureHelper.Unbind();
                GL.LineWidth(3);
                GL.Begin(PrimitiveType.Lines);
                GL.Color3(1f, 1, 0);
                foreach (var line in pointBox.GetBoxLines())
                {
                    GL.Vertex3(line.Start.DX, line.Start.DY, line.Start.DZ);
                    GL.Vertex3(line.End.DX, line.End.DY, line.End.DZ);
                }
                GL.End();
                GL.LineWidth(1);
            }
        }
Ejemplo n.º 19
0
 public BurningBuff(int dur, int lvl, AnimatedSprite target) :
     base("Burning", dur, lvl, "You're burning!", texture: TextureHelper.Blank(Color.Red))
 {
     Target  = target;
     OnStart = () =>
     {
         if (timer == null)
         {
             timer = new TimerHelper(
                 GameMathHelper.TimeToFrames(0.3f - (0.3f / 20f * (lvl - 1f))),
                 () => { Target.AddHealthIgnoreInvincibility(-(1 + (lvl / 2))); }
                 );
         }
     };
     OnEnd = () =>
     {
         timer?.Delete();
         timer = null;
     };
 }
Ejemplo n.º 20
0
    void spellSelected(SpellSelectedEvent selectedSpell)
    {
        Debug.Log("UI canvas spell selected");

        if (selectedSpell.selected)
        {
            //if (selectedSpell.spell.spellType == TempSpell.SpellType.PROJECTILE)
            //{

            this.selectedSpell = selectedSpell.spell.spell;

            //}
        }
        else
        {
            this.selectedSpell = null;
            clearTexture(UITexture);
            TextureHelper.ApplyTexture(UITexture, SpriteRenderer, new Vector2(0.5f, 0.5f));
        }
    }
Ejemplo n.º 21
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            Graphics    = graphics.GraphicsDevice;
            GameContent = Content;
            ControllerManager.Initialize();
            GameDebugger.Initialize();
            TextureHelper.Init();
            Segment.Initialize();
            GameSpriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            TileHighlight.Initialize();
            roamState  = new TestFreeRoamState();
            fightState = new TestFightState();
            editState  = new TestEditState();

            StateManager.QueueState(editState);
            this.IsMouseVisible = true;
            base.Initialize();
        }
Ejemplo n.º 22
0
    public void GeneratePreview()
    {
        if (!(target is BlockType))
        {
            return;
        }

        var block     = (BlockType)target;
        var rectangle = new Rect(0, 0, DefaultPreviewSize, DefaultPreviewSize);

        var background = previewRenderUtility.camera.backgroundColor;

        previewRenderUtility.camera.backgroundColor = Color.clear;

        var resultRender = RenderPreview(rectangle, GUIStyle.none);

        TextureHelper.SaveTexture(block.blockName, (RenderTexture)resultRender);

        previewRenderUtility.camera.backgroundColor = background;
    }
Ejemplo n.º 23
0
        public void ApplySmoothedTextures()
        {
            if (smoothedTextures.Count == 0)
            {
                foreach (var part in HeadMesh.Parts)
                {
                    if (!smoothedTextures.Contains(part.Texture) && part.Texture > 0)
                    {
                        smoothedTextures.Add(part.Texture);
                    }
                }
            }

            foreach (var smoothTex in smoothedTextures)
            {
                var bitmap = RenderToTexture(smoothTex);
                TextureHelper.SetTexture(smoothTex, bitmap);
                bitmap.Save("texture_" + smoothTex.ToString() + ".png");
            }
        }
Ejemplo n.º 24
0
 public RegenerationBuff(int dur, int lvl, AnimatedSprite target) :
     base("Regeneration", dur, lvl, "Your wounds are healing", texture: TextureHelper.Blank(Color.LightPink))
 {
     Target  = target;
     OnStart = () =>
     {
         if (timer == null)
         {
             timer = new TimerHelper(
                 GameMathHelper.TimeToFrames(0.3f - (0.3f / 20f * (lvl - 1f))),
                 () => { Target.AddHealth(1 + (lvl / 2)); }
                 );
         }
     };
     OnEnd = () =>
     {
         timer?.Delete();
         timer = null;
     };
 }
Ejemplo n.º 25
0
        public override void Render(ViewportBase viewport)
        {
            TextureHelper.Unbind();
            GL.Begin(PrimitiveType.Lines);
            foreach (var face in Document.Selection.GetSelectedFaces())
            {
                var lineStart = face.BoundingBox.Center + face.Plane.Normal * 0.5m;
                var uEnd      = lineStart + face.Texture.UAxis * 20;
                var vEnd      = lineStart + face.Texture.VAxis * 20;

                GL.Color3(Color.Yellow);
                GL.Vertex3(lineStart.DX, lineStart.DY, lineStart.DZ);
                GL.Vertex3(uEnd.DX, uEnd.DY, uEnd.DZ);

                GL.Color3(Color.FromArgb(0, 255, 0));
                GL.Vertex3(lineStart.DX, lineStart.DY, lineStart.DZ);
                GL.Vertex3(vEnd.DX, vEnd.DY, vEnd.DZ);
            }
            GL.End();
        }
Ejemplo n.º 26
0
    void Init(bool regenerateMesh)
    {
        if (regenerateMesh)
        {
            GenerateMesh();
        }
        var customPostProcessing = FindObjectOfType <CustomPostProcessing> ();

        customPostProcessing.onPostProcessingComplete -= Set;
        customPostProcessing.onPostProcessingComplete += Set;
        cam = customPostProcessing.GetComponent <Camera> ();
        TextureHelper.TextureFromGradient(colourSpectrum, 64, ref spectrum);
        mat.SetTexture("_Spectrum", spectrum);
        mat.SetFloat("daytimeFade", daytimeFade);

        if (!oceanMaskRenderer)
        {
            oceanMaskRenderer = FindObjectOfType <OceanMaskRenderer> ();
        }
    }
Ejemplo n.º 27
0
        public Grass(CowGameScreen cowGameScreen, World world, Vector2 position)
            : base(cowGameScreen, world, new Rectangle((int)position.X, (int)position.Y, 25, 51), new StaticAnimatedSprites(cowGameScreen.GameTextures["grassMovement"], 1, 0))
        {
            _currentAnim        = PlantMovement;
            _eatenGrassMovement = new StaticAnimatedSprites(cowGameScreen.GameTextures["eatenGrassMovement"], 1, 0);

            CurrentWorld = world;

            Body = BodyFactory.CreateRectangle(world, (float)DestRect.Width / 100, (float)DestRect.Height / 200, 0, new Vector2((float)(DestRect.X + DestRect.Width / 2) / 100, (float)(DestRect.Y + 30) / 100));

            Body.BodyTypeName        = "grass";
            Body.BodyType            = BodyType.Static;
            Body.CollisionCategories = Category.Cat10;
            Body.CollidesWith        = Category.Cat10;

            ReapaintTexture = TextureHelper.RepaintRectangle(TextureHelper.CopyTexture(PlantMovement.Animation, Graphics));
            CanInteract     = true;
            world.AddStaticEntity(this);
            _eatedTime = TimeSpan.Zero;
        }
Ejemplo n.º 28
0
        public void Render2D()
        {
            if (!Focus || !FreeLook)
            {
                return;
            }

            TextureHelper.Unbind();
            GL.Begin(PrimitiveType.Lines);
            GL.Color3(Color.White);
            GL.Vertex2(0, -5);
            GL.Vertex2(0, 5);
            GL.Vertex2(1, -5);
            GL.Vertex2(1, 5);
            GL.Vertex2(-5, 0);
            GL.Vertex2(5, 0);
            GL.Vertex2(-5, 1);
            GL.Vertex2(5, 1);
            GL.End();
        }
Ejemplo n.º 29
0
    public static void CreateGUITexture(Rect coorindates, Color colTexture, string name, float layer)
    {
        // we need a new game object to hold the component
        GameObject guiTextureObject = new GameObject(name);

        // set some gameObject properties
        guiTextureObject.transform.position   = new Vector3(0, 0, layer);
        guiTextureObject.transform.rotation   = Quaternion.identity;
        guiTextureObject.transform.localScale = new Vector3(0.01f, 0.01f, 1.0f);

        // add our GUITexture Component
        GUITexture guiDisplayTexture = guiTextureObject.AddComponent <GUITexture>();

        // create a simple 1x1 black texture
        Texture2D guiTexture = TextureHelper.Create1x1Texture(colTexture);

        // set some GUITexture properties
        guiDisplayTexture.texture    = guiTexture;
        guiDisplayTexture.pixelInset = coorindates;
    }
Ejemplo n.º 30
0
        private void RenderTrigger(Trigger trigger)
        {
            if (trigger.Texture >= 0)
            {
                var   r = Scale(trigger.Location, trigger.Size);
                float o = 0.0f;
                if (State != null && State.Axes.Count > trigger.Id)
                {
                    o = (float)State.Axes[trigger.Id];
                }
                o *= 256.0f;
                o  = trigger.Range.Clip(o);

                RectangleF crop      = new RectangleF(PointF.Empty, new SizeF(1.0f, 1.0f));
                float      pressRate = (o - trigger.Range.LowerBound) / (trigger.Range.UpperBound - trigger.Range.LowerBound);
                if (trigger.Inverse)
                {
                    pressRate = 1.0f - pressRate;
                }

                if (trigger.Orientation == TriggerOrientation.Horizontal)
                {
                    crop.X     = trigger.Reverse ^ trigger.Inverse ? 1.0f - pressRate : 0;
                    crop.Width = pressRate;
                }
                else
                {
                    crop.Y      = trigger.Reverse ^ trigger.Inverse ? 1.0f - pressRate : 0;
                    crop.Height = pressRate;
                }

                // compensate texture size for crop rate
                r.X      += r.Width * crop.X;
                r.Y      += r.Height * crop.Y;
                r.Width  *= crop.Width;
                r.Height *= crop.Height;

                GL.BindTexture(TextureTarget.Texture2D, trigger.Texture);
                TextureHelper.RenderTexture(crop, r);
            }
        }