Example #1
0
    public void loadLastDrawings()
    {
        var img = new Image();
        var err = img.Load("user://lastDraw.png");

        if (err == Error.Ok)
        {
            var imgTex = new ImageTexture();
            imgTex.CreateFromImage(img);
            var spr = new Sprite();
            spr.Centered = false;
            var shader   = (Shader)ResourceLoader.Load("res://shaders/blackFix.shader");
            var material = new ShaderMaterial();
            material.Shader = shader;
            spr.Material    = material;

            spr.Material = material;
            spr.Texture  = imgTex;
            drawContainerNode.AddChild(spr);
        }
        else
        {
            GD.PrintErr(err);
        }
    }
Example #2
0
        TerrainTile TileLoad(int tileX, int tileY)
        {
            Assert(!HasNode(TileNodeName(tileX, tileY)), $"Tile [{tileX}, {tileY}] already loaded");

            var tileData = _tileBuffer.Value;

            if (!TryLoadTileFile(tileX, tileY, tileData))
            {
                TileGenerate(tileX, tileY, tileData);
            }

            var texture = new ImageTexture();

            tileData.ExportTo(texture);

            var tile = (TerrainTile)Config.TerrainTile !.Instance();

            tile.Name        = TileNodeName(tileX, tileY);
            tile.TileX       = tileX;
            tile.TileY       = tileY;
            tile.DataTexture = texture;
            ((ShaderMaterial)tile.RenderSprite.Material).SetShaderParam("Materials", Materials);

            var neighbors = GetTilesRange(tileX - 1, tileX + 1, tileY - 1, tileY + 1);

            foreach (var neighbor in neighbors)
            {
                neighbor.SetDataTexture(tileX, tileY, texture);
                tile.SetDataTexture(neighbor.TileX, neighbor.TileY, neighbor.DataTexture);
            }

            AddChild(tile);

            return(tile);
        }
Example #3
0
        public Particle(ImageTexture texture, float x, float y, float _rotation, float speed, int lifetime, float sizex, float sizey, byte[] color, int parent, bool physics, bool mass) : base()
        {
            Type = "Particle.Particle";
            SetSize(sizex, sizey);
            SetTexture(texture);
            _lifeTime = lifetime;
            SetRotation(_rotation);
            SetPos(x, y);
            _speed = speed;
            EnablePhysics(physics);
            SetStaticObject(false);
            EnableAirResistance(false);
            SetIsParticle(true);
            HasMass(mass);
            float xAdd = (float)Math.Sin((double)GetRotation());
            float yAdd = (float)Math.Cos((double)GetRotation());

            SetVelocity(xAdd * _speed, yAdd * _speed);
            SetPhysSize(0.1f);
            SetColor(color);
            _parent = parent;
            if (parent != 0)
            {
                Z_Index = TomatoMainEngine.GetRenderObject(_parent).Z_Index - 1;
            }
            else
            {
                Z_Index = 999999999;
            }
        }
Example #4
0
    void loadBody(StadiumObject stadiumObject)
    {
        StaticBody2D body = new StaticBody2D();

        ImageTexture texture = new ImageTexture();

        texture.Load(stadiumObject.TexturePath);
        Sprite sprite = new Sprite();

        sprite.Texture = texture;
        if (stadiumObject.Shape == StadiumObject.Type.RECT)
        {
            sprite.Centered = false;
        }
        body.AddChild(sprite);

        float positionX = (float)(stadiumObject.ShapeStruct.Position.X);
        float positionY = (float)(stadiumObject.ShapeStruct.Position.Y);

        body.Position = new Godot.Vector2(positionX, positionY);

        if (stadiumObject.Shape == StadiumObject.Type.RECT)
        {
            body = loadRectBody(stadiumObject, body);
        }
        else
        {
            body = loadCircBody(stadiumObject, body);
        }


        AddChild(body);
    }
Example #5
0
    void initializeBackground()
    {
        ImageTexture texture = new ImageTexture();

        texture.Load(data.BackgroundTexturePath);
        background.Texture = texture;
    }
        /// <summary>
        /// Pipes an OpenGL rendering; converting the frame buffer to ASCII text,
        /// and outputting into the System.Console.
        /// </summary>
        /// <param name="rc">
        /// The rendering context.
        /// </param>
        /// <param name="renderBlock">
        /// The rendering method to execute.
        /// </param>
        public void PipeToConsole(RenderingContext rc, Action renderBlock)
        {
            Bitmap frame;
            string frameBuffer;
            int    rows;
            int    columns;

            frame = CaptureFramebufferAsBitmap(rc, renderBlock);

            ImageTexture.Scale(ref frame, new Size(100, 100));
            frame.RotateFlip(RotateFlipType.Rotate180FlipX);

            //frame.Save("D:\\test-frame2.png");

            frameBuffer = asciiTextImageTranslator(frame, out rows, out columns);

            frame.Dispose();

            Console.Clear();
            //Console.WindowWidth = rows;
            //Console.WindowHeight = columns + 1;
            //Console.BufferWidth = rows + 1;
            //Console.BufferHeight = columns + 1;

            Console.Write(frameBuffer);
        }
