当前位置: 首页>>代码示例>>C#>>正文


C# RenderWindow.GetFrameTime方法代码示例

本文整理汇总了C#中SFML.Graphics.RenderWindow.GetFrameTime方法的典型用法代码示例。如果您正苦于以下问题:C# RenderWindow.GetFrameTime方法的具体用法?C# RenderWindow.GetFrameTime怎么用?C# RenderWindow.GetFrameTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SFML.Graphics.RenderWindow的用法示例。


在下文中一共展示了RenderWindow.GetFrameTime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create main window
            RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL");
            App.PreserveOpenGLStates(true);

            // Setup event handlers
            App.Closed     += new EventHandler(OnClosed);
            App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            App.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Create a sprite for the background
            Image BackgroundImage = new Image("datas/opengl/background.jpg");
            Sprite Background = new Sprite(BackgroundImage);

            // Create a text to display
            String2D Text = new String2D("This is a rotating cube");
            Text.Position = new Vector2(250.0F, 300.0F);
            Text.Color = new Color(128, 0, 128);

            // Load an OpenGL texture.
            // We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
            // but here we want more control on it (generate mipmaps, ...) so we create a new one
            int Texture = 0;
            using (Image TempImage = new Image("datas/opengl/texture.jpg"))
            {
                Gl.glGenTextures(1, out Texture);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture);
                Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, (int)TempImage.Width, (int)TempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR);
            }

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);
            Gl.glClearDepth(1.0F);

            // Setup a perspective projection
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);

            // Bind our texture
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture);
            Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

            float Time = 0.0F;

            // Start game loop
            while (App.IsOpened())
            {
                // Process events
                App.DispatchEvents();

                // Clear the window
                App.Clear();

                // Draw background
                App.Draw(Background);

                // Clear depth buffer
                Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);

                // Apply some transformations
                Time += App.GetFrameTime();
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(0.0F, 0.0F, -200.0F);
                Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F);
                Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F);
                Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F);

                // Draw a cube
                Gl.glBegin(Gl.GL_QUADS);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F,  50.0F, -50.0F);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F,  50.0F, -50.0F);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, -50.0F);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F,  50.0F, 50.0F);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F,  50.0F, 50.0F);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, 50.0F);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F,  50.0F, -50.0F);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-50.0F,  50.0F,  50.0F);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-50.0F, -50.0F,  50.0F);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(50.0F, -50.0F, -50.0F);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(50.0F,  50.0F, -50.0F);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F,  50.0F,  50.0F);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, -50.0F,  50.0F);

//.........这里部分代码省略.........
开发者ID:freemaul,项目名称:SFML,代码行数:101,代码来源:OpenGL.cs

