Beispiel #1
0
        //------------------------------------------------------------------------------------------------------------------------
        //                                                        Game()
        //------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="Game"/> class.
        /// This class represents a game window, containing an openGL view.
        /// </summary>
        /// <param name='width'>
        /// Width of the window in pixels.
        /// </param>
        /// <param name='height'>
        /// Height of the window in pixels.
        /// </param>
        /// <param name='fullScreen'>
        /// If set to <c>true</c> the application will run in fullscreen mode.
        /// </param>
        public Game(int pWidth, int pHeight, bool pFullScreen, bool pVSync = true)
            : base()
        {
            if (main != null) {
                throw new Exception ("Only a single instance of Game is allowed");
            } else {

                main = this;
                _updateManager = new UpdateManager ();
                _collisionManager = new CollisionManager ();
                _glContext = new GLContext (this);
                _glContext.CreateWindow (pWidth, pHeight, pFullScreen, pVSync);
                _gameObjectsContained = new List<GameObject>();

                //register ourselves for updates
                Add (this);

            }
        }
Beispiel #2
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        RenderSelf()
 //------------------------------------------------------------------------------------------------------------------------
 protected override void RenderSelf(GLContext glContext)
 {
     //empty
 }
Beispiel #3
0
        //------------------------------------------------------------------------------------------------------------------------
        //                                                        Render()
        //------------------------------------------------------------------------------------------------------------------------
        protected override void RenderSelf(GLContext glContext)
        {
            if (_invalidate) {
                _texture.UpdateGLTexture ();
                _invalidate = false;
            }

            base.RenderSelf (glContext);
        }
Beispiel #4
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        RenderSelf()
 //------------------------------------------------------------------------------------------------------------------------
 protected override void RenderSelf(GLContext glContext)
 {
     if (game != null) {
         Vector2[] bounds = GetExtents();
         float maxX = float.MinValue;
         float maxY = float.MinValue;
         float minX = float.MaxValue;
         float minY = float.MaxValue;
         for (int i=0; i<4; i++) {
             if (bounds[i].x > maxX) maxX = bounds[i].x;
             if (bounds[i].x < minX) minX = bounds[i].x;
             if (bounds[i].y > maxY) maxY = bounds[i].y;
             if (bounds[i].y < minY) minY = bounds[i].y;
         }
         bool test = (maxX < 0) || (maxY < 0) || (minX >= game.width) || (minY >= game.height);
         if (test == false) {
             if (blendMode != null) blendMode.enable ();
             _texture.Bind();
             glContext.SetColor((byte)((_color >> 16) & 0xFF),
                                (byte)((_color >> 8) & 0xFF),
                                (byte)(_color & 0xFF),
                                (byte)(_alpha * 0xFF));
             glContext.DrawQuad(GetArea(), _uvs);
             glContext.SetColor(1, 1, 1, 1);
             _texture.Unbind();
             if (blendMode != null) BlendMode.NORMAL.enable();
         }
     }
 }
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        RenderSelf
 //------------------------------------------------------------------------------------------------------------------------
 protected virtual void RenderSelf(GLContext glContext)
 {
     if (visible == false) return;
     glContext.PushMatrix(matrix);
     glContext.PopMatrix();
 }
        //------------------------------------------------------------------------------------------------------------------------
        //                                                        Render
        //------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// This function is called by the renderer. You can override it to change this object's rendering behaviour.
        /// When not inside the GXPEngine package, specify the parameter as GXPEngine.Core.GLContext.
        /// This function was made public to accomoadate split screen rendering. Use SetViewPort for that.
        /// </summary>
        /// <param name='glContext'>
        /// Gl context, will be supplied by internal caller.
        /// </param>
        public virtual void Render(GLContext glContext)
        {
            if (visible) {
                glContext.PushMatrix(matrix);

                RenderSelf (glContext);
                foreach (GameObject child in GetChildren()) {
                    child.Render(glContext);
                }

                glContext.PopMatrix();
            }
        }