示例#1
0
 /// <summary>
 /// Draws the MenuView and all its subcomponents.
 /// </summary>
 /// <param name="viewport">The used Viewport.</param>
 /// <param name="spriteBatch">The used SpriteBatch.</param>
 public void Draw(Viewport viewport, SpriteBatch spriteBatch)
 {
     foreach (MenuDialogView menuDialogView in this.menuDialogViews)
     {
         menuDialogView.Draw(viewport, spriteBatch);
     }
 }
示例#2
0
 public void Update(GameTime gameTime, Viewport view, float Health, float MaxHealth, int score)
 {
     _view = view;
     _health = Health;
     _maxHealth = MaxHealth;
     _score = score;
 }
        public GraphicsDevice(DrawQueue drawQueue)
        {
            // TODO: Complete member initialization
            this.drawQueue = drawQueue;

            viewport = new Viewport(0,0,UnityEngine.Screen.width, UnityEngine.Screen.height);
        }
        public void LoadContent(SpriteBatch spriteBatch, ContentManager Content, Viewport viewport, 
            Camera camera, Texture2D enemyTexture, GraphicsDeviceManager graphics, 
            SoundEffect _backgroundMusic, GameController _gameController, 
            SoundEffect _fireballSound, SpriteFont _spritefont, Texture2D _bossTexture)
        {
            _enemyTexture = enemyTexture;
            this.camera = camera;
            _graphics = graphics;

            spritefont = _spritefont;

            bossTexture = _bossTexture;

            backgroundMusic = _backgroundMusic;
            fireballSound = _fireballSound;

            _content = Content;
            gameController = _gameController;
            character = Content.Load<Texture2D>("imp");
            Flame.SetTexture(Content.Load<Texture2D>("Flames"));
            
            soundEffectInstance = backgroundMusic.CreateInstance();

            onFirstLevel = false;
            onSecondLevel = false;
            onThirdLevel = false;
            onFourthLevel = false;

        }
示例#5
0
 /// <summary>
 /// Constructs a camera object.
 /// </summary>
 /// <param name="viewport">Current viewport for the game</param>
 public Camera(Viewport viewport)
 {
     mPosition = new Vector3(300.0f, 200.0f, 0.0f);
     mZoom = 0.75f;
     mHeight = viewport.Height;
     mWidth = viewport.Width;
 }
示例#6
0
        public TreeController(Viewport vp, ContentManager content)
        {
            Trees = new List<Tree>();

            baseTreeTxtr = content.Load<Texture2D>(@"Tree/Base");
            sides[0] = content.Load<Texture2D>(@"Tree/LogLeft");
            sides[1] = content.Load<Texture2D>(@"Tree/LogRight");
            sides[2] = content.Load<Texture2D>(@"Tree/LogNEU");

            viewport = vp;
            float xSize = viewport.Width * 0.5f;
            size = new Vector2(xSize, xSize * 0.7407f);
            StandardX = Convert.ToInt32(viewport.Width / 2);

            DownRate = size.Y;
            float sizeX = viewport.Width * 0.25f;

            Vector2 baseSize = new Vector2(sizeX, sizeX * 0.1125f);
            Vector2 baseLocation = new Vector2(StandardX, viewport.Height - (baseSize.Y * 7));
            Tree baseLog = new Tree(baseLocation, baseSize, baseTreeTxtr);

            locations[0] = xSize / 4;
            locations[1] = StandardX - (xSize / 4);
            Trees.Add(baseLog);

            for (int i = 1; i < 12; i++)
            {
                Tree prevT = Trees[i - 1];
                Tree t = new Tree(new Vector2(locations[i % 2], prevT.location.Y - size.Y), size, sides[i % 2]);
                Trees.Add(t);
            }
        }
        public override void EndFrameRendering()
        {
            GraphicsDevice graphicsDevice = base.GraphicsDeviceManager.GraphicsDevice;
            graphicsDevice.BlendState = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.None;
            graphicsDevice.RasterizerState = RasterizerState.CullNone;
            
            _viewport = graphicsDevice.Viewport;

            CustomFrameBufferCollection buffers = SceneState.FrameBuffers.GetCustomFrameBufferCollection("colorcorrect", true);

            if (buffers.Count == 0)
            {
                SurfaceFormat surfaceFormat = SurfaceFormat.Color;
                buffers.Add(new RenderTarget2D(graphicsDevice, SceneState.FrameBuffers.Width, SceneState.FrameBuffers.Height, false, surfaceFormat, DepthFormat.None, 0, RenderTargetUsage.PlatformContents));
                graphicsDevice.SetRenderTarget(null);
            }
       
            graphicsDevice.SetRenderTarget(PreviousRenderTarget);
            _gammaCorrectEffect.CurrentTechnique = _gammaCorrectEffect.Techniques["ColorCorrect"];

            _gammaCorrectEffect.Parameters["SceneTexture"].SetValue(ProcessorRenderTarget);
            _gammaCorrectEffect.Parameters["Brightness"].SetValue(_brightness);

            _gammaCorrectEffect.CurrentTechnique.Passes[0].Apply();
            graphicsDevice.SamplerStates.Reset();
            FullFrameQuad.Render(graphicsDevice, _viewport.Width, _viewport.Height);

            base.EndFrameRendering();
        }
示例#8
0
 internal Camera(Viewport viewport)
 {
     Viewport = viewport;
     NearClipDistance = 1.0f;
     FarClipDistance = 1000.0f;
     FieldOfView = MathHelper.PiOver4;
 }
 public HorizontallyScrollingBackground(Viewport theViewport)
 {
     mBackgroundSprites = new List<Sprite>();
       mRightMostSprite = null;
       mLeftMostSprite = null;
       mViewport = theViewport;
 }
示例#10
0
 public Score(Viewport vp, ContentManager content)
 {
     viewport = vp;
     spriteFont = content.Load<SpriteFont>("ScoreFont");
     score = 0;
     highScore = getHighScore();
 }
