Click here to Skip to main content
15,896,453 members
Articles / Desktop Programming / WPF

Anaglyph ShaderEffect in WPF

Rate me:
Please Sign up or sign in to vote.
4.96/5 (62 votes)
8 Nov 2009CPOL5 min read 111.2K   3.1K   108  
This article shows how to use a WPF ShaderEffect for anaglyph blending (for red/cyan glasses). The effect can be used for both 2D and 3D elements.
///////////////////////////////////////////////////////////////////////////////
// CapHelper v1.1
//
// This software is released into the public domain.  You are free to use it
// in any way you like, except that you may not sell this source code.
//
// This software is provided "as is" with no expressed or implied warranty.
// I accept no liability for any damage or loss of business that this software
// may cause.
// 
// This source code is originally written by Tamir Khason (see http://blogs.microsoft.co.il/blogs/tamir
// or http://www.codeplex.com/wpfcap).
// 
// Modifications are made by Geert van Horrik (CatenaLogic, see http://blog.catenalogic.com) 
//
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CatenaLogic.Windows.Presentation.WebcamPlayer
{
    /// <summary>
    /// Class that helps finding the pins for a specific filter
    /// </summary>
    internal static class CapHelper
    {
        /// <summary>
        /// Gets a specific pin of a specific filter
        /// </summary>
        /// <param name="filter">Filter to retrieve the pin for (defines which object should make this method available)</param>
        /// <param name="dir">Direction</param>
        /// <param name="num">Number</param>
        /// <returns>IPin object or null</returns>
        public static IPin GetPin(this IBaseFilter filter, PinDirection dir, int num)
        {
            // Declare variables
            IPin[] pin = new IPin[1];
            IEnumPins pinsEnum = null;

            // Enumerator the pins
            if (filter.EnumPins(out pinsEnum) == 0)
            {
                // Get the pin direction
                PinDirection pinDir;
                int n = 0; ;

                // Loop the pins
                while (pinsEnum.Next(1, pin, out n) == 0)
                {
                    // Query the direction
                    pin[0].QueryDirection(out pinDir);

                    // Is the pin direction correct?
                    if (pinDir == dir)
                    {
                        // Yes, check the pins
                        if (num == 0)
                        {
                            return pin[0];
                        }
                        num--;
                    }

                    // Release the pin, this is not the one we are looking for
                    Marshal.ReleaseComObject(pin[0]);
                    pin[0] = null;
                }
            }

            // Not found
            return null;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions