Beispiel #1
0
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="SdlDotNet.Core.TickEventArgs"/> instance containing the event data.</param>
        public override void Tick(object sender, SdlDotNet.Core.TickEventArgs e)
        {
            base.Tick(sender, e);

            Gl.glViewport(0, 0, BackbufferWidth, BackbufferHeight);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluOrtho2D(0, BackbufferWidth, BackbufferHeight, 0);

            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            // render the current game screen
            GameScreenManager.CurrentGameScreen.Render();

            // render the FPS
            VariableManager.SetVariable("FPS", e.Fps);
            // Video.Screen.Blit(FontManager.DrawText("fntMain", e.Fps.ToString(), Color.Yellow), new Point(100, 20));


            // render the mouse cursor
            cursor.Draw(MouseX - cursor.RealSize.Width / 2, MouseY - cursor.RealSize.Height / 2);

            Gl.glFlush();

            Video.GLSwapBuffers();
        }
Beispiel #2
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();
            }
        }