示例#11
0
        protected override void Render(IntPtr windowHandle)
        {
            // If we have no graphics service, we can't draw
            if (_graphicsService == null)
                return;

            // Get the current width and height of the control
            var width = (int) ActualWidth;
            var height = (int) ActualHeight;

            // This piece of code is copied from the WinForms equivalent
            var deviceResetStatus = HandleDeviceReset(width, height);
            if (deviceResetStatus != GraphicsDeviceResetStatus.Normal)
                return;

            // Create the active viewport to which we'll render our content
            var viewport = new Viewport(0, 0, width, height);
            _graphicsService.GraphicsDevice.Viewport = viewport;

            // Invoke the event to render this control
            RaiseRenderXna(new GraphicsDeviceEventArgs(_graphicsService.GraphicsDevice));

            // Present to the screen, but only use the visible area of the back buffer
            _graphicsService.GraphicsDevice.Present(viewport.Bounds, null, windowHandle);
            //_graphicsService.GraphicsDevice.Present();
        }
示例#12
0
 public Camera()
 {
     Viewport = new Viewport();
     Viewport.Width = Engine.Instance.Screen.Width;
     Viewport.Height = Engine.Instance.Screen.Height;
     UpdateMatrices();
 }
示例#13
0
文件: Gui.cs 项目: Czeslav/Costam
        public Gui(Viewport viewport)
        {
            this.viewport = viewport;

            mainMenu = new MainMenu(viewport); //for developing only, later it will be moved somewhere and rewritten
            messageBox = new MessageBox(viewport);
        }
示例#14
0
 public Camera3D(string id, ObjectType objectType,
     Transform3D transform, ProjectionParameters projectionParameters, Viewport viewPort)
     : base(id, objectType, transform)
 {
     this.projectionParameters = projectionParameters;
     this.viewPort = viewPort;
 }
        public LevelElement(string text, Texture2D texture, Vector2 pos, bool selectable, Menu m, MenuAction a, string levelname)
            : base(text, texture, pos, selectable,m, a)
        {
            if (levelname == "alley")
            { unlocked = true; }
            topLeft = pos;
            bottomRight = new Vector2(pos.X + smallWidth, pos.Y + smallHeight);

            topLeftDest = topLeft;
            bottomRightDest = bottomRight;

            world = new World();
            world.Init(levelname);

            vp = new Viewport();
            this.levelname = levelname;
            smallfont = new GFont(TextureManager.smallFont, 5, 10);

            levelThatUnlocks.Add("airport", "alley");
            levelThatUnlocks.Add("jungle", "airport");
            levelThatUnlocks.Add("city", "jungle");
            levelThatUnlocks.Add("powerplant", "city");

            if (levelThatUnlocks.ContainsKey(levelname))
            {
                if (Config.highScore[levelThatUnlocks[levelname]] >= neededScore)
                {
                    unlocked = true;
                }
            }
        }
示例#16
0
        public Camera2D(Main game, Vector2 translation, float rotation, float scale)
            : base(game)
        {
            this.game = game;

            //we need access to viewport to get dimensions of screen
            //we cant use windowDimensions because we may want to create more than one viewport (i.e. for splitscreen)
            this.viewPort = game.GraphicsDevice.Viewport;

            //sets the position of the camera
            this.translation = translation;

            //sets any rotation around Z (i.e. coming out of the screen)
            this.rotation = rotation;

            //sets the zoom level (i.e. if > 1 zoom in, if < 1 zoom out, bounded at minimum value)
            //call property and not this.scale to ensure scale not set to less than minimum
            SCALE = scale;

            //stored for reset
            this.originalTranslation = translation;
            this.originaRotation = rotation;
            this.originalScale = scale;

            //Calc this properly, with game data etc.
            this.minY = 300;
            this.maxY = GameData.LEVEL_HEIGHT-300;
            this.minX = 400;
            this.maxX = GameData.LEVEL_WIDTH - 400;

            this.cameraElasticity = 0.1f;
            this.difference = Vector2.Zero;
        }
示例#17
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime, Viewport view)
        {
            _view = view;
            _new = Keyboard.GetState();
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            _scale += _scaleGrow * elapsed;
            if (_scale >= 2)
            {
                _scale = 2;
                _scaleGrow *= -1;
            }
            else if(_scale <= 1)
            {
                _scale = 1;
                _scaleGrow *= -1;
            }

            if (IsKeyPressed(Keys.Up))
            {
                _select.Play();
                selectedItem--;
            }
            else if (IsKeyPressed(Keys.Down))
            {
                _select.Play();
                selectedItem++;
            }

            if (selectedItem > _items.Count - 1) selectedItem = 0;
            else if(selectedItem < 0) selectedItem = _items.Count - 1;

            _old = _new;
        }
示例#18
0
        //Player constructor
        //Takes in the Textures for the Box, the ship, the player's starting position,
        //the width, heigh, speed and the player's ID
        public Player(Texture2D boxAura,Texture2D ship, Vector2 position,Rectangle boxRect,
                        Rectangle shipRect, float speed, int playerID, ContentManager content, Viewport gameView)
        {
            //Use of the viewport is allowed
            this.screen = gameView;
            //Ship information being setup
            this.ship = ship;
            sourceRectShip = shipRect;
            destRectShip = new Vector2(position.X , position.Y);

            //not debugging as soon as the game starts

            //center position of the ship
            //" / 2 " gets the center
            center = new Vector2((int)(shipRect.Width / 2), (int)(shipRect.Height / 2));

            //This boxAura's information being setup
            this.boxAura = boxAura;
            this.width = boxRect.Width;
            this.height = boxRect.Height;
            this.speed = speed;
            destRectBox = new Rectangle((int)position.X  , (int)position.Y , width, height);

            //Initiate the weapons
            init(content);

            //The player's ID
            this.playerID = playerID;

            //The player ID and KeyBoard setup (For 1 computer currently)
            if (this.playerID == 0)
                setKeys(Keys.Up, Keys.Down, Keys.Left, Keys.Right,Keys.End);
            else
                setKeys(Keys.W, Keys.S, Keys.A, Keys.D,Keys.Q);
        }