Example #7
0
    public static unsafe void RebuildFontAtlas()
    {
        var io = ImGui.GetIO();

        io.Fonts.GetTexDataAsRGBA32(out byte *pixelData, out int width, out int height, out int bytesPerPixel);

        byte[] pixels = new byte[width * height * bytesPerPixel];
        Marshal.Copy(new IntPtr(pixelData), pixels, 0, pixels.Length);

        Image img = new Image();

        img.CreateFromData(width, height, false, Image.Format.Rgba8, pixels);

        var imgtex = new ImageTexture();

        imgtex.CreateFromImage(img, 0);

        if (_fontTextureId.HasValue)
        {
            UnbindTexture(_fontTextureId.Value);
        }
        _fontTextureId = BindTexture(imgtex);

        io.Fonts.SetTexID(_fontTextureId.Value);
        io.Fonts.ClearTexData();
    }
Example #8
0
    void setCountry()
    {
        ImageTexture texture = new ImageTexture();

        texture.Load($"Resources/Graphics/Flags/{Team.TeamData.Country}.png");
        country.Texture = texture;
    }
Example #9
0
    void setKit(string teamShort)
    {
        ImageTexture texture = new ImageTexture();

        texture.Load($"Resources/Graphics/Teams/{teamShort}/kit.png");
        kit.Texture = texture;
    }
        public void ParseData(MemoryStream stream)
        {
            var img = new Image();

            if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".png", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadPngFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".jpg", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadJpgFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".bmp", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadBmpFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".tga", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadTgaFromBuffer(stream.ToArray());
            }
            else if (System.IO.Path.GetExtension(uri.AbsolutePath).Equals(".webp", StringComparison.OrdinalIgnoreCase))
            {
                img.LoadWebpFromBuffer(stream.ToArray());
            }
            img.FlipY();

            var imageTexture = new ImageTexture();

            imageTexture.CreateFromImage(img);
            Texture = imageTexture;
        }
    void setCountry()
    {
        ImageTexture countryTexture = new ImageTexture();

        countryTexture.Load($"Resources/Graphics/Flags/{footballerData.Country}.png");
        country.Texture = countryTexture;
    }
Example #12
0
 public ParticleSystem(string texture)
 {
     _texture = ResourceManager.GetTexture(texture);
     _color[0] = 255;
     _color[1] = 255;
     _color[2] = 255;
 }
Example #13
0
    public static Texture GenerateColorTexture(float[,] noiseMap, float[] regionThresholds, Color[] regionColors)
    {
        int width  = noiseMap.GetLength(0);
        int height = noiseMap.GetLength(1);

        Image mapImage = new Image();

        mapImage.Create(width, height, true, Image.Format.Rgb8);
        mapImage.Lock();
        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                for (int i = 0; i < regionThresholds.Length; ++i)
                {
                    if (noiseMap[x, y] <= regionThresholds[i])
                    {
                        mapImage.SetPixel(x, y, regionColors[i]);
                        break;
                    }
                }
            }
        }
        mapImage.Unlock();

        ImageTexture mapTexture = new ImageTexture();

        mapTexture.CreateFromImage(mapImage);
        mapTexture.Flags = (uint)ImageTexture.FlagsEnum.Mipmaps;

        return(mapTexture);
    }
Example #14
0
    public void finalToConvertSprite()
    {
        GD.Print("final the convertion");
        GD.Print("first draw");
        var img = captureViewport.GetTexture().GetData();

        img.FlipY();
        var imgTex = new ImageTexture();

        imgTex.CreateFromImage(img);
        var convertedSprite = new Sprite();

        convertedSprite.Texture  = imgTex;
        convertedSprite.Centered = false;
        convertedSprite.Position = new Vector2(xMin, yMin);
        if (drawMode == drawObjectMode.brush)
        {
            var material = new ShaderMaterial();
            material.Shader          = (Shader)ResourceLoader.Load("res://shaders/blackFix.shader");
            convertedSprite.Material = material;
        }
        else if (drawMode == drawObjectMode.erase)
        {
            convertedSprite.Material = Material;
        }
        GetParent().AddChild(convertedSprite);
        this.Visible = false;
        EmitSignal("converted_sprite", this, convertedSprite);
        captureViewport.QueueFree();
        cloneDrawObject.QueueFree();

        expectedSpriteConvertion = false;
        this.QueueFree();
    }
