在60 FPS .NET重绘? [英] .NET Redraw at 60 FPS?

查看:121
本文介绍了在60 FPS .NET重绘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在OpenGL上下文窗口中运行一些动画,所以我需要不断地重新绘制。所以,我想出了下面的代码:

I've got some animations running in an OpenGL context window, so I need to constantly redraw it. So I came up with the following code:

    void InitializeRedrawTimer()
    {
        var timer = new Timer();
        timer.Interval = 1000 / 60;
        timer.Tick += new EventHandler(timer_Tick);
        timer.Start();
    }

    void timer_Tick(object sender, EventArgs e)
    {
        glWin.Draw();
    }

这只是给了我40 FPS虽然。但是,如果我时间间隔设置为1毫秒,我能达到60所以哪里的其他20毫秒去了?是,仅仅由于定时器或什么的精度差?如果我想让我的程序运行尽可能快,是有办法,不断调用draw FUNC?

That only gives me 40 FPS though. If I set the interval to 1 ms however, I can achieve 60. So where did the other 20 ms go? Is that just due to poor accuracy of the timer or what? What if I wanted to let my program run as fast as possible, is there a way to continuously call the draw func?

推荐答案

你可以尝试实现游戏循环。

You could try implementing a game loop.

http://blogs.msdn.com/tmiller/archive/2005/05/05/415008.aspx

以下链接介绍了一个使用应用程序的空闲事件。这可能是使用的。你可以简单地进行一点时间测试或睡眠慢下来到你所需的帧。尝试使用System.Diagnostics.StopWatch类最精确的计时器。

This link describes one that uses the application's Idle event. It may be of use. You can simply perform a little time test or sleep to slow it down to your required fps. Try using the System.Diagnostics.StopWatch class for the most accurate timer.

我希望这有助于一点。

这篇关于在60 FPS .NET重绘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