示例#19
0
        public LoadMenu(EventHandler callback)
            : base(callback)
        {
            viewport = GraphicsDevice.Viewport;

            if (!contentLoaded)
            {
                buttonFont = Content.Load<SpriteFont>("buttonFont");

                contentLoaded = true;
            }

            readMapFiles();

            int posY = 5;
            if (files.Count > 0)
                buttonHeight = (int)MathHelper.Min(40, viewport.Height / files.Count - 5);

            foreach (string file in files)
            {
                Vector2 stringSize = buttonFont.MeasureString(file.Substring(12));
                buttonWidth = (int)(stringSize.X + 15);

                SimpleButton button = new SimpleButton(new Rectangle(viewport.Width / 2 - buttonWidth / 2, posY, buttonWidth, buttonHeight), ColorTexture.Black, null, null);
                SimpleButton.AddButton(button);

                posY += buttonHeight + 5;
            }
        }
示例#20
0
        public AtlasGraphics(AtlasGlobal atlas, GraphicsDeviceManager _graphicsDeviceManager)
            : base(atlas)
        {
            _currentMode = AtlasGraphicsMode.None;

            _graphicsDevice = atlas.Game.GraphicsDevice;
            this._graphicsDeviceManager = _graphicsDeviceManager;

            _graphicsDeviceManager.PreferredBackBufferFormat = SurfaceFormat.Color;

            #if XNA
            _graphicsDeviceManager.PreferredBackBufferHeight = 768;
            _graphicsDeviceManager.PreferredBackBufferWidth = 1024;
            #endif
            ////_graphicsDeviceManager.IsFullScreen = true;
            _graphicsDeviceManager.ApplyChanges();

            _spriteBatch = new SpriteBatch(_graphicsDevice);

            _basicEffect = new BasicEffect(_graphicsDeviceManager.GraphicsDevice);

            batch = new VertexPositionColorTexture[32][];
            batchPrimitiveCount = new int[batch.Length];

            _viewPort = new Viewport(0, 0,
                _graphicsDeviceManager.PreferredBackBufferWidth,
                _graphicsDeviceManager.PreferredBackBufferHeight);
        }
示例#21
0
		public static Vector2 ToClipSpace(this Vector2 vector, Viewport viewport)
		{
			float clipX = (vector.X / viewport.Width) * 2f - 1;
			float clipY = (vector.Y / viewport.Height) * 2f - 1;

			return new Vector2(clipX, -clipY);
		}
示例#22
0
文件: Spell.cs 项目: nezek6/Wizardry
 public void Initialize(Viewport viewport, Texture2D texture)
 {
     Texture = texture;
     this.viewport = viewport;
     Active = false;
     AnimationTime = 4f;
 }
示例#23
0
        /// <summary>
        /// Initialize viewports.
        /// Use current viewport as full screen and create split screen viewports for later use.
        /// </summary>
        static Viewports()
        {
            //setup for 2 player splitscreen
            fullViewport = BeatShift.graphics.GraphicsDevice.Viewport;
            topViewport = BeatShift.graphics.GraphicsDevice.Viewport;
            bottomRightViewport = BeatShift.graphics.GraphicsDevice.Viewport;
            bottomLeftViewport = BeatShift.graphics.GraphicsDevice.Viewport;
            topRightViewport = BeatShift.graphics.GraphicsDevice.Viewport;
            topLeftViewport = BeatShift.graphics.GraphicsDevice.Viewport;

            leftViewPort = BeatShift.graphics.GraphicsDevice.Viewport;
            rightViewPort = BeatShift.graphics.GraphicsDevice.Viewport;

            topViewport.Height = (fullViewport.Height / 2);
            bottomViewport = topViewport;
            bottomViewport.Y = topViewport.Height;
            leftViewPort.Width = (fullViewport.Width/2);
            rightViewPort.Width = leftViewPort.Width;
            rightViewPort.X = leftViewPort.Width;
            //set size for 4 player split
            bottomRightViewport.Height = (fullViewport.Height / 2);
            bottomRightViewport.Width = (fullViewport.Width / 2);
            bottomLeftViewport.Height = (fullViewport.Height / 2);
            bottomLeftViewport.Width = (fullViewport.Width / 2);
            topRightViewport.Height = (fullViewport.Height / 2);
            topRightViewport.Width = (fullViewport.Width / 2);
            topLeftViewport.Height = (fullViewport.Height / 2);
            topLeftViewport.Width = (fullViewport.Width / 2);
            //set X and Y for 4 player split
            topRightViewport.X = topLeftViewport.Width;
            bottomRightViewport.X = bottomLeftViewport.Width;
            bottomLeftViewport.Y = topViewport.Height;
            bottomRightViewport.Y = topViewport.Height;
        }
示例#24
0
        public GameCamera(Scene _currentScene, Vector3 _position, Quaternion _rotation, float _aspectRatio)
        {
            currentScene = _currentScene;
            position = _position;
            rotation = _rotation;
            aspectRatio = _aspectRatio;
            up = new Vector3(0, 1, 0);
            target = new Vector3();
            viewMatrix = Matrix.CreateLookAt(position,
                        target, up);
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                        MathHelper.ToRadians(45.0f), aspectRatio,
                        0.1f, VIEW_DEPTH);
            viewPort = Space394Game.GameInstance.GraphicsDevice.Viewport;
            fourthPort = new Viewport(
                        Space394Game.GameInstance.DefaultViewPort.Width / 2 + 1,
                        Space394Game.GameInstance.DefaultViewPort.Height / 2 + 1,
                        Space394Game.GameInstance.DefaultViewPort.Width / 2 - 1,
                        Space394Game.GameInstance.DefaultViewPort.Height / 2 - 1);

            splitScreen2 = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\splitScreen2"), Vector2.Zero);
            splitScreen3 = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\splitScreen3"), Vector2.Zero);
            splitScreen4 = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\splitScreen4"), Vector2.Zero);
            blackTexture = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\blackTexture"), Vector2.Zero);
            blackTexture.Width = fourthPort.Width;
            blackTexture.Height = fourthPort.Height;
            pausedTexture = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\pausedTexture"), Vector2.Zero);
        }
示例#25
0
文件: Game1.cs 项目: ndssia/Corsair2
        protected override void Initialize()
        {
            base.Initialize();

            ActiveScreen = new GameplayScreen(Content, Graphics.GraphicsDevice.Viewport);
            Viewport = Graphics.GraphicsDevice.Viewport;
        }