Example #15
0
    private void SetShaderTiles()
    {
        int startX = (int)Position.x / 16;
        int startY = (int)Position.y / 16;

        float[] regionTileInfo = new float[(int)(sizeInTiles.y - startY) + (int)(sizeInTiles.x - startX)];

        for (int y = startY; y < startY + sizeInTiles.y; y++)
        {
            for (int x = startX; x < startX + sizeInTiles.x; x++)
            {
                if (WithinBounds(x, y))
                {
                    regionTileInfo[y + x] = lightValues[x, y] * 255;
                }
                else
                {
                    regionTileInfo[y + x] = 255;
                }
            }
        }

        Image img = new Image();

        byte[] byteRegionTileInfo = new byte[regionTileInfo.Length * 4];
        Buffer.BlockCopy(regionTileInfo, 0, byteRegionTileInfo, 0, byteRegionTileInfo.Length);
        img.CreateFromData((int)sizeInTiles.x, (int)sizeInTiles.y, false, Image.Format.L8, byteRegionTileInfo);

        ImageTexture tex = new ImageTexture();

        tex.CreateFromImage(img);
        (this.Material as ShaderMaterial).SetShaderParam("lightValues", tex);
    }
Example #16
0
    public override void _Ready()
    {
        if (Terrain == null || Terrain.GetWidth() != TileSize || Terrain.GetHeight() != TileSize)
        {
            Terrain = new ImageTexture();
            Terrain.Create(TileSize, TileSize, Image.Format.Rgbaf);
            terrainImg = new Image();
            terrainImg.Create(TileSize, TileSize, false, Image.Format.Rgbaf);
        }
        if (Mesh == null)
        {
            var mesh = new PlaneMesh();
            mesh.Size           = new Vector2(TileSize, TileSize);
            mesh.SubdivideWidth = TileSize;
            mesh.SubdivideDepth = TileSize;
            Mesh = mesh;
            var mat = new ShaderMaterial();
            mat.SetShader(TerrainShader);
            SetSurfaceMaterial(0, mat);
        }

        if (WorldPos != Vector3.Zero)
        {
            _LoadTerrainData();
        }

        hydraulics = new HydraulicSimulation(Terrain);
        terrainImg = Terrain.GetData();
    }
Example #17
0
    /// <summary>
    /// Stack the sprites
    /// </summary>
    public void MakeStackFromPath(string path)
    {
        // Set the name of the stack to the name of the loaded folder.
        string[] path_ = path.Split("\\");
        this.Name = path_[path_.Length - 1];

        int offset = 0;

        foreach (var image in GetSpritesFromPath(path))
        {
            // Loading Image
            var image_ = new Image();
            GD.Print(image);
            image_.Load(image);

            // Making ImageTexture from image.
            var texture = new ImageTexture();
            texture.CreateFromImage(image_);
            texture.SetData(image_);

            // Adding the layer
            var sprite = new Sprite();
            sprite.SetTexture(texture);
            sprite.Position -= new Vector2(0, offset);
            sprite.Name      = offset.ToString();

            Layers[Layers.Length - 1] = sprite;
            this.AddChild(sprite);

            // Increasing the offset for next layer.
            offset += 1;
        }
    }
Example #18
0
    /// <summary>
    /// Stack the sprites, but with a custom spacing between each layer.
    /// </summary>
    public void MakeStackFromPath(string path, int offsetSize)
    {
        int offset = 0;

        foreach (var image in GetSpritesFromPath(path))
        {
            // Loading Image
            var image_ = new Image();
            image_.Load(image);

            // Making ImageTexture from image.
            var texture = new ImageTexture();
            texture.CreateFromImage(image_);
            texture.SetData(image_);

            // Adding the layer
            var sprite = new Sprite();
            sprite.SetTexture(texture);
            sprite.Position -= new Vector2(0, offset * offsetSize);
            sprite.Name      = offset.ToString();

            Layers[Layers.Length] = sprite;
            AddChild(sprite);

            // Increasing the offset for next layer.
            offset += 1;
        }
    }
Example #19
0
    void updateFederationCountryFlag(string identifier)
    {
        ImageTexture texture = new ImageTexture();

        texture.Load($"Resources/Graphics/Flags/{identifier}.png");
        flag.Texture = texture;
    }
