C# 双缓冲?
我正在使用 COSMOS 编译器用 C# 编写操作系统(对于那些不知道 COSMOS 将 IL 代码转换为 x86 程序集的人),并且我正在制作一个 GUI。
我以前制作过 GUI,但现在我正在尝试制作双缓冲区。
听起来很简单,但以下是我的问题 -
我无法使用 System.Drawing 库或任何其他使用 p/ 调用的命名空间中的任何方法。另外,我不能使用多维数组(我可以使用常规数组)。所以我的问题是如何实现双缓冲区?
我知道这是可能的,因为我知道有人做到了。
此外,我唯一拥有的图形函数是 SetPixel
、 GetPixel
和 Clear
。尽管我更喜欢一个答案,但如果有人知道一篇关于双缓冲等的好文章,请告诉我。
附言。我的操作系统分辨率为 320 x 200 哈哈
I am using the COSMOS compiler to write an OS in C# (For those who dont know COSMOS converts IL code into x86 assembly) and I am making a GUI.
I have made GUIs before but now i am trying to make a double buffer.
It sounds rather easy but following is my problem -
I cant use any methods from the System.Drawing
Library or any other namespace that uses p/ invokes. Also, I can not use multi Dimensional arrays (I CAN use regular arrays). So my question is how would I implement double buffer?
I know it is possible because I know someone who did it.
Additionally, the only graphical functions I have are SetPixel
, GetPixel
and Clear
. All though I prefer an answer , if any one knows a good article about double buffering ect please tell me.
PS. My OS in 320 x 200 Res LOL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要学习一点 DOS C VGA 游戏知识,听起来像 ;-)
请参阅 双缓冲、翻页、&无链模式。所有相同的概念都适用,但不确定它们将如何转换为 C# 代码。
快乐编码。
You will need to learn a little bit of DOS C VGA game lore it sounds like ;-)
See Double Buffering, Page Flipping, & Unchained Mode. All the same concepts apply, not sure how they will translate to the C# code though.
Happy coding.
尝试查看是否可以访问System.Drawing.BufferedGraphics。它实现了用于该目的的方法。否则,恐怕你必须手动完成。
通常,当您直接在屏幕上绘图时,用户会在绘制时看到您正在绘制的内容。这就像当你要求亚历克斯给你画一个苹果时;当他用笔画苹果时,你会检查他。现在,如果你让亚历克斯画一个红苹果,然后擦掉它,然后画一个蓝苹果,然后擦掉它,然后画一个黄苹果,等等……当他每次擦掉它时,你都会看着他。可以这样想:计算机是一个快速的亚历克斯。因此,如果您要求直接在屏幕上绘制快速动画,用户将标记动画帧之间正在发生某些事情:糟糕的闪烁!
解决闪烁的方法是双缓冲。缓冲区只是用于绘图的屏幕外内存区域。当您使用双缓冲时,您不是直接绘制到屏幕,而是绘制到位于视频内存中的后台缓冲区,然后将整个缓冲区复制到屏幕。
Try to see if you can access System.Drawing.BufferedGraphics. It implements methods for that purpose. Otherwise, I'm afraid you have to do it manually.
Usually, when you draw directly on the screen, the user sees what you’re drawing as it’s being drawn. It’s like when you ask Alex to draw you an apple; you’ll examine him while he draws the apple with the pen. Now if you ask Alex to draw a red apple, then erase it, then draw a blue apple, then erase it then draw a yellow apple, etc… You’ll be looking at him while he’s erasing it each time. Think of it this way: The computer is a fast Alex. So if you ask for a fast animation to be drawn directly on the screen, the user will mark that something is happening between the animation frames: bad flickering!
The solution to flickering is double buffering. A buffer is simply an off-screen area of memory used for drawing. When you use double buffering, instead of drawing directly to the screen, you draw to a back buffer, located in the video memory, and then copy the entire buffer to the screen.
双缓冲可以通过使用要绘制的数组(而不是显示)以及将数组(完成绘制时)传输到显示来实现。
Double buffering can be implemented by using an array to plot to (as opposed to the display) and by blitting the array (when finished plotting) to the display.