示例#26
0
        private void Initialize()
        {
            // create Camera
            _camera = new ArcBallCamera(MapData.GetWorldPosition(20, 20), 0, MathHelper.PiOver2 * 0.5f * 0.8f * 0.8f, 0, MathHelper.PiOver2, CameraDistance, 30, 100, Manager.GraphicsDevice);

            // zooming
            zooming = new Zooming("Middle", "VeryFar", 2f, "Far", 1.3f, "Middle", 1.0f, "Near", 0.7f, "VeryNear", 0.5f, "Detail", 0.2f);
            zooming.ZoomChanged += delegate(float zoom) { _camera.Distance = CameraDistance * zoom; };

            _effect = Manager.Content.Load<Effect>("Content/Effects/Series4Effects");

            Mouse.SetPosition(Manager.GraphicsDevice.Viewport.Width / 2, Manager.GraphicsDevice.Viewport.Height / 2);

            _skyDome = Manager.Content.Load<Model>("Content/Models/dome");
            _skyDome.Meshes[0].MeshParts[0].Effect = _effect.Clone();

            _cloudMap = Manager.Content.Load<Texture2D>("Content/Models/cloudMap");

            _mapRenderer.Initialize();
            _mapRenderer.LoadContent();

            // init complete view
            defaultViewport = new Viewport();
            defaultViewport.X = 0;
            defaultViewport.Y = 0;
            defaultViewport.Width = Manager.GraphicsDevice.Viewport.Width;
            defaultViewport.Height = Manager.GraphicsDevice.Viewport.Height;

            // init control view
            controlViewport = new Viewport();
            controlViewport.X = 4;
            controlViewport.Y = 27;
            controlViewport.Width = Manager.GraphicsDevice.Viewport.Width - 8;
            controlViewport.Height = Manager.GraphicsDevice.Viewport.Height - 32;
        }
示例#27
0
        public Camera(Viewport pViewPort)
        {
            _viewport = pViewPort;

            UpdateViewMatrix();
            UpdateProjectionMatrix();
        }
示例#28
0
文件: Camera.cs 项目: 2Light/Insomnia
 public Camera(Viewport viewport, bool widescreen)
 {
     if (widescreen) Origin = new Vector2((viewport.Width / 2.0f) + 64, (viewport.Height / 2.0f) + 640);
     else Origin = new Vector2(viewport.Width / 2.0f, viewport.Height / 2.0f);
     Zoom = 1.0f;
     this.viewport = viewport;
 }
        protected override void Initialize()
        {
            viewport = GraphicsDevice.Viewport;
            TileEngine.InitializeEngine();
            AudioManager.Initialize();

            //Later replace with something else.
            IsMouseVisible = true;

            //Load the tileset here so the map can be properly loaded.
            new Tileset(Content.Load<Texture2D>("levelTileset"));

            //Let the audio manager load all relevant assets itself
            AudioManager.LoadContent(Content);

            // If you want to make changes to the game map, uncomment the following line and then comment out the
            // two lines that follow it.  Make any changes you like to the map, and then click the save button to
            // automatically write to map.gtd.  Afterwards, swap the commented lines once more.

            //currentScene = new MapEditorScene();

            currentScene = new OpeningMovieScene();
            currentScene.LoadContent(Content);

            base.Initialize();
        }
示例#30
0
        public static void Initialize(Game game)
        {
            Texture = new Texture2D(game.GraphicsDevice, 1, 1);
            Texture.SetData<Color>(new Color[] { Color.White });

            Viewport = game.GraphicsDevice.Viewport;
        }
示例#31
0
 internal static void ConvertViewport(ref XFG.Viewport vp, out Viewport result)
 {
     result.X        = vp.X;
     result.Y        = vp.Y;
     result.Width    = vp.Width;
     result.Height   = vp.Height;
     result.MaxDepth = vp.MaxDepth;
     result.MinDepth = vp.MinDepth;
 }
示例#32
0
        public void DrawScene(GameTime gameTime, Microsoft.Xna.Framework.Graphics.Viewport viewport, Matrix stereoTransform, Matrix view, Matrix projection)
        {
            // TODO: Draw something fancy. Or at the very least visible?
            var translation = Matrix.CreateTranslation(Vector3.Negate(position));
            var kbRotation  = Matrix.CreateRotationY(-rotationY);
            var cameraView  = stereoTransform * translation * kbRotation * view;

            // Draw the model. A model can have multiple meshes, so loop.
            var modelWorld = Matrix.CreateTranslation(0f, -0f, -0f);

            foreach (ModelMesh mesh in model.Meshes)
            {
                // This is where the mesh orientation is set, as well
                // as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World      = modelWorld;
                    effect.View       = cameraView;
                    effect.Projection = projection;
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }

            DrawPose(Color.Red, leftHandPose, leftHandOffset, cameraView, projection);
            if (orientationMode != OrientationMode.RightHand)
            {
                DrawPose(Color.Blue, rightHandPose, rightHandOffset, cameraView, projection);
            }

            var kbstate = Keyboard.GetState();

            if (kbstate.IsKeyDown(Keys.Q) || kbstate.IsKeyDown(Keys.E))
            {
                // display IPD
                spriteBatch.Begin();
                spriteBatch.DrawString(diagnosticFont, "IPD: " + (vrHead.IPDInMeters * 1000).ToString() + "mm",
                                       new Vector2((float)viewport.Width / 2f, (float)viewport.Height / 2f), Color.White);

                // display eye tracking 2D location
                var halfXSize         = diagnosticFont.MeasureString("X") * .5f;
                var eyeState          = leftEye2D.GetState();
                var scaledEyePosition = new Vector2(
                    (eyeState.Value.X * (float)viewport.Width) - halfXSize.X,
                    (eyeState.Value.Y * (float)viewport.Height) - halfXSize.Y);

                spriteBatch.DrawString(diagnosticFont, "X",
                                       scaledEyePosition, Color.Red);

                spriteBatch.End();
            }
        }