示例2: Main

        private static void Main(string[] args)
        {
            var form = new SettingsDialog();
            Application.EnableVisualStyles();
            Application.Run(form);
            videoMode = VideoMode.DesktopMode;
            RenderWindow window = new RenderWindow(videoMode, "Maze Crap", Styles.Fullscreen);
            window.EnableVerticalSync(Settings.Default.VerticalSync);
            window.ShowMouseCursor(false);
            window.Closed += (sender, e) => Application.Exit();
            window.KeyPressed += (sender, e) => ((RenderWindow) sender).Close();
            SetUpMaze();
            target = new Image(VideoMode.DesktopMode.Width/10, VideoMode.DesktopMode.Height/10) {Smooth = false};
            float accumulator = 0;
            float WaitTime = 0;
            var fps = (float) Settings.Default.Framerate;
            window.Show(true);
            bool hasrun = false;
            while (window.IsOpened())
            {
                accumulator += window.GetFrameTime();
                while (accumulator > fps)
                {
                    if (FinishedGenerating && !Solving)
                    {
                        if (WaitTime < Settings.Default.WaitTime && hasrun)
                        {
                            WaitTime += window.GetFrameTime();
                        }
                        else
                        {
                            WaitTime = 0;
                            CurrentCell = StartCell*2;
                            VisitedWalls[CurrentCell.X, CurrentCell.Y] = true;
                            CellStack.Clear();
                            Solving = true;
                            hasrun = true;
                        }
                        accumulator -= fps;
                        continue;
                    }
                    if (Solving && FinishedSolving)
                    {
                        if (WaitTime < Settings.Default.WaitTime)
                            WaitTime += window.GetFrameTime();
                        else
                        {
                            Solving = false;
                            FinishedGenerating = false;
                            FinishedSolving = false;
                            SetUpMaze();
                            continue;
                        }
                        continue;
                    }
                    if (Solving && !FinishedSolving)
                    {
                        if (Settings.Default.ShowSolving)
                            FinishedSolving = !SolveIterate(CellStack, Cells, Walls, StartCell, EndCell);
                        else
                        {
                            while (SolveIterate(CellStack, Cells, Walls, StartCell, EndCell)) ;
                            FinishedSolving = true;
                        }
                        accumulator -= fps;
                        continue;
                    }

                    if (Settings.Default.ShowGeneration)
                    {
                        FinishedGenerating = !GenerateIterate(CellStack, Cells, Walls);
                        hasrun = true;
                    }
                    else
                    {
                        while (GenerateIterate(CellStack, Cells, Walls)) ;
                        FinishedGenerating = true;
                    }
                    accumulator -= fps;
                    NeedsRedraw = true;
                }
                Render(window);
                window.Display();
                window.DispatchEvents();
            }
        }
开发者ID:Phyxius,项目名称:Maze-Gen,代码行数:86,代码来源:Program.cs