Example #20
0
    public override void _Process(float delta)
    {
        if (!loadingData)
        {
            return;
        }

        if (!saveInfoLoadTask.IsCompleted)
        {
            return;
        }

        var save = saveInfoLoadTask.Result;

        saveInfoLoadTask.Dispose();
        saveInfoLoadTask = null;

        // Screenshot
        var texture = new ImageTexture();

        texture.CreateFromImage(save.Screenshot);

        screenshot.Texture = texture;

        // General info
        version.Text           = save.Info.ThriveVersion;
        type.Text              = save.Info.Type.ToString();
        createdAt.Text         = save.Info.CreatedAt.ToString("G", CultureInfo.CurrentCulture);
        createdBy.Text         = save.Info.Creator;
        createdOnPlatform.Text = save.Info.Platform.ToString();
        description.Text       = save.Info.Description;

        loadingData = false;
    }
Example #21
0
        public void Cube()
        {
            var texture = new ImageTexture(AppContext.BaseDirectory + "/Resources/Images/tex.jpg");
            var camera  = GameObject.Create(new Vector3(0, 0, 0), new Vector3(30, 0, 0));
            var light   = GameObject.Create(new Vector3(0, 1f, 1), new Vector3());

            light.AddComponent(new Light {
                intensity = 2, color = Color32.White
            });
            camera.AddComponent(new Camera((float)Math.PI / 4, Canvas.Width / (float)Canvas.Height, 1f, 500f));
            var mat = new Material(new VSampleShader(), new FSampleShader {
                image = texture
            });
            var game_object2 = new GameObject
            {
                renderer = new MeshRenderer
                {
                    mesh_filter = new MeshFilter
                    {
                        mesh = new Mesh(Model.Cube)
                    },
                    material = mat
                               //new Material(new Phong(), Color32.Blue)
                },
                transform = new Transform(new Vector3(0f, -1.5f, 2.5f), new Vector3(0, 0, 0)),
            };

            game_object2.AddComponent(new AutoRotate(30));
        }
Example #22
0
        protected override object CreateResourceConfiguration(string fileName)
        {
            var extension = Path.GetExtension(fileName);

            fileName = PathConvert.GetProjectPath(fileName);

            Texture2D configuration;

            if (Array.IndexOf(VideoExtensions, extension) >= 0)
            {
                if (Control.ModifierKeys == Keys.Control)
                {
                    configuration = new ImageSequence {
                        FileName = fileName
                    }
                }
                ;
                else
                {
                    configuration = new VideoTexture {
                        FileName = fileName
                    }
                };
            }
            else
            {
                configuration = new ImageTexture {
                    FileName = fileName
                }
            };
            configuration.Name = Path.GetFileNameWithoutExtension(fileName);
            return(configuration);
        }
    }
Example #23
0
    void setCountry(string countryCode)
    {
        ImageTexture texture = new ImageTexture();

        texture.Load($"Resources/Graphics/Flags/{countryCode}.png");
        country.Texture = texture;
    }
Example #24
0
    public void GenerateFromPerlinNoise(float period, int octaves, float lacunarity, float persistence)
    {
        terrainImg = new Image();
        terrainImg.Create(TileSize, TileSize, false, Image.Format.Rgbaf);
        var noise = new OpenSimplexNoise();

        noise.Seed        = rng.Next();
        noise.Octaves     = octaves;
        noise.Period      = period;
        noise.Lacunarity  = lacunarity;
        noise.Persistence = persistence;
        var   center    = new Vector2(TileSize / 2f, TileSize / 2f);
        float maxDist   = 0.75f * (TileSize / 2f);
        float maxHeight = 40f;

        terrainImg.Lock();
        for (int x = 0; x < TileSize; x++)
        {
            for (int y = 0; y < TileSize; y++)
            {
                float distance             = new Vector2(x, y).DistanceTo(center);
                float inverseDistanceRatio = 1 - (distance / maxDist);
                float noiseHeight          = noise.GetNoise2d(x, y) + 0.5f;
                float height = 0f;
                if (distance <= maxDist)
                {
                    height = Mathf.Max(0, maxHeight * inverseDistanceRatio * noiseHeight);
                }
                terrainImg.SetPixel(x, y, new Color(height, 0, 0, 0));
            }
        }
        terrainImg.Unlock();
        Terrain = new ImageTexture();
        Terrain.CreateFromImage(terrainImg);
    }
