Пример #1
0
        /// <summary>
        /// Load contents
        /// </summary>
        public override void LoadContent()
        {
            Display.RenderState.ClearColor = Color.CornflowerBlue;

            SpriteBatch = new Graphic.SpriteBatch();
            Font        = BitmapFont.CreateFromTTF(@"c:\windows\fonts\verdana.ttf", 16, FontStyle.Regular);

            Gamepad.Init(Window);
            CheckDevices();
        }
Пример #2
0
        /// <summary>
        /// Load contents
        /// </summary>
        public override void LoadContent()
        {
            Display.RenderState.ClearColor = Color.Black;
            Display.RenderState.DepthTest  = true;
            Display.RenderState.Culling    = true;


            #region Audio

            AudioManager.Create();
            Stream = new AudioStream();
            Stream.LoadOgg("data/Hydrate-Kenny_Beltrey.ogg");
            Stream.Play();

            #endregion


            #region Matrices

            CameraPostion = new Vector3(0.0f, 0.1f, 3.0f);

            float aspectRatio = (float)Display.ViewPort.Width / (float)Display.ViewPort.Height;
            ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45.0f), aspectRatio, 0.1f, 100.0f);

            #endregion


            #region Shader

            Shader = new Shader();
            Shader.LoadSource(ShaderType.VertexShader, "data/shader.vert");
            Shader.LoadSource(ShaderType.FragmentShader, "data/shader.frag");
            Shader.Compile();
            Display.Shader = Shader;

            #endregion


            #region Textures

            Texture2D.DefaultMagFilter            = TextureMagFilter.Linear;
            Texture2D.DefaultMinFilter            = TextureMinFilter.Linear;
            Texture2D.DefaultHorizontalWrapFilter = TextureWrapFilter.Repeat;
            Texture2D.DefaultVerticalWrapFilter   = TextureWrapFilter.Repeat;

            Marble                = new Texture2D("data/Marble.png");
            Marble.MinFilter      = TextureMinFilter.Linear;
            Marble.MagFilter      = TextureMagFilter.Linear;
            Marble.HorizontalWrap = TextureWrapFilter.Repeat;
            Marble.VerticalWrap   = TextureWrapFilter.Repeat;

            Moon           = new Texture2D("data/Moon.png");
            Moon.MinFilter = TextureMinFilter.Linear;
            Moon.MagFilter = TextureMagFilter.Linear;

            Mars           = new Texture2D("data/Mars.png");
            Mars.MinFilter = TextureMinFilter.Linear;
            Mars.MagFilter = TextureMagFilter.Linear;

            #endregion


            #region Mesh
            Torus = Mesh.CreateTorus(0.15f, 0.50f, 40, 20);

            Sphere          = Mesh.CreateSphere(0.1f, 26);
            Sphere.Position = new Vector3(1.0f, 0.4f, 0.0f);

            float[] data = new float[]
            {
                // Vertex					Texture
                -10.0f, 0.0f, 20.0f, 0.0f, 0.0f,
                10.0f, 0.0f, 20.0f, 20.0f, 0.0f,
                10.0f, 0.0f, -20.0f, 20.0f, 20.0f,
                -10.0f, 0.0f, -20.0f, 0.0f, 20.0f,
            };
            Floor = new Mesh();
            Floor.SetVertices(data);
            Floor.SetIndices(new uint[] { 0, 1, 2, 3 });
            Floor.Buffer.AddDeclaration("in_position", 3);
            Floor.Buffer.AddDeclaration("in_texcoord", 2);
            Floor.PrimitiveType = PrimitiveType.TriangleFan;
            Floor.Position      = new Vector3(0.0f, -1.0f, 0.0f);

            #endregion


            Batch = new Graphic.SpriteBatch();
            Font  = BitmapFont.CreateFromTTF(@"c:\windows\fonts\verdana.ttf", 10, FontStyle.Regular);
        }
Пример #3
0
        /// <summary>
        /// Loads contents
        /// </summary>
        public override void LoadContent()
        {
            Display.RenderState.ClearColor = Color.CornflowerBlue;



            // Shader
            Shader         = Shader.CreateTextureShader();
            Display.Shader = Shader;


            #region Texture

            // Loads a texture and binds it to TUI 2
            Texture = new Texture2D("data/texture.png");
            Texture.HorizontalWrap = TextureWrapFilter.Repeat;
            Texture.VerticalWrap   = TextureWrapFilter.Repeat;
            Display.TextureUnit    = 2;
            Display.Texture        = Texture;

            #endregion

            // Matrices
            ModelViewMatrix  = Matrix4.LookAt(new Vector3(0, 0, 1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));;
            ProjectionMatrix = Matrix4.CreateOrthographicOffCenter(0, Display.ViewPort.Width, Display.ViewPort.Height, 0, -1.0f, 1.0f);
            TextureMatrix    = Matrix4.Scale(1.0f / Texture.Size.Width, 1.0f / Texture.Size.Height, 1.0f);

            #region Buffer


            // Indices
            uint[] indices = new uint[]
            {
                0, 1, 2,
                1, 2, 3
            };

            Index = new IndexBuffer();
            Index.Update(indices);


            // Creates a position, color, texture buffer
            Buffer = BatchBuffer.CreatePositionColorTextureBuffer();


            // Vertex elements
            float[] vertices = new float[]
            {
                // Coord						Color							Texture
                100.0f, 100.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                500.0f, 100.0f, 0.0f, 1.0f, 0.0f, 1.0f, 256.0f, 0.0f,
                100.0f, 500.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 256.0f,
                500.0f, 500.0f, 1.0f, 1.0f, 1.0f, 1.0f, 256.0f, 256.0f
            };
            Buffer.SetVertices(vertices);


            // Or set data one by one
            Buffer.AddPoint(new Point(100, 100), Color.FromArgb(255, 0, 0), new Point(0, 0));
            Buffer.AddPoint(new Point(500, 100), Color.FromArgb(0, 255, 0), new Point(256, 0));
            Buffer.AddPoint(new Point(100, 500), Color.FromArgb(0, 0, 255), new Point(0, 256));
            Buffer.AddPoint(new Point(500, 500), Color.FromArgb(255, 255, 255), new Point(256, 256));
            Buffer.Update();


            #region VAO

            //Batch = new BatchBuffer();


            //VertexBuffer.Bind(0, 2);
            //Shader.BindAttrib(0, "in_position");

            //ColorBuffer.Bind(1, 4);
            //Shader.BindAttrib(1, "in_color");


            //GL.BindVertexArray(0);

            #endregion

            #endregion


            #region Font

            SpriteBatch = new Graphic.SpriteBatch();
            Font        = BitmapFont.CreateFromTTF("c:\\windows\\fonts\\verdana.ttf", 16, FontStyle.Regular);

            #endregion
        }