コード例 #1
0
        private WowMaterial MakeMaterialFromWhTexUnit(WhTexUnit whTexUnit)
        {
            var material = new WowMaterial()
            {
                BothSides = !whTexUnit.Cull,
                Type      = GetMaterialTypeFromBlendFlag(whTexUnit.RenderFlag.Blend)
            };

            var whTextures = whTexUnit.GetTextures();

            var images = new TextureImage[]
            {
                GetImageFromWhTextureInfo(whTextures["Texture1"]),
                GetImageFromWhTextureInfo(whTextures["Texture2"]),
                GetImageFromWhTextureInfo(whTextures["Texture3"]),
                GetImageFromWhTextureInfo(whTextures["Texture4"])
            };

            material.MainImage = images.FirstOrDefault(x => x != null);

            material.Image1 = images[0];
            material.Image2 = images[1];
            material.Image3 = images[2];
            material.Image4 = images[3];

            return(material);
        }
コード例 #2
0
        protected override void OnShown()
        {
            base.OnShown();

            var stackPanel = new StackPanel()
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            var imageSource = new TextureImage(new Texture2DAdapter(GetService <CommonContentManager>().Logo));
            var image       = new Image()
            {
                Source = imageSource,
                HorizontalAlignment = HorizontalAlignment.Center,
                Stretch             = Stretch.None,
                Margin = new Thickness(0, 0, 0, 40)
            };

            stackPanel.Children.Add(image);

            AddButton(stackPanel, "new game", () => Messenger.Send(new StartingSinglePlayerGameMessage()));
            AddButton(stackPanel, "start a multiplayer game", () => TransitionToScreen("StartMultiplayer"));
            AddButton(stackPanel, "join a multiplayer game", () => TransitionToScreen("JoinMultiplayer"));
            AddButton(stackPanel, "see help", () => TransitionToScreen("Help"));

            RootElement.Content = stackPanel;
        }
コード例 #3
0
ファイル: ObjMaterial.cs プロジェクト: mdiller/EffigyMaker
        /// <summary>
        /// Writes this material and any accompanying textures to a file
        /// </summary>
        /// <param name="path">The file name to write to, without any extensions</param>
        public void WriteToFiles(string path)
        {
            var file = Path.GetFileName(path);

            var mtlText = new List <string>();

            mtlText.Add("# Exported from EffigyMaker");
            mtlText.Add("# Material count 1");
            mtlText.Add("");
            mtlText.Add($"newmtl {Name}");
            mtlText.Add($"Kd 1.000 1.000 1.000");
            mtlText.Add("Ka 1.000000 1.000000 1.000000");
            mtlText.Add("Ks 1.000000 1.000000 1.000000");
            mtlText.Add("Ni 1.450000");
            mtlText.Add("d 1.000000");
            mtlText.Add("illum 2");
            mtlText.Add($"map_Kd {file}.png");
            mtlText.Add($"map_bump {file}_Normals.png");
            //mtlText.Add($"map_Ks {file}_Specular.png"); (ignore specular for now, because its a bit bugged)

            File.WriteAllText(path + ".mtl", string.Join("\n", mtlText));

            File.WriteAllBytes(path + ".png", TextureImage.Encode(SKEncodedImageFormat.Png, 100).ToArray());
            File.WriteAllBytes(path + "_Normals.png", NormalsImage.Encode(SKEncodedImageFormat.Png, 100).ToArray());
            //File.WriteAllBytes(path + "_Specular.png", SpecularImage.Encode(SKEncodedImageFormat.Png, 100).ToArray());
        }
コード例 #4
0
        public void DrawScaledImage(TextureImage tex, float x, float y, float scaleX, float scaleY)
        {
            Vector2 origin = new Vector2(0.5f * tex.GetWidth(), 0.5f * tex.GetHeight());
            Vector2 scale  = new Vector2(scaleX, scaleY);

            GetSpriteBatch(BatchMode.Sprite).Draw(tex.GetTexture(), new Vector2(x, y), null, drawColor, 0.0f, origin, scale, SpriteEffects.None, 0.0f);
        }
