Ejemplo n.º 1
0
        public static ClearStencilNode Create()
        {
            var model   = new ClearStencilModel();
            var vs      = new VertexShader(vertexCode);
            var fs      = new FragmentShader(fragmentCode);
            var array   = new ShaderArray(vs, fs);
            var map     = new AttributeMap();
            var builder = new RenderMethodBuilder(array, map);
            var node    = new ClearStencilNode(model, builder);

            node.Initialize();

            return(node);
        }
Ejemplo n.º 2
0
        private SceneNodeBase GetRootElement()
        {
            // demo 1:
            //return StencilTestNode.Create();

            // demo 2:
            //var quaterNode = QuaterNode.Create();
            //var bottleNode = KleinBottleNode.Create(new KleinBottleModel());
            //bottleNode.Scale = new vec3(1, 1, 1) * 0.1f;
            //var group = new HowStencilTestWorkNode();
            //group.Children.Add(quaterNode);
            //group.Children.Add(bottleNode);
            //return group;

            // demo 3:
            var    clearStencilNode = ClearStencilNode.Create(); // this helps clear stencil buffer because glClear(GL_STENCIL_BUFFER_BIT); doesn't work.
            string folder           = System.Windows.Forms.Application.StartupPath;
            var    bitmap           = new Bitmap(System.IO.Path.Combine(folder, @"Lenna.png"));

            bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
            var texture = new Texture(new TexImageBitmap(bitmap));

            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapS, (int)GL.GL_REPEAT));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapT, (int)GL.GL_REPEAT));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureWrapR, (int)GL.GL_REPEAT));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMinFilter, (int)GL.GL_LINEAR));
            texture.BuiltInSampler.Add(new TexParameteri(TexParameter.PropertyName.TextureMagFilter, (int)GL.GL_LINEAR));
            texture.Initialize();
            bitmap.Dispose();

            var group = new GroupNode(clearStencilNode);

            for (int x = 0; x < 3; x++)
            {
                for (int z = 0; z < 3; z++)
                {
                    var outlineCubeNode = OutlineCubeNode.Create(texture);
                    outlineCubeNode.Scale         = new vec3(1, 1, 1) * 0.6f;
                    outlineCubeNode.WorldPosition = new vec3(x - 1, 0, z - 1);
                    group.Children.Add(outlineCubeNode);
                }
            }
            return(group);
        }