Beispiel #1
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (lastTexture != null)
            {
                lastTexture.RemoveUser();
                lastTexture = null;
            }

            GC.SuppressFinalize(this);
        }
Beispiel #2
0
        /// <summary>
        /// Performs the initialization steps required to setup the game.
        /// </summary>
        /// <param name="args"></param>
        public override void Init(string[] args)
        {
            base.Init(args);

            Video.SetVideoMode(BackbufferWidth, BackbufferHeight, false, true, false, true);
            Video.GLDoubleBufferEnabled = true;

            Gl.glEnable(Gl.GL_TEXTURE_2D);                                                  // Enable Texture Mapping
            Gl.glEnable(Gl.GL_ALPHA);
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glShadeModel(Gl.GL_SMOOTH);                                                  // Enable Smooth Shading
            Gl.glClearColor(0, 0, 0, 0.5f);                                                 // Black Background
            Gl.glClearDepth(1);                                                             // Depth Buffer Setup
            Gl.glEnable(Gl.GL_DEPTH_TEST);                                                  // Enables Depth Testing
            Gl.glDepthFunc(Gl.GL_LEQUAL);                                                   // The Type Of Depth Testing To Do
            Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);                     // Really Nice Perspective Calculations

            cursor           = TextureManager.GetTexture("cursor");
            Mouse.ShowCursor = false;
        }
Beispiel #3
0
        /// <summary>
        /// Renders this face.
        /// </summary>
        public void Render(int offsetX, int offsetY)
        {
            renderingStack.Push(this);

            try
            {
                if (this.Background.Color.HasValue && Size.Width.HasValue && Size.Height.HasValue)
                {
                    Rectangle DrawArea = new Rectangle(offsetX, offsetY, Size.Width.Value, Size.Height.Value);

                    Gl.glMatrixMode(Gl.GL_MODELVIEW);
                    Gl.glPushMatrix();
                    Gl.glLoadIdentity();

                    Gl.glScalef(Game.Scale, Game.Scale, 1);

                    Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);

                    GlHelper.SetColor(this.Background.Color.Value);

                    Gl.glBegin(Gl.GL_QUADS);
                    Gl.glVertex3f(DrawArea.Left, DrawArea.Top, 0);
                    Gl.glVertex3f(DrawArea.Right, DrawArea.Top, 0);
                    Gl.glVertex3f(DrawArea.Right, DrawArea.Bottom, 0);
                    Gl.glVertex3f(DrawArea.Left, DrawArea.Bottom, 0);
                    Gl.glEnd();

                    Gl.glColor3f(1, 1, 1);
                    Gl.glPopMatrix();
                }

                if (this.Background.Image.HasValue)
                {
                    string currentImageId = this.Background.Image.Value;

                    if (string.IsNullOrEmpty(lastImageId) || currentImageId != lastImageId)
                    {
                        if (lastTexture != null)
                        {
                            lastTexture.RemoveUser();
                        }

                        lastImageId = currentImageId;
                        lastTexture = Game.TextureManager.GetTexture(this.Background.Image.Value);
                    }

                    lastTexture.Draw(offsetX, offsetY);
                }

                // TODO: Implement background repeat, preferably by cleverly using texture coordinates on the image rendering quad.
                // This is probably impossible for images in tile-sets (and any with custom DrawArea) without the use of shaders.
                // We can either split it in multiple quads (one tile each) - that's quite wasteful, or we can make the TextureManagerItem
                // split the original tile-set into multiple autonomous textures (tile-sets aren't implemented yet anyway)
                if (this.Background.Repeat.GetValueOrDefault(GuiRepeatStyle.NoRepeat) != GuiRepeatStyle.NoRepeat)
                {
                    throw new NotSupportedException("Background repeat not supported yet.");
                }

                foreach (var control in Controls)
                {
                    control.Render(offsetX, offsetY);
                }
            }
            finally
            {
                renderingStack.Pop();
            }
        }