コード例 #5
0
 AChild()
 {
     if (!TextureImage.ContainsKey(typeof(AChild)))
     {
         TextureImage.Add(typeof(AChild), LoadTexture(PathToImageA));
     }
 }
コード例 #6
0
        public Card(TextureImage faceDownImage, TextureImage faceUpImage)
        {
            this.faceDownImage = faceDownImage;
            this.faceUpImage   = faceUpImage;

            this.CardImage = this.faceDownImage;
        }
コード例 #7
0
ファイル: Textures.cs プロジェクト: mainblade/OpentK3D
        public void Load()
        {
            if (TextureImage == null)
            {
                return;
            }

            int        myTextureHandle = 0;
            BitmapData bitmapData      = TextureImage.LockBits(new Rectangle(0, 0, TextureImage.Width, TextureImage.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.GenTextures(1, out myTextureHandle);
            GL.BindTexture(TextureTarget.Texture2D, myTextureHandle);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, TextureImage.Width, TextureImage.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);

            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);


            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.NearestMipmapLinear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode);

            GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, (float)16.0);
            GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, (float)16.0);

            MyTextureHandle = myTextureHandle;
            TextureImage.UnlockBits(bitmapData);
        }
コード例 #8
0
        private void DrawCellImage(Context context, FieldCell cell, TextureImage image)
        {
            float drawX = cell.GetPx() - 0.5f * image.GetWidth();
            float drawY = cell.GetPy() - 0.5f * image.GetHeight();

            context.DrawImage(image, drawX, drawY);
        }
コード例 #9
0
        public static TextureImage createImage(Bitmap bitmap)
        {
            TextureImage image = new TextureImage(bitmap);

            imgs.Add(image);
            return(image);
        }
コード例 #10
0
 public override void LoadContent(ContentManager content)
 {
     base.LoadContent(content);
       m_GameFont = Content.Load<SpriteFont>("GameFont");
       m_Background = TextureImageManager.Instance.GetTextureImage("Images//background");
       m_GameOverImage = TextureImageManager.Instance.GetTextureImage("Images//GameOver");
 }