Example #25
0
        private static ImageTexture ImageTextureData(string[] lines, int startIndex, int endIndex)
        {
            ImageTexture imageTexture = new ImageTexture();

            for (int i = startIndex + 1; i < endIndex; i++)
            {
                string[] lineSplit = GenericUtils.SplitKeyValue(lines[i]);
                string   k = lineSplit[0]; string v = lineSplit[1];
                switch (k)
                {
                case "repeatS":
                    imageTexture.RepeatS = v;
                    break;

                case "repeatT":
                    imageTexture.RepeatT = v;
                    break;

                case "url":
                    imageTexture.Url = GenericUtils.SplitQuoteValue(v);     // url "3DCCECBB_c.bmp"
                    break;

                default:
                    break;
                }
            }
            return(imageTexture);
        }
Example #26
0
        private ImageTexture[] loadMaterialTextures(ai.Material material, ai.TextureType type, TextureType textureType)
        {
            ImageTexture[] textures = new ImageTexture[material.GetMaterialTextureCount(type)];

            for (int i = 0; i < textures.Length; i++)
            {
                ai.TextureSlot slot;
                material.GetMaterialTexture(type, i, out slot);

                string path = directory + slot.FilePath;

                ImageTexture texture;

                ImageTexture loaded = loadedTextures.Find(x => x.path == path);

                if (loaded != null)
                {
                    texture = loaded;
                }
                else
                {
                    texture = new ImageTexture(gl, path, textureType);
                    loadedTextures.Add(texture);
                    Console.WriteLine($"Texture file path: {path}");
                }

                textures[i] = texture;
            }

            return(textures);
        }
Example #27
0
 public Particle(ImageTexture texture, float x, float y, float _rotation, float speed, int lifetime, float sizex, float sizey, byte[] color, int parent, bool physics, bool mass)
     : base()
 {
     Type = "Particle.Particle";
     SetSize(sizex,sizey);
     SetTexture(texture);
     _lifeTime = lifetime;
     SetRotation(_rotation);
     SetPos(x,y);
     _speed = speed;
     EnablePhysics(physics);
     SetStaticObject(false);
     EnableAirResistance(false);
     SetIsParticle(true);
     HasMass(mass);
     float xAdd = (float)Math.Sin((double)GetRotation());
     float yAdd = (float)Math.Cos((double)GetRotation());
     SetVelocity(xAdd * _speed, yAdd * _speed);
     SetPhysSize(0.1f);
     SetColor(color);
     _parent = parent;
     if ( parent  != 0 )
     {
         Z_Index = TomatoMainEngine.GetRenderObject(_parent).Z_Index - 1;
     }
     else
     {
         Z_Index = 999999999;
     }
 }
Example #28
0
    public static Texture GenerateNoiseTexture(float[,] noiseMap)
    {
        int width  = noiseMap.GetLength(0);
        int height = noiseMap.GetLength(1);

        Image mapImage = new Image();

        mapImage.Create(width, height, true, Image.Format.Rgb8);
        mapImage.Lock();
        for (int y = 0; y < height; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                mapImage.SetPixel(x, y, Colors.Black.LinearInterpolate(Colors.White, noiseMap[x, y]));
            }
        }
        mapImage.Unlock();

        ImageTexture mapTexture = new ImageTexture();

        mapTexture.CreateFromImage(mapImage);
        mapTexture.Flags = (uint)ImageTexture.FlagsEnum.Mipmaps;

        return(mapTexture);
    }
 public ParticleSystem(string texture)
 {
     _texture  = ResourceManager.GetTexture(texture);
     _color[0] = 255;
     _color[1] = 255;
     _color[2] = 255;
 }
    private static Texture image2Texture(Image image)
    {
        var texture = new ImageTexture();

        texture.CreateFromImage(image, (int)Texture.FlagsEnum.Repeat);
        return(texture);
    }
Example #31
0
    public void SetImageOnSprite(Image image)
    {
        ImageTexture texture = new ImageTexture();

        texture.CreateFromImage(image, 0);
        TokenSprite.Texture = texture;
    }
Example #32
0
        public static ImageTexture RadialGradient(int width, int height, Gradient gradient)
        {
            Image image = new Image();

            image.Create(width, height, true, Image.Format.Rgb8);
            image.Lock();

            Color[,] colors = Gradients.RadialGradient(width, height, gradient);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    image.SetPixel(x, y, colors[x, y]);
                }
            }

            image.Unlock();

            ImageTexture tex = new ImageTexture();

            tex.CreateFromImage(image);

            return(tex);
        }
Example #33
0
 public void SetTexture(ImageTexture texture)
 {
     _texture = texture;
 }