示例#33
0
        public void FixViewport()
        {
            Microsoft.Xna.Framework.Graphics.Viewport _vp =
                new Microsoft.Xna.Framework.Graphics.Viewport();

            // fit gfx viewport to view bounds.
            _vp.X      = this._view.ClientBounds.Left;
            _vp.Y      = this._view.ClientBounds.Top;
            _vp.Width  = this._view.ClientBounds.Width;
            _vp.Height = this._view.ClientBounds.Height;

            GraphicsDevice.Viewport = _vp;
        }
示例#34
0
        // This method calls the game Initialize and BeginRun methods before it begins the game loop and starts
        // processing events for the game.
        public void Run()
        {
            _lastUpdate = DateTime.Now;

            // In an original XNA game the GraphicsDevice property is null during initialization
            // but before the Game's Initialize method is called the property is available so we can
            // only assume that it should be created somewhere in here.  We can not set the viewport
            // values correctly based on the Preferred settings which is causing some problems on some
            // Microsoft samples which we are not handling correctly.
            graphicsDeviceManager.CreateDevice();

            var manager = Services.GetService(typeof(IGraphicsDeviceManager)) as GraphicsDeviceManager;

            Microsoft.Xna.Framework.Graphics.Viewport _vp =
                new Microsoft.Xna.Framework.Graphics.Viewport();

            _vp.X      = 0;
            _vp.Y      = 0;
            _vp.Width  = manager.PreferredBackBufferWidth;
            _vp.Height = manager.PreferredBackBufferHeight;

            GraphicsDevice.Viewport = _vp;

            _initializing = true;

            // Moving the GraphicsDevice creation to here also modifies when GameComponents are being
            // initialized.
            // Use OpenGL context locking in delegate function
//			InitialiseGameComponentsDelegate initD = new InitialiseGameComponentsDelegate (InitializeGameComponents);
//
//			// Invoke on thread from the pool
//			initD.BeginInvoke (
//				delegate (IAsyncResult iar)
//				{
//					// We must have finished initialising, so set our flag appropriately
//					// So that we enter the Update loop
//					_initialized = true;
//					_initializing = false;
//				},
//			initD);

            InitializeGameComponents();
            _initialized  = true;
            _initializing = false;


            Initialize();

            _view.Run(FramesPerSecond / (FramesPerSecond * TargetElapsedTime.TotalSeconds));
            _mainWindow.MakeKeyAndOrderFront(_mainWindow);
        }
示例#35
0
文件: Game.cs 项目: jordoh/MonoGame
        public void Run()
        {
            _lastUpdate = DateTime.Now;

            // In an original XNA game the GraphicsDevice property is null during initialization
            // but before the Game's Initialize method is called the property is available so we can
            // only assume that it should be created somewhere in here.  We can not set the viewport
            // values correctly based on the Preferred settings which is causing some problems on some
            // Microsoft samples which we are not handling correctly.
            graphicsDeviceManager.CreateDevice();

            var manager = Services.GetService(typeof(IGraphicsDeviceManager)) as GraphicsDeviceManager;

            Microsoft.Xna.Framework.Graphics.Viewport _vp =
                new Microsoft.Xna.Framework.Graphics.Viewport();

            _vp.X      = 0;
            _vp.Y      = 0;
            _vp.Width  = manager.PreferredBackBufferWidth;
            _vp.Height = manager.PreferredBackBufferHeight;

            GraphicsDevice.Viewport = _vp;

            _view.Run(FramesPerSecond / (FramesPerSecond * TargetElapsedTime.TotalSeconds));

            _view.MainContext       = _view.EAGLContext;
            _view.ShareGroup        = _view.MainContext.ShareGroup;
            _view.BackgroundContext = new MonoTouch.OpenGLES.EAGLContext(_view.ContextRenderingApi, _view.ShareGroup);


            Accelerometer.SetupAccelerometer();
            Initialize();

            // Draw the splash screen to the render buffer before making the window visible so
            // there is no flicker when a blank render buffer is made visible
            DrawSplashScreen();
            _view.SwapBuffers();

            //Show the window
            _mainWindow.MakeKeyAndVisible();

            // Listen out for rotation changes
            ObserveDeviceRotation();
        }
示例#36
0
文件: Graphics.cs 项目: thomaswp/RTS
        private static Microsoft.Xna.Framework.Graphics.Viewport GetViewport(Viewport vp)
        {
            Microsoft.Xna.Framework.Graphics.Viewport xnaVp;

            if (viewportsMap.ContainsKey(vp))
            {
                xnaVp = viewportsMap[vp];
            }
            else
            {
                xnaVp = new Microsoft.Xna.Framework.Graphics.Viewport();
                viewportsMap.Add(vp, xnaVp);
            }

            xnaVp.X      = vp.X;
            xnaVp.Y      = vp.Y;
            xnaVp.Width  = vp.Width;
            xnaVp.Height = vp.Height;

            return(xnaVp);
        }
示例#37
0
        internal void applyChanges(GraphicsDeviceManager manager)
        {
            Microsoft.Xna.Framework.Graphics.Viewport _vp =
                new Microsoft.Xna.Framework.Graphics.Viewport();

            _vp.X      = 0;
            _vp.Y      = 0;
            _vp.Width  = manager.PreferredBackBufferWidth;
            _vp.Height = manager.PreferredBackBufferHeight;

            GraphicsDevice.Viewport = _vp;

            if (GraphicsDevice.PresentationParameters.IsFullScreen)
            {
                GoFullScreen();
            }
            else
            {
                _wasResizeable = IsAllowUserResizing;
                GoWindowed();
            }
        }
示例#38
0
        public void Run()
        {
            _lastUpdate = DateTime.Now;

            // In an original XNA game the GraphicsDevice property is null during initialization
            // but before the Game's Initialize method is called the property is available so we can
            // only assume that it should be created somewhere in here.  We can not set the viewport
            // values correctly based on the Preferred settings which is causing some problems on some
            // Microsoft samples which we are not handling correctly.

            graphicsDeviceManager.CreateDevice();

            var manager = Services.GetService(typeof(IGraphicsDeviceManager)) as GraphicsDeviceManager;

            Microsoft.Xna.Framework.Graphics.Viewport _vp =
                new Microsoft.Xna.Framework.Graphics.Viewport();

            _vp.X      = 0;
            _vp.Y      = 0;
            _vp.Width  = manager.PreferredBackBufferWidth;
            _vp.Height = manager.PreferredBackBufferHeight;

            GraphicsDevice.Viewport = _vp;

            //Need to execute this on the rendering thread
            _view.OpenTkGameWindow.RenderFrame += delegate
            {
                if (!_devicesLoaded)
                {
                    Initialize();
                    _devicesLoaded = true;
                }
            };

            _view.OpenTkGameWindow.Run(FramesPerSecond / (FramesPerSecond * TargetElapsedTime.TotalSeconds));
        }