コード例 #11
0
ファイル: NeHeLesson29.cs プロジェクト: lvendrame/p-atack
        /// <summary>
        /// Reads a .RAW file in to the allocated image buffer using data in the image structure.  Flips the image top to bottom.
        /// </summary>
        /// <param name="filename">The filename to load.</param>
        /// <param name="buffer">The TextureImage to save it to.</param>
        private void ReadTextureData(string filename, ref TextureImage buffer)
        {
            int i, j, k, offset;                                                                        // Generic Loop Variables
            int stride = buffer.width * buffer.format;                                                  // Size Of A Row (Width * Bytes Per Pixel)

            byte[ , ] p = new byte[buffer.height, (buffer.width * buffer.format)];                      // The Pixel Data
            FileStream    stream   = null;                                                              // Our Stream
            ASCIIEncoding encoding = new ASCIIEncoding();                                               // Our Encoding
            BinaryReader  reader   = null;                                                              // Our Reader

            try {
                // Open The File
                stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                reader = new BinaryReader(stream, encoding);

                // Read Data Into Multi-Dimensional Array
                for (i = 0; i < buffer.height; i++)                                                                                     // Loop Through The Height
                {
                    offset = 0;                                                                                                         // Reset The Offset
                    for (j = 0; j < buffer.width; j++)                                                                                  // Loop Through The Width
                    {
                        for (k = 0; k < buffer.format - 1; k++)                                                                         // Loop Through Format
                        {
                            p[i, j + k + offset] = reader.ReadByte();                                                                   // Read A Byte
                        }
                        p[i, j + k + offset] = 255;                                                                                     // Add An Alpha Value
                        offset += buffer.format - 1;                                                                                    // Calculate New Offset
                    }
                }

                // Flip Bottom To Top And Put Back Into Single-Dimensional data Array
                int arrayposition = 0;
                for (i = buffer.height - 1; i >= 0; i--)                                                                                // Loop Through Height Starting At The Bottom
                {
                    for (j = 0; j < stride; j++)                                                                                        // Loop Through Width & Format (Stride)
                    {
                        buffer.data[arrayposition] = p[i, j];                                                                           // Stick It In The Top Of The data Array (Now It's Flipped)
                        arrayposition++;                                                                                                // Increment Array Position
                    }
                }
            }
            catch (Exception e) {
                // Handle Any Exceptions While Loading Textures, Exit App
                string errorMsg = "An Error Occurred While Loading RAW Texture:\n\t" + filename + "\n" + "\n\nStack Trace:\n\t" + e.StackTrace + "\n";
                MessageBox.Show(errorMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                App.Terminate();
            }
            finally {
                if (reader != null)
                {
                    reader.Close();                                                                                                                             // Close The File
                }
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Draws an image.
        /// </summary>
        /// <param name="image">An <see cref="TextureImage"/> that represents the image to draw.</param>
        /// <param name="position">The position at which to draw the image.</param>
        /// <param name="width">The width of the image in pixels.</param>
        /// <param name="height">The height of the image in pixels.</param>
        /// <param name="color">The image's color.</param>
        public void DrawImage(TextureImage image, Vector2 position, Single width, Single height, Color color)
        {
            if (SpriteBatch == null)
            {
                throw new InvalidOperationException(PresentationStrings.DrawingContextDoesNotHaveSpriteBatch);
            }

            SpriteBatch.DrawImage(image, position, width, height, color * Opacity);
        }
コード例 #13
0
        private void DrawPlayer(Context context, Player player)
        {
            TextureImage image = TempFindPlayerImage(player);
            float        drawX = player.GetPx() - 0.5f * cellWidth;
            float        drawY = player.GetPy() - 0.5f * cellHeight;

            if (CVars.g_drawPlayerCell.boolValue)
            {
                context.DrawRect(player.GetCx() * cellWidth, player.GetCy() * cellHeight, cellWidth, cellHeight, Color.White);
            }

            if (CVars.g_drawPlayerMovable.boolValue)
            {
                context.DrawRect(drawX, drawY, cellWidth, cellHeight, Color.Yellow);
            }

            if (player.IsInfected())
            {
                if (blink)
                {
                    AnimationInstance anim = player.currentAnimation;
                    anim.Draw(context, drawX + 0.5f * cellWidth, drawY + cellHeight);
                }
            }
            else
            {
                AnimationInstance anim = player.currentAnimation;
                anim.Draw(context, drawX + 0.5f * cellWidth, drawY + cellHeight);
            }

            if (CVars.g_drawPlayerStepRect.boolValue)
            {
                int stepX = Math.Sign(player.px - player.CellCenterPx());
                int stepY = Math.Sign(player.py - player.CellCenterPy());

                bool hasStepX = stepX != 0;
                bool hasStepY = stepY != 0;

                int cx = player.GetCx();
                int cy = player.GetCy();

                if (hasStepX && hasStepY)
                {
                    DrawCellRect(context, cx + stepX, cy, Color.Yellow);
                    DrawCellRect(context, cx, cy + stepY, Color.Yellow);
                    DrawCellRect(context, cx + stepX, cy + stepY, Color.Yellow);
                }
                else if (hasStepX)
                {
                    DrawCellRect(context, cx + stepX, cy, Color.Yellow);
                }
                else if (hasStepY)
                {
                    DrawCellRect(context, cx, cy + stepY, Color.Yellow);
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Draws an image.
        /// </summary>
        /// <param name="image">An <see cref="TextureImage"/> that represents the image to draw.</param>
        /// <param name="position">The position at which to draw the image.</param>
        /// <param name="width">The width of the image in pixels.</param>
        /// <param name="height">The height of the image in pixels.</param>
        /// <param name="color">The image's color.</param>
        /// <param name="rotation">The image's rotation in radians.</param>
        /// <param name="origin">The image's point of origin.</param>
        /// <param name="effects">The image's rendering effects.</param>
        /// <param name="layerDepth">The image's layer depth.</param>
        public void DrawImage(TextureImage image, Vector2 position, Single width, Single height, Color color, Single rotation, Vector2 origin, SpriteEffects effects, Single layerDepth)
        {
            if (SpriteBatch == null)
            {
                throw new InvalidOperationException(PresentationStrings.DrawingContextDoesNotHaveSpriteBatch);
            }

            SpriteBatch.DrawImage(image, position, width, height, color * Opacity, rotation, origin, effects, layerDepth);
        }
コード例 #15
0
        public Card(TextureImage faceDownImage, TextureImage faceUpImage)
        {
            this.faceDownImage = faceDownImage;
            this.faceUpImage   = faceUpImage;

            this.isCardFaceUp.Subscribe(this.OnIsCardFaceUpChanged);

            this.cardImage.OnNext(this.faceDownImage);
            this.isCardFaceUp.OnNext(false);
        }
コード例 #16
0
ファイル: NeHeLesson29.cs プロジェクト: lvendrame/p-atack
        /// <summary>
        /// Build the OpenGL texture.
        /// </summary>
        /// <param name="tex">The TextureImage to create texture from.</param>
        private void BuildTexture(TextureImage tex)
        {
            glGenTextures(1, texture);                                                                                                                  // Generate 1 Texture

            // Create Linear Filtered Texture
            glBindTexture(GL_TEXTURE_2D, texture[0]);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            gluBuild2DMipmaps(GL_TEXTURE_2D, (int)GL_RGB8, tex.width, tex.height, GL_RGBA, GL_UNSIGNED_BYTE, tex.data);
        }
コード例 #17
0
        public void DrawImage(TextureImage tex, ref Rectangle src, ref Vector2 position, ref Color color, float rotation, ref Vector2 origin, ref Vector2 scale, ref Vector2 flip)
        {
            SpriteEffects flipEffects = flip.X == 1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;

            if (flip.Y == 1)
            {
                flipEffects |= SpriteEffects.FlipVertically;
            }

            GetSpriteBatch(BatchMode.Sprite).Draw(tex.GetTexture(), position, src, color, rotation, origin, scale, flipEffects, 0.0f);
        }
コード例 #18
0
 public void rebindTexture()
 {
     if (GraphicsContext.CurrentContext == null)
     {
         return;
     }
     if (imageTextured == null)
     {
         imageTextured = new TextureImage((Bitmap)image);
     }
     else
     {
         imageTextured.rebindBitmap((Bitmap)image);
     }
 }
コード例 #19
0
        private void DrawPowerup(Context context, PowerupCell powerupCell)
        {
            int powerup = powerupCell.powerup;

            if (powerup != Powerups.None)
            {
                if (powerup == Powerups.Random)
                {
                    powerup = ((int)(powerupCell.elasped / 0.05f)) % powerupImages.Length;
                }

                TextureImage image = powerupImages[powerup];
                DrawCellImage(context, powerupCell, image);
            }
        }
コード例 #20
0
        private void DrawBrick(Context context, BrickCell cell)
        {
            DrawCellImage(context, cell, breakableImage);

            if (CVars.g_drawHiddenPowerups.boolValue)
            {
                int powerup = cell.powerup;
                if (powerup != Powerups.None)
                {
                    TextureImage powerupImage = powerupImages[powerup];
                    float        drawX        = cell.GetPx() - 0.5f * powerupImage.GetWidth();
                    float        drawY        = cell.GetPy() - 0.5f * powerupImage.GetHeight();
                    context.DrawImage(powerupImage, drawX, drawY, 0.25f);
                }
            }
        }
コード例 #21
0
        public PowerupView(TextureImage tex, int count)
            : base(tex.GetWidth(), tex.GetHeight())
        {
            ImageView view = new ImageView(tex);

            AddView(view);

            m_countTextView           = new TextView(Helper.fontSystem, "");
            m_countTextView.backColor = Color.Black;
            AddView(m_countTextView);

            m_dimmingView = new RectView(0, 0, width, height, new Color(0, 0, 0, 0.5f), Color.Black);
            AddView(m_dimmingView);

            SetCount(count);
        }
コード例 #22
0
ファイル: NeHeLesson29.cs プロジェクト: lvendrame/p-atack
        // --- Basecode Methods ---
        #region Initialize()
        /// <summary>
        /// Overrides OpenGL's initialization.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();                                                                                  // Run The Base Initialization
            glEnable(GL_TEXTURE_2D);                                                                            // Enable Texture Mapping
            glDepthFunc(GL_LESS);                                                                               // The Type Of Depth Test To Do

            t1 = AllocateTextureBuffer(256, 256, 4);                                                            // Get An Image Structure
            ReadTextureData(@"..\..\data\NeHeLesson29\Monitor.raw", ref t1);                                    // Read In The Texture

            t2 = AllocateTextureBuffer(256, 256, 4);                                                            // Second Image Structure
            ReadTextureData(@"..\..\data\NeHeLesson29\GL.raw", ref t2);                                         // Read In The Texture

            Blit(t2, ref t1, 127, 127, 128, 128, 64, 64, true, 127);                                            // Call The Blitter Routine

            BuildTexture(t1);                                                                                   // Load The Texture Map Into Texture Memory
        }
コード例 #23
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     if (TextureImage != null)
     {
         er.Write((uint)4);
     }
     else
     {
         er.Write((uint)0);
     }
     if (TextureImage != null)
     {
         TextureImage.Write(er, c);
     }
 }
コード例 #24
0
        private void DrawBomb(Context context, Bomb bomb)
        {
            float drawX = bomb.GetPx();
            float drawY = bomb.GetPy();

            AnimationInstance anim = bomb.currentAnimation;

            anim.Draw(context, drawX, drawY + 0.5f * cellHeight, bomb.IsBlocked ? Color.Red : Color.White);

            if (CVars.g_drawBombDir.boolValue)
            {
                TextureImage dirImage = dirLookup[bomb.direction];
                context.DrawImage(dirImage, drawX - 0.5f * dirImage.GetWidth(), drawY - 0.5f * dirImage.GetHeight());
            }

            context.DrawRect(bomb.cx * cellWidth, bomb.cy * cellHeight, cellWidth, cellHeight, Color.White);
            context.DrawRect(bomb.px - 0.5f * cellWidth, bomb.py - 0.5f * cellHeight, cellWidth, cellHeight, Color.Red);
        }
コード例 #25
0
        private void DrawAnim(Context context, AnimationInstance instance, int x, int y)
        {
            int          frameIndex = instance.FrameIndex;
            TextureImage texture    = instance.Texture;

            Animation group = instance.Animation;

            Rectangle src;
            int       ox = group.frames[frameIndex].ox;
            int       oy = group.frames[frameIndex].oy;

            src.X      = group.frames[frameIndex].x;
            src.Y      = group.frames[frameIndex].y;
            src.Width  = group.frames[frameIndex].w;
            src.Height = group.frames[frameIndex].h;

            context.DrawImagePart(texture, src, x - ox, y - oy);
        }
コード例 #26
0
 private void ReadTexturesFromNode(XmlNode node)
 {
     if (node == null)
     {
         return;
     }
     foreach (XmlNode childNode in node.ChildNodes)
     {
         if (childNode.LocalName != "texture")
         {
             continue;
         }
         TextureImage newTexture = new TextureImage();
         newTexture.id   = uint.Parse(childNode.Attributes[IDATTR_NAME].Value);
         newTexture.name = SafeGetNodeValue(FindFirstChildNode(childNode, NAMENODE_NAME), MISSING_STR);
         backgrounds.Add(newTexture.id, newTexture);
     }
 }
コード例 #27
0
        private void TempInitImages()
        {
            playerImages = new Dictionary <Direction, TextureImage>();
            playerImages.Add(Direction.DOWN, Helper.GetTexture(A.gfx_wlks0001));
            playerImages.Add(Direction.UP, Helper.GetTexture(A.gfx_wlkn0001));
            playerImages.Add(Direction.LEFT, Helper.GetTexture(A.gfx_wlkw0001));
            playerImages.Add(Direction.RIGHT, Helper.GetTexture(A.gfx_wlke0001));

            playerGrabImages = new Dictionary <Direction, TextureImage>();
            playerGrabImages.Add(Direction.DOWN, Helper.GetTexture(A.gfx_bmf0010));
            playerGrabImages.Add(Direction.UP, Helper.GetTexture(A.gfx_bmf0010));
            playerGrabImages.Add(Direction.LEFT, Helper.GetTexture(A.gfx_pul0010));
            playerGrabImages.Add(Direction.RIGHT, Helper.GetTexture(A.gfx_pur0010));

            solidImage       = Helper.GetTexture(A.gfx_f0solid);
            breakableImage   = Helper.GetTexture(A.gfx_f0brick);
            bombImage        = Helper.GetTexture(A.gfx_bmb1001);
            bombJellyImage   = Helper.GetTexture(A.gfx_bmbc1);
            bombTriggerImage = Helper.GetTexture(A.gfx_digib001);

            powerupImages = new TextureImage[]
            {
                Helper.GetTexture(A.gfx_powerups_bomb),
                Helper.GetTexture(A.gfx_powerups_flame),
                Helper.GetTexture(A.gfx_powerups_disea),
                Helper.GetTexture(A.gfx_powerups_kick),
                Helper.GetTexture(A.gfx_powerups_skate),
                Helper.GetTexture(A.gfx_powerups_punch),
                Helper.GetTexture(A.gfx_powerups_grab),
                Helper.GetTexture(A.gfx_powerups_spooge),
                Helper.GetTexture(A.gfx_powerups_gold),
                Helper.GetTexture(A.gfx_powerups_trig),
                Helper.GetTexture(A.gfx_powerups_jelly),
                Helper.GetTexture(A.gfx_powerups_ebola),
                Helper.GetTexture(A.gfx_powerups_random),
            };

            dirLookup = new Dictionary <Direction, TextureImage>();
            dirLookup[Direction.UP]    = Helper.GetTexture(A.gfx_dir_up);
            dirLookup[Direction.DOWN]  = Helper.GetTexture(A.gfx_dir_down);
            dirLookup[Direction.LEFT]  = Helper.GetTexture(A.gfx_dir_left);
            dirLookup[Direction.RIGHT] = Helper.GetTexture(A.gfx_dir_right);
        }
コード例 #28
0
        public void DrawImageTiled(TextureImage tex, ref Rectangle src, ref Rectangle dest)
        {
            // TODO: implement with texture repeat
            int destWidth  = dest.Width;
            int destHeight = dest.Height;
            int srcWidth   = src.Width;
            int srcHeight  = src.Height;
            int numTilesX  = destWidth / srcWidth + (destWidth % srcWidth != 0 ? 1 : 0);
            int numTilesY  = destHeight / srcHeight + (destHeight % srcHeight != 0 ? 1 : 0);
            int x          = dest.X;
            int y          = dest.Y;

            for (int tileY = 0; tileY < numTilesY; ++tileY)
            {
                for (int tileX = 0; tileX < numTilesX; ++tileX)
                {
                    DrawImagePart(tex, src, x, y);
                    x += srcWidth;
                }
                y += srcHeight;
            }
        }
コード例 #29
0
ファイル: Texture.cs プロジェクト: lunactic/RayTracer
        public RayTracer.Structs.Color GetColorFromTexCoordinate(Vector2 texCoord)
        {
            lock (this)
            {
                float u = texCoord.X * (Width - 1);
                float v = (1 - texCoord.Y) * (Height - 1);

                int u0 = (int)Math.Floor(u);
                int v0 = (int)Math.Floor(v);
                int u1 = (int)Math.Ceiling(u);
                int v1 = (int)Math.Ceiling(v);

                u0 = Math.Min(Math.Max(u0, 0), Width - 1);
                u1 = Math.Min(Math.Max(u1, 0), Width - 1);
                v0 = Math.Min(Math.Max(v0, 0), Height - 1);
                v1 = Math.Min(Math.Max(v1, 0), Height - 1);

                float wu = (u - u0) / (u1 - u0);
                float wv = (v - v0) / (v1 - v0);

                int r1 = (int)(TextureImage.GetPixel(u0, v0).R *(1 - wu)) + (int)(TextureImage.GetPixel(u1, v0).R *wu);
                int r2 = (int)(TextureImage.GetPixel(u0, v1).R *(1 - wu)) + (int)(TextureImage.GetPixel(u1, v1).R *wu);

                int g1 = (int)(TextureImage.GetPixel(u0, v0).G *(1 - wu)) + (int)(TextureImage.GetPixel(u1, v0).G *wu);
                int g2 = (int)(TextureImage.GetPixel(u0, v1).G *(1 - wu)) + (int)(TextureImage.GetPixel(u1, v1).G *wu);

                int b1 = (int)(TextureImage.GetPixel(u0, v0).B *(1 - wu)) + (int)(TextureImage.GetPixel(u1, v0).B *wu);
                int b2 = (int)(TextureImage.GetPixel(u0, v1).B *(1 - wu)) + (int)(TextureImage.GetPixel(u1, v1).B *wu);

                int finalR = (int)(r1 * (1 - wv) + r2 * wv);
                int finalG = (int)(g1 * (1 - wv) + g2 * wv);
                int finalB = (int)(b1 * (1 - wv) + b2 * wv);

                return(new Structs.Color(finalR / 255f, finalG / 255f, finalB / 255f));
            }
        }
コード例 #30
0
        private void DrawSpecial(Context context, Player player)
        {
            Bomb bomb = player.bombInHands;

            if (bomb != null)
            {
                TextureImage image = Helper.GetTexture(A.gfx_bmb1001);

                float drawX = player.GetPx() - 0.5f * image.GetWidth();
                float drawY = player.GetPy() - 1.5f * image.GetHeight();
                context.DrawImage(image, drawX, drawY);
            }

            List <Bomb> thrownBombs = player.thrownBombs;

            foreach (Bomb b in thrownBombs)
            {
                TextureImage image = Helper.GetTexture(A.gfx_bmb1001);

                float drawX = b.GetPx() - 0.5f * image.GetWidth();
                float drawY = b.GetPy() - 0.5f * image.GetHeight() - b.fallHeight;
                context.DrawImage(image, drawX, drawY);
            }
        }
コード例 #31
0
ファイル: TextureCube.cs プロジェクト: vetuomia/rocket
 /// <summary>
 /// Initializes the texture image.
 /// </summary>
 /// <param name="image">The texture image.</param>
 /// <param name="bitmap">The source bitmap.</param>
 /// <param name="x">The tile X coordinate.</param>
 /// <param name="y">The tile Y coordinate.</param>
 /// <param name="size">The tile size.</param>
 private void Initialize(TextureImage image, Bitmap bitmap, int x, int y, int size)
 {
     using (var tile = bitmap.Clone(x * size, y * size, size, size))
     {
         tile.PinAsReadOnly(data => image.Initialize(size, size, GL.BGRA, data));
     }
 }
コード例 #32
0
        /// <summary>
        /// Draws an image.
        /// </summary>
        /// <param name="image">An <see cref="TextureImage"/> that represents the image to draw.</param>
        /// <param name="position">The position at which to draw the image.</param>
        /// <param name="width">The width of the image in pixels.</param>
        /// <param name="height">The height of the image in pixels.</param>
        /// <param name="color">The image's color.</param>
        /// <param name="rotation">The image's rotation in radians.</param>
        /// <param name="origin">The image's point of origin.</param>
        /// <param name="effects">The image's rendering effects.</param>
        /// <param name="layerDepth">The image's layer depth.</param>
        public void DrawImage(TextureImage image, Vector2 position, Single width, Single height, Color color, Single rotation, Vector2 origin, SpriteEffects effects, Single layerDepth)
        {
            if (SpriteBatch == null)
                throw new InvalidOperationException(PresentationStrings.DrawingContextDoesNotHaveSpriteBatch);

            SpriteBatch.DrawImage(image, position, width, height, color * Opacity, rotation, origin, effects, layerDepth);
        }
コード例 #33
0
ファイル: MyComponent.cs プロジェクト: Xbox-dev/XPF
        protected override void LoadContent()
        {
            var spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice));
            var spriteFontAdapter  = new SpriteFontAdapter(this.Game.Content.Load <SpriteFont>("SpriteFont"));
            var renderer           = new Renderer(spriteBatchAdapter, new PrimitivesService(this.GraphicsDevice));

            this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager());

            // Setup Layout
            var cardImage = new Image
            {
                Stretch = Stretch.None
            };

            var cardToggleButton = new ToggleButton
            {
                Content = cardImage,
                Margin  = new Thickness(10)
            };

            var resetButton = new Button
            {
                Content =
                    new Border
                {
                    Background = new SolidColorBrush(Colors.LightGray),
                    Child      = new TextBlock(spriteFontAdapter)
                    {
                        Text   = "Reset",
                        Margin = new Thickness(10)
                    }
                },
                Margin = new Thickness(10),
                HorizontalAlignment = HorizontalAlignment.Center
            };

            var stackPanel = new StackPanel
            {
                Children =
                {
                    cardToggleButton,
                    resetButton
                }
            };

            this.rootElement.Content = stackPanel;

            // Setup Data Binding
            var faceDownImage = new TextureImage(new Texture2DAdapter(this.Game.Content.Load <Texture2D>("FaceDown")));
            var faceUpImage   = new TextureImage(new Texture2DAdapter(this.Game.Content.Load <Texture2D>("FaceUp")));

            var card = new Card(faceDownImage, faceUpImage);

            cardImage.Bind(
                Image.SourceProperty,
                BindingFactory.CreateOneWay <Card, ImageSource>(card, d => d.CardImage));

            cardToggleButton.Bind(
                ToggleButton.IsCheckedProperty,
                BindingFactory.CreateTwoWay(card, d => d.IsCardFaceUp));

            resetButton.Click += (sender, args) => card.Reset();
        }
コード例 #34
0
        /// <summary>
        /// Draws an image.
        /// </summary>
        /// <param name="image">An <see cref="TextureImage"/> that represents the image to draw.</param>
        /// <param name="position">The position at which to draw the image.</param>
        /// <param name="width">The width of the image in pixels.</param>
        /// <param name="height">The height of the image in pixels.</param>
        /// <param name="color">The image's color.</param>
        public void DrawImage(TextureImage image, Vector2 position, Single width, Single height, Color color)
        {
            if (SpriteBatch == null)
                throw new InvalidOperationException(PresentationStrings.DrawingContextDoesNotHaveSpriteBatch);

            SpriteBatch.DrawImage(image, position, width, height, color * Opacity);
        }