示例3: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net Shader");

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);

            // Check that the system can use shaders
            if (Shader.IsAvailable == false)
            {
                DisplayError(window);
                return;
            }

            // Create the render image
            RenderImage image = new RenderImage(window.Width, window.Height);

            // Load a background image to display
            Sprite background = new Sprite(new Image("resources/background.jpg"));
            background.Image.Smooth = false;

            // Load a sprite which we'll move into the scene
            Sprite entity = new Sprite(new Image("resources/sprite.png"));

            // Load the text font
            Font font = new Font("resources/arial.ttf");

            // Load the image needed for the wave effect
            Image waveImage = new Image("resources/wave.jpg");

            // Load all effects
            shaders = new Dictionary<string, Shader>();
            shaders["nothing"]  = new Shader("resources/nothing.sfx");
            shaders["blur"]     = new Shader("resources/blur.sfx");
            shaders["colorize"] = new Shader("resources/colorize.sfx");
            shaders["fisheye"]  = new Shader("resources/fisheye.sfx");
            shaders["wave"]     = new Shader("resources/wave.sfx");
            shaders["pixelate"] = new Shader("resources/pixelate.sfx");
            backgroundShader = new ShaderSelector(shaders);
            entityShader     = new ShaderSelector(shaders);
            globalShader     = new ShaderSelector(shaders);

            // Do specific initializations
            shaders["nothing"].SetTexture("texture", Shader.CurrentTexture);
            shaders["blur"].SetTexture("texture", Shader.CurrentTexture);
            shaders["blur"].SetParameter("offset", 0.0F);
            shaders["colorize"].SetTexture("texture", Shader.CurrentTexture);
            shaders["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
            shaders["fisheye"].SetTexture("texture", Shader.CurrentTexture);
            shaders["wave"].SetTexture("texture", Shader.CurrentTexture);
            shaders["wave"].SetTexture("wave", waveImage);
            shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture);

            // Define a string for displaying current effect description
            shaderText = new Text();
            shaderText.Font = font;
            shaderText.Size = 20;
            shaderText.Position = new Vector2(5.0F, 0.0F);
            shaderText.Color = new Color(250, 100, 30);
            shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
                                         "Flower shader: \"" + entityShader.Name + "\"\n" +
                                         "Global shader: \"" + globalShader.Name + "\"\n";

            // Define a string for displaying help
            Text infoText = new Text();
            infoText.Font = font;
            infoText.Size = 20;
            infoText.Position = new Vector2(5.0F, 500.0F);
            infoText.Color = new Color(250, 100, 30);
            infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" +
                                       "Press numpad 1 to change the background shader\n" +
                                       "Press numpad 2 to change the flower shader\n" +
                                       "Press numpad 3 to change the global shader";

            // Start the game loop
            float time = 0.0F;
            while (window.IsOpened())
            {
                // Process events
                window.DispatchEvents();

                // TOFIX -- using window.Input together with image.Draw apparently causes a memory corruption
                // Get the mouse position in the range [0, 1]
                //float x = window.Input.GetMouseX() / (float)window.Width;
                //float y = window.Input.GetMouseY() / (float)window.Height;
                float x = (float)(Math.Cos(time * 1.3) + 1) * 0.5F;
                float y = (float)(Math.Sin(time * 0.8) + 1) * 0.5F;

                // Update the shaders
                backgroundShader.Update(x, y);
                entityShader.Update(x, y);
                globalShader.Update(x, y);

                // Animate the sprite
                time += window.GetFrameTime();
//.........这里部分代码省略.........
开发者ID:vidjogamer,项目名称:ProjectTemplate,代码行数:101,代码来源:Shader.cs

示例4: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL", Styles.Default, new ContextSettings(32, 0));

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Create a sprite for the background
            Image backgroundImage = new Image("resources/background.jpg");
            Sprite background = new Sprite(backgroundImage);

            // Create a text to display
            Text text = new Text("SFML / OpenGL demo");
            text.Position = new Vector2(250.0F, 450.0F);
            text.Color = new Color(255, 255, 255, 170);

            // Load an OpenGL texture.
            // We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
            // but here we want more control on it (generate mipmaps, ...) so we create a new one
            int texture = 0;
            using (Image image = new Image("resources/texture.jpg"))
            {
                Gl.glGenTextures(1, out texture);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
                Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, (int)image.Width, (int)image.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.Pixels);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
                Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR);
            }

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);
            Gl.glClearDepth(1.0F);

            // Setup a perspective projection
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);

            // Bind our texture
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture);
            Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

            float time = 0.0F;

            // Start game loop
            while (window.IsOpened())
            {
                // Process events
                window.DispatchEvents();

                // Clear the window
                window.Clear();

                // Draw background
                window.SaveGLStates();
                window.Draw(background);
                window.RestoreGLStates();

                // Activate the window before using OpenGL commands.
                // This is useless here because we have only one window which is
                // always the active one, but don't forget it if you use multiple windows
                window.SetActive();

                // Clear depth buffer
                Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);

                // We get the position of the mouse cursor, so that we can move the box accordingly
                float x =  window.Input.GetMouseX() * 200.0F / window.Width  - 100.0F;
                float y = -window.Input.GetMouseY() * 200.0F / window.Height + 100.0F;

                // Apply some transformations
                time += window.GetFrameTime();
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(x, y, -100.0F);
                Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F);
                Gl.glRotatef(time * 30, 0.0F, 1.0F, 0.0F);
                Gl.glRotatef(time * 90, 0.0F, 0.0F, 1.0F);

                // Draw a cube
                float size = 20.0F;
                Gl.glBegin(Gl.GL_QUADS);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-size, -size, -size);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-size,  size, -size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( size,  size, -size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( size, -size, -size);

                    Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-size, -size, size);
                    Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-size,  size, size);
                    Gl.glTexCoord2f(1, 1); Gl.glVertex3f( size,  size, size);
                    Gl.glTexCoord2f(1, 0); Gl.glVertex3f( size, -size, size);
//.........这里部分代码省略.........
开发者ID:vidjogamer,项目名称:SFML,代码行数:101,代码来源:OpenGL.cs


注:本文中的SFML.Graphics.RenderWindow.GetFrameTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。