Beispiel #1
0
        /// <summary>
        /// See BlWindow3D for details.
        /// </summary>
        protected override void Setup()
        {
            // Any type of content (3D models, fonts, images, etc.) can be converted to an XNB file by downloading and
            // using the mgcb-editor (see Blotch3D.chm for details). XNB files are then normally added to the project
            // and loaded as shown here. 'Content', here, is the folder that contains the XNB files or subfolders with
            // XNB files. We need to create one ContentManager object for each top-level content folder we'll be loading
            // XNB files from. You can create multiple content managers if content is spread over diverse folders. Some
            // content can also be loaded in its native format using platform specific code (may not be portable) or
            // certain Blotch3D/Monogame methods, like BlGraphicsDeviceManager.LoadFromImageFile.
            var MyContent = new ContentManager(Services, "Content");

            // The font we will use to draw the menu on the screen.
            // "Arial14" is the pathname to the font file
            Font = MyContent.Load <SpriteFont>("Arial14");

            // The model of the toroid
            var TorusModel = MyContent.Load <Model>("torus");

            // The sprite we draw in this window
            Torus = new BlSprite(Graphics, "Torus");

            // We use a custom effect rather than the default effect
            BlBasicEffectAlphaTest = new BlBasicEffect(Graphics.GraphicsDevice, "BlBasicEffectAlphaTestOGL.mgfxo");
            BlBasicEffectAlphaTest.Parameters["AlphaTestThreshold"].SetValue(.5f);

            // See Blotch3D documentation for details on translucency
            Torus.SetEffect = (s, effect) =>
            {
                s.SetupBasicEffect(BlBasicEffectAlphaTest);

                return(BlBasicEffectAlphaTest);
            };

            Torus.LODs.Add(TorusModel);

            // Load the image into a Texture2D
            MyTexture = Graphics.LoadFromImageFile("Content/image_with_alpha.png");

            // Set the sprite's mipmap
            // NOTE: The texture mapping is up to the model designer, because
            // the texture coordinates for each vertex are embedded in the model file.
            Torus.Mipmap = new BlMipmap(Graphics, MyTexture);
        }
Beispiel #2
0
        /// <summary>
        /// See BlWindow3D for details.
        /// </summary>
        protected override void Setup()
        {
            // We need to create one ContentManager object for each top-level content folder we'll be
            // loading things from. Here "Content" is the most senior folder name of the content tree.
            // (Content [models, fonts, etc.] are added to the project with the Content utility. Double-click
            // 'Content.mgcb' in solution explorer.). You can create multiple content managers if content
            // is spread of diverse folders.
            var MyContent = new ContentManager(Services, "Content");

            // The font we will use to draw the menu on the screen.
            // "Arial14" is the pathname to the font file
            Font = MyContent.Load <SpriteFont>("Arial14");

            // The model of the toroid
            var TorusModel = MyContent.Load <Model>("torus");

            // The sprite we draw in this window
            Torus = new BlSprite(Graphics, "Torus");

            // We use a custom effect rather than the default effect
            byte[] bytes = File.ReadAllBytes("Content/BlBasicEffectAlphaTest.mgfxo");
            BlBasicEffectAlphaTest = new BlBasicEffect(Graphics.GraphicsDevice, bytes);
            BlBasicEffectAlphaTest.Parameters["AlphaTestThreshold"].SetValue(.5f);

            // See Blotch3D documentation for details on translucency
            Torus.SetEffect = (s, effect) =>
            {
                s.SetupBasicEffect(BlBasicEffectAlphaTest);

                return(BlBasicEffectAlphaTest);
            };

            Torus.LODs.Add(TorusModel);

            // Load the image into a Texture2D
            MyTexture = Graphics.LoadFromImageFile("image_with_alpha.png");

            // Set the sprite's mipmap
            // NOTE: The texture mapping is up to the model designer, because
            // the texture coordinates for each vertex are embedded in the model file.
            Torus.Mipmap = new BlMipmap(Graphics, MyTexture);
        }