示例#39
0
        public void Reset(
            PresentationParameters presentationParameters,
            GraphicsAdapter graphicsAdapter
            )
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException("presentationParameters");
            }

            // We're about to reset, let the application know.
            if (DeviceResetting != null)
            {
                DeviceResetting(this, EventArgs.Empty);
            }

            /* FIXME: Why are we not doing this...? -flibit
             * lock (resourcesLock)
             * {
             *      foreach (WeakReference resource in resources)
             *      {
             *              object target = resource.Target;
             *              if (target != null)
             *              {
             *                      (target as GraphicsResource).GraphicsDeviceResetting();
             *              }
             *      }
             *
             *      // Remove references to resources that have been garbage collected.
             *      resources.RemoveAll(wr => !wr.IsAlive);
             * }
             */

            // Set the new PresentationParameters first.
            PresentationParameters = presentationParameters;
            PresentationParameters.MultiSampleCount = Math.Min(
                MathHelper.ClosestMSAAPower(
                    PresentationParameters.MultiSampleCount
                    ),
                GLDevice.MaxMultiSampleCount
                );

            /* Reset the backbuffer first, before doing anything else.
             * The GLDevice needs to know what we're up to right away.
             * -flibit
             */
            GLDevice.Backbuffer.ResetFramebuffer(
                PresentationParameters,
                RenderTargetCount > 0
                );

            // Now, update the viewport
            Viewport = new Viewport(
                0,
                0,
                PresentationParameters.BackBufferWidth,
                PresentationParameters.BackBufferHeight
                );

            // Update the scissor rectangle to our new default target size
            ScissorRectangle = new Rectangle(
                0,
                0,
                PresentationParameters.BackBufferWidth,
                PresentationParameters.BackBufferHeight
                );

            // FIXME: This should probably mean something. -flibit
            Adapter = graphicsAdapter;

            // We just reset, let the application know.
            if (DeviceReset != null)
            {
                DeviceReset(this, EventArgs.Empty);
            }
        }
示例#40
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsDevice" /> class.
        /// </summary>
        /// <param name="adapter">The graphics adapter.</param>
        /// <param name="graphicsProfile">The graphics profile.</param>
        /// <param name="presentationParameters">The presentation options.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="presentationParameters"/> is <see langword="null"/>.
        /// </exception>
        public GraphicsDevice(
            GraphicsAdapter adapter,
            GraphicsProfile graphicsProfile,
            PresentationParameters presentationParameters
            )
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException("presentationParameters");
            }

            // Set the properties from the constructor parameters.
            Adapter = adapter;
            PresentationParameters = presentationParameters;
            GraphicsProfile        = graphicsProfile;
            PresentationParameters.MultiSampleCount = MathHelper.ClosestMSAAPower(
                PresentationParameters.MultiSampleCount
                );

            // Set up the IGLDevice
            GLDevice = FNAPlatform.CreateGLDevice(PresentationParameters, adapter);

            // The mouse needs to know this for faux-backbuffer mouse scaling.
            Input.Mouse.INTERNAL_BackBufferWidth  = PresentationParameters.BackBufferWidth;
            Input.Mouse.INTERNAL_BackBufferHeight = PresentationParameters.BackBufferHeight;

            // The Touch Panel needs this too, for the same reason.
            Input.Touch.TouchPanel.DisplayWidth  = PresentationParameters.BackBufferWidth;
            Input.Touch.TouchPanel.DisplayHeight = PresentationParameters.BackBufferHeight;

            // Force set the default render states.
            BlendState        = BlendState.Opaque;
            DepthStencilState = DepthStencilState.Default;
            RasterizerState   = RasterizerState.CullCounterClockwise;

            // Initialize the Texture/Sampler state containers
            int maxTextures       = Math.Min(GLDevice.MaxTextureSlots, MAX_TEXTURE_SAMPLERS);
            int maxVertexTextures = MathHelper.Clamp(
                GLDevice.MaxTextureSlots - MAX_TEXTURE_SAMPLERS,
                0,
                MAX_VERTEXTEXTURE_SAMPLERS
                );

            vertexSamplerStart = GLDevice.MaxTextureSlots - maxVertexTextures;
            Textures           = new TextureCollection(
                maxTextures,
                modifiedSamplers
                );
            SamplerStates = new SamplerStateCollection(
                maxTextures,
                modifiedSamplers
                );
            VertexTextures = new TextureCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );
            VertexSamplerStates = new SamplerStateCollection(
                maxVertexTextures,
                modifiedVertexSamplers
                );

            // Set the default viewport and scissor rect.
            Viewport         = new Viewport(PresentationParameters.Bounds);
            ScissorRectangle = Viewport.Bounds;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                FNALoggerEXT.LogError("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                FNALoggerEXT.LogError("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            wiiuPixelData = new byte[
                PresentationParameters.BackBufferWidth *
                PresentationParameters.BackBufferHeight *
                4
                            ];
#endif
        }