Beispiel #3
0
        /// <summary>
        /// See BlWindow3D for details.
        /// </summary>
        protected override void Setup()
        {
            // We need to create one ContentManager object for each top-level content folder we'll be
            // loading things from. Here "Content" is the most senior folder name of the content tree.
            // (Content [models, fonts, etc.] are added to the project with the Content utility. Double-click
            // 'Content.mgcb' in solution explorer.). You can create multiple content managers if content
            // is spread of diverse folders.
            var MyContent = new ContentManager(Services, "Content");

            // The font we will use to draw the menu on the screen.
            // "Arial14" is the pathname to the font file
            Font = MyContent.Load <SpriteFont>("Arial14");

            // The model of the toroid
            var PlaneModel = MyContent.Load <Model>("plane");

            // The sprite we draw in this window
            Plane = new BlSprite(Graphics, "Plane");

            // We use a custom effect rather than the default effect
            BlBasicEffectXformTexture = new BlBasicEffect(Graphics.GraphicsDevice, "Content/BlBasicEffectAlphaTestXformTex.mgfxo");
            BlBasicEffectXformTexture.Parameters["AlphaTestThreshold"].SetValue(.5f);

            // Set the delegate
            Plane.SetEffect = (s, effect) =>
            {
                // Rotate the texture.
                TexRotAngle += .0234f;

                // avoid eventual visible floating point errors
                if (TexRotAngle > Math.PI)
                {
                    TexRotAngle -= (float)(2 * Math.PI);
                }
                if (TexRotAngle < 0)
                {
                    TexRotAngle += (float)(2 * Math.PI);
                }

                // We create a 2x2 matrix by using only the first two rows and columns of a 4x4 matrix
                // to demonstrate it can be done easily. Of course, this could be done more efficiently
                // with explicit 2x2 math.
                // (Also note that we pass the four elements as a Vector4 because there is no Matrix2x2)
                var m = Matrix.CreateRotationZ(TexRotAngle);
                BlBasicEffectXformTexture.Parameters["TextureTransform"].SetValue(new Vector4(m.M11, m.M12, m.M21, m.M22));

                // Let's also change the texture offset.
                TexTrans += .01f;

                // avoid eventual visible floating point errors
                if (TexTrans > 1)
                {
                    TexTrans -= (int)TexTrans;
                }
                if (TexTrans < 0)
                {
                    TexTrans += (int)-TexTrans + 1;
                }

                BlBasicEffectXformTexture.Parameters["TextureTranslate"].SetValue(new Vector2(TexTrans, 2 * TexTrans));

                s.SetupBasicEffect(BlBasicEffectXformTexture);

                return(BlBasicEffectXformTexture);
            };

            Plane.LODs.Add(PlaneModel);

            // Load the image into a Texture2D
            MyTexture = Graphics.LoadFromImageFile("image_with_alpha.png");

            // Set the sprite's mipmap
            // NOTE: The texture mapping is up to the model designer, because
            // the texture coordinates for each vertex are embedded in the model file.
            Plane.Mipmap = new BlMipmap(Graphics, MyTexture);
        }
Beispiel #4
0
        /// <summary>
        /// See BlWindow3D for details.
        /// </summary>
        protected override void Setup()
        {
            // Any type of content (3D models, fonts, images, etc.) can be converted to an XNB file by downloading and
            // using the mgcb-editor (see Blotch3D.chm for details). XNB files are then normally added to the project
            // and loaded as shown here. 'Content', here, is the folder that contains the XNB files or subfolders with
            // XNB files. We need to create one ContentManager object for each top-level content folder we'll be loading
            // XNB files from. You can create multiple content managers if content is spread over diverse folders. Some
            // content can also be loaded in its native format using platform specific code (may not be portable) or
            // certain Blotch3D/Monogame methods, like BlGraphicsDeviceManager.LoadFromImageFile.
            var MyContent = new ContentManager(Services, "Content");

            // The font we will use to draw the menu on the screen.
            // "Arial14" is the pathname to the font file
            Font = MyContent.Load <SpriteFont>("Arial14");

            // The model of the toroid
            var PlaneModel = MyContent.Load <Model>("plane");

            // The sprite we draw in this window
            Plane = new BlSprite(Graphics, "Plane");

            // We use a custom effect rather than the default effect
            BlBasicEffectXformTexture = new BlBasicEffect(Graphics.GraphicsDevice, "BlBasicEffectAlphaTestXformTexOGL.mgfxo");
            BlBasicEffectXformTexture.Parameters["AlphaTestThreshold"].SetValue(.5f);

            // Set the delegate
            Plane.SetEffect = (s, effect) =>
            {
                // Rotate the texture.
                TexRotAngle += .0234f;

                // avoid eventual visible floating point errors
                if (TexRotAngle > Math.PI)
                {
                    TexRotAngle -= (float)(2 * Math.PI);
                }
                if (TexRotAngle < 0)
                {
                    TexRotAngle += (float)(2 * Math.PI);
                }

                // We create a 2x2 matrix by using only the first two rows and columns of a 4x4 matrix
                // to demonstrate it can be done easily. Of course, this could be done more efficiently
                // with explicit 2x2 math.
                // (Also note that we pass the four elements as a Vector4 because there is no Matrix2x2)
                var m = Matrix.CreateRotationZ(TexRotAngle);
                BlBasicEffectXformTexture.Parameters["TextureTransform"].SetValue(new Vector4(m.M11, m.M12, m.M21, m.M22));

                // Let's also change the texture offset.
                TexTrans += .01f;

                // avoid eventual visible floating point errors
                if (TexTrans > 1)
                {
                    TexTrans -= (int)TexTrans;
                }
                if (TexTrans < 0)
                {
                    TexTrans += (int)-TexTrans + 1;
                }

                BlBasicEffectXformTexture.Parameters["TextureTranslate"].SetValue(new Vector2(TexTrans, 2 * TexTrans));

                s.SetupBasicEffect(BlBasicEffectXformTexture);

                return(BlBasicEffectXformTexture);
            };

            Plane.LODs.Add(PlaneModel);

            // Load the image into a Texture2D
            MyTexture = Graphics.LoadFromImageFile("Content/image_with_alpha.png");

            // Set the sprite's mipmap
            // NOTE: The texture mapping is up to the model designer, because
            // the texture coordinates for each vertex are embedded in the model file.
            Plane.Mipmap = new BlMipmap(Graphics, MyTexture);
        }