示例#41
0
        public void Reset(
            PresentationParameters presentationParameters,
            GraphicsAdapter graphicsAdapter
            )
        {
            if (presentationParameters == null)
            {
                throw new ArgumentNullException("presentationParameters");
            }
            PresentationParameters = presentationParameters;
            Adapter = graphicsAdapter;

            // Verify MSAA before we really start...
            PresentationParameters.MultiSampleCount = Math.Min(
                MathHelper.ClosestMSAAPower(
                    PresentationParameters.MultiSampleCount
                    ),
                GLDevice.MaxMultiSampleCount
                );

            // We're about to reset, let the application know.
            if (DeviceResetting != null)
            {
                DeviceResetting(this, EventArgs.Empty);
            }

            /* FIXME: Why are we not doing this...? -flibit
             * lock (resourcesLock)
             * {
             *      foreach (WeakReference resource in resources)
             *      {
             *              object target = resource.Target;
             *              if (target != null)
             *              {
             *                      (target as GraphicsResource).GraphicsDeviceResetting();
             *              }
             *      }
             *
             *      // Remove references to resources that have been garbage collected.
             *      resources.RemoveAll(wr => !wr.IsAlive);
             * }
             */

            /* Reset the backbuffer first, before doing anything else.
             * The GLDevice needs to know what we're up to right away.
             * -flibit
             */
            GLDevice.ResetBackbuffer(
                PresentationParameters,
                Adapter,
                RenderTargetCount > 0
                );

            // The mouse needs to know this for faux-backbuffer mouse scaling.
            Input.Mouse.INTERNAL_BackBufferWidth  = PresentationParameters.BackBufferWidth;
            Input.Mouse.INTERNAL_BackBufferHeight = PresentationParameters.BackBufferHeight;

            // The Touch Panel needs this too, for the same reason.
            Input.Touch.TouchPanel.DisplayWidth  = PresentationParameters.BackBufferWidth;
            Input.Touch.TouchPanel.DisplayHeight = PresentationParameters.BackBufferHeight;

#if WIIU_GAMEPAD
            wiiuPixelData = new byte[
                PresentationParameters.BackBufferWidth *
                PresentationParameters.BackBufferHeight *
                4
                            ];
#endif

            // Now, update the viewport
            Viewport = new Viewport(
                0,
                0,
                PresentationParameters.BackBufferWidth,
                PresentationParameters.BackBufferHeight
                );

            // Update the scissor rectangle to our new default target size
            ScissorRectangle = new Rectangle(
                0,
                0,
                PresentationParameters.BackBufferWidth,
                PresentationParameters.BackBufferHeight
                );

            // We just reset, let the application know.
            if (DeviceReset != null)
            {
                DeviceReset(this, EventArgs.Empty);
            }
        }
示例#42
0
        public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
        {
            // Checking for redundant SetRenderTargets...
            if (renderTargets == null && RenderTargetCount == 0)
            {
                return;
            }
            else if (renderTargets != null && renderTargets.Length == RenderTargetCount)
            {
                bool isRedundant = true;
                for (int i = 0; i < renderTargets.Length; i += 1)
                {
                    if (renderTargets[i].RenderTarget != renderTargetBindings[i].RenderTarget ||
                        renderTargets[i].CubeMapFace != renderTargetBindings[i].CubeMapFace)
                    {
                        isRedundant = false;
                        break;
                    }
                }
                if (isRedundant)
                {
                    return;
                }
            }

            int newWidth;
            int newHeight;
            RenderTargetUsage clearTarget;

            if (renderTargets == null || renderTargets.Length == 0)
            {
                GLDevice.SetRenderTargets(null, null, DepthFormat.None);

                // Set the viewport/scissor to the size of the backbuffer.
                newWidth    = PresentationParameters.BackBufferWidth;
                newHeight   = PresentationParameters.BackBufferHeight;
                clearTarget = PresentationParameters.RenderTargetUsage;

                // Resolve previous targets, if needed
                for (int i = 0; i < RenderTargetCount; i += 1)
                {
                    GLDevice.ResolveTarget(renderTargetBindings[i]);
                }
                Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length);
                RenderTargetCount = 0;
            }
            else
            {
                IRenderTarget target = renderTargets[0].RenderTarget as IRenderTarget;
                GLDevice.SetRenderTargets(
                    renderTargets,
                    target.DepthStencilBuffer,
                    target.DepthStencilFormat
                    );

                // Set the viewport/scissor to the size of the first render target.
                newWidth    = target.Width;
                newHeight   = target.Height;
                clearTarget = target.RenderTargetUsage;

                // Resolve previous targets, if needed
                for (int i = 0; i < RenderTargetCount; i += 1)
                {
                    // We only need to resolve if the target is no longer bound.
                    bool stillBound = false;
                    for (int j = 0; j < renderTargets.Length; j += 1)
                    {
                        if (renderTargetBindings[i].RenderTarget == renderTargets[j].RenderTarget)
                        {
                            stillBound = true;
                            break;
                        }
                    }
                    if (stillBound)
                    {
                        continue;
                    }
                    GLDevice.ResolveTarget(renderTargetBindings[i]);
                }
                Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length);
                Array.Copy(renderTargets, renderTargetBindings, renderTargets.Length);
                RenderTargetCount = renderTargets.Length;
            }

            // Apply new GL state, clear target if requested
            Viewport         = new Viewport(0, 0, newWidth, newHeight);
            ScissorRectangle = new Rectangle(0, 0, newWidth, newHeight);
            if (clearTarget == RenderTargetUsage.DiscardContents)
            {
                Clear(
                    ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil,
                    DiscardColor,
                    Viewport.MaxDepth,
                    0
                    );
            }
        }
示例#43
0
        public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
        {
            currentRenderTargets = renderTargets;

            if (currentRenderTargets != null)
            {
                // TODO: For speed we need to consider using FBO switching instead
                // of multiple FBO's if they are the same size.

                // http://www.songho.ca/opengl/gl_fbo.html

                frameBufferIDs = new int[currentRenderTargets.Length];

                renderBufferIDs = new int[currentRenderTargets.Length];
                GL.GenRenderbuffers(currentRenderTargets.Length, renderBufferIDs);

                for (int i = 0; i < currentRenderTargets.Length; i++)
                {
                    RenderTarget2D target = (RenderTarget2D)currentRenderTargets[i].RenderTarget;

                    // create a renderbuffer object to store depth info
                    GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, renderBufferIDs[i]);

                    ClearOptions clearOptions = ClearOptions.Target | ClearOptions.DepthBuffer;

                    switch (target.DepthStencilFormat)
                    {
                    case DepthFormat.Depth16:
                        GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, RenderbufferStorage.DepthComponent16,
                                               target.Width, target.Height);
                        break;

                    case DepthFormat.Depth24:
                        GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, RenderbufferStorage.DepthComponent24,
                                               target.Width, target.Height);
                        break;

                    case DepthFormat.Depth24Stencil8:
                        GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, RenderbufferStorage.Depth24Stencil8,
                                               target.Width, target.Height);
                        GL.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.StencilAttachmentExt,
                                                   RenderbufferTarget.RenderbufferExt, renderBufferIDs[i]);
                        clearOptions = clearOptions | ClearOptions.Stencil;
                        break;

                    default:
                        GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, RenderbufferStorage.DepthComponent24,
                                               target.Width, target.Height);
                        break;
                    }

                    // create framebuffer
                    GL.GenFramebuffers(1, out frameBufferIDs[i]);
                    GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, frameBufferIDs[i]);

                    // attach the texture to FBO color attachment point
                    GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0,
                                            TextureTarget.Texture2D, target.ID, 0);

                    // attach the renderbuffer to depth attachment point
                    GL.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt,
                                               RenderbufferTarget.RenderbufferExt, renderBufferIDs[i]);

                    if (target.RenderTargetUsage == RenderTargetUsage.DiscardContents)
                    {
                        Clear(clearOptions, Color.Transparent, 0, 0);
                    }

                    GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, 0);
                }

                FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.FramebufferExt);

                if (status != FramebufferErrorCode.FramebufferComplete)
                {
                    throw new Exception("Error creating framebuffer: " + status);
                }

                // We need to start saving off the ViewPort and setting the current ViewPort to
                // the width and height of the texture.  Then when we pop off the rendertarget
                // it needs to be reset.  This causes drawing problems if we do not set the viewport.
                // Makes sense once you follow the flow (hits head on desk)
                // For an example of this take a look at NetRumble's sample for the BloomPostprocess

                // Save off the current viewport to be reset later
                savedViewport = Viewport;

                // Create a new Viewport
                Viewport renderTargetViewPort = new Viewport();

                // Set the new viewport to the width and height of the render target
                Texture2D target2 = (Texture2D)currentRenderTargets[0].RenderTarget;
                renderTargetViewPort.Width  = target2.Width;
                renderTargetViewPort.Height = target2.Height;

                // now we set our viewport to the new rendertarget viewport just created.
                Viewport = renderTargetViewPort;
            }
        }
 private void PlatformSetViewport(ref Viewport value)
 {
 }
示例#45
0
 internal static void ConvertViewport(ref Viewport vp, out XFG.Viewport result)
 {
     result          = new XFG.Viewport(vp.X, vp.Y, vp.Width, vp.Height);
     result.MaxDepth = vp.MaxDepth;
     result.MinDepth = vp.MinDepth;
 }
示例#46
0
        public void End()
        {
            // apply the custom effect if there is one
            if (_effect != null)
            {
                _effect.Apply();

                if (graphicsDevice.Textures._textures.Count > 0)
                {
                    foreach (EffectParameter ep in _effect._textureMappings)
                    {
                        // if user didn't inform the texture index, we can't bind it
                        if (ep.UserInedx == -1)
                        {
                            continue;
                        }

                        Texture tex = graphicsDevice.Textures[ep.UserInedx];

                        // Need to support multiple passes as well
                        GL.ActiveTexture((TextureUnit)((int)TextureUnit.Texture0 + ep.UserInedx));
                        GL.BindTexture(TextureTarget.Texture2D, tex._textureId);
                        GL.Uniform1(ep.UniformLocation, ep.UserInedx);
                    }
                }
            }

            // Disable Blending by default = BlendState.Opaque
            GL.Disable(EnableCap.Blend);

            // set the blend mode
            if (_blendState == BlendState.NonPremultiplied)
            {
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                GL.Enable(EnableCap.Blend);
            }

            if (_blendState == BlendState.AlphaBlend)
            {
                GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
                GL.Enable(EnableCap.Blend);
            }

            if (_blendState == BlendState.Additive)
            {
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);
                GL.Enable(EnableCap.Blend);
            }

            // set camera
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            Viewport vp = this.graphicsDevice.Viewport;

            // Switch on the flags.
            switch (this.graphicsDevice.PresentationParameters.DisplayOrientation)
            {
            case DisplayOrientation.LandscapeLeft:
            {
                GL.Rotate(-90, 0, 0, 1);
                break;
            }

            case DisplayOrientation.LandscapeRight:
            {
                GL.Rotate(90, 0, 0, 1);
                break;
            }

            case DisplayOrientation.PortraitUpsideDown:
            {
                GL.Rotate(180, 0, 0, 1);
                break;
            }

            default:
            {
                break;
            }
            }

            GL.Ortho(0, vp.Width, vp.Height, 0, -1, 1);

            // Enable Scissor Tests if necessary
            if (this.graphicsDevice.RasterizerState.ScissorTestEnable)
            {
                GL.Enable(EnableCap.ScissorTest);
            }

            GL.MatrixMode(MatrixMode.Modelview);

            GL.Viewport(0, 0, vp.Width, vp.Height);
            //GL.Viewport (vp.X, vp.Y, vp.Width, vp.Height);

            // Enable Scissor Tests if necessary
            if (this.graphicsDevice.RasterizerState.ScissorTestEnable)
            {
                GL.Scissor(this.graphicsDevice.ScissorRectangle.X, this.graphicsDevice.ScissorRectangle.Y, this.graphicsDevice.ScissorRectangle.Width, this.graphicsDevice.ScissorRectangle.Height);
            }

            GL.LoadMatrix(ref _matrix.M11);

            // Initialize OpenGL states (ideally move this to initialize somewhere else)
            GL.Disable(EnableCap.DepthTest);
            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)All.BlendSrc);
            GL.Enable(EnableCap.Texture2D);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);

            // Enable Culling for better performance
            GL.Enable(EnableCap.CullFace);
            GL.FrontFace(FrontFaceDirection.Cw);
            GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);

            _batcher.DrawBatch(_sortMode, _samplerState);

            // Disable Scissor Tests if necessary
            if (this.graphicsDevice.RasterizerState.ScissorTestEnable)
            {
                GL.Disable(EnableCap.ScissorTest);
            }

            // clear out the textures
            graphicsDevice.Textures._textures.Clear();

            // unbinds shader
            if (_effect != null)
            {
                GL.UseProgram(0);
                _effect = null;
            }
        }