用数组中的RGB数据重复填充窗口的最快方法是什么? [英] What's the fastest way to repeatedly fill a window with RGB data from an array?

查看:149
本文介绍了用数组中的RGB数据重复填充窗口的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个简单的游戏.我的图形代码每帧运行一次(每秒约30次),然后将RGB数据写入具有640 * 480 = 307200项的数组.

I'm currently writing a simple game. My graphics code runs once per frame (approximately 30 times per second), and writes RGB data to an array with 640 * 480 = 307200 entries.

我创建了一个Win32窗口,其客户区大小恰好为640 x 480像素.使RGB数据显示在否则为空的窗口中的最快方法是什么?

I have created a Win32 window with a client area exactly 640 x 480 pixels in size. What's the fastest way to get my RGB data displayed within the otherwise-empty window?

该窗口将需要每帧更新一次,因此我需要避免闪烁.我应该为此使用GDI吗?还是有使用其他库(例如DirectDraw)的更快方法?

The window will need to be updated every frame, so I need to avoid flickering. Should I use GDI for this? Or is there a faster approach using a different library - say, DirectDraw?

感谢所有答复.首先,让我排除Direct2D作为选项-我需要支持Windows XP.其次,我有3D背景知识,因此Yann Ramin和Ben Voigtto建议的方法(使用Direct3D/OpenGL和单个纹理四边形)是我过去一直这样做的方式.

Thanks for all the replies. Firstly, let me rule out Direct2D as an option - I need to support Windows XP. Secondly, I have a background in 3D so the method suggested by Yann Ramin and Ben Voigtto - use Direct3D/OpenGL and a single textured quad - is how I've always done this in the past.

但是,我很想知道2D API是否会是更好的解决方案.由于没有明确的答案,因此我编写了一个测试程序.该代码只是尽可能快地在屏幕上重复显示帧缓冲区.

However, I was interested to find out whether a 2D API would be a better solution. Since there has been no definite answer, I threw together a test program. The code simply displays a framebuffer on the screen repeatedly, as fast as possible.

我已将结果发布为推荐答案

使用GDI最好的方法是使用

The best you can do using GDI is use SetDIBitsToDevice to directly copy the RGB data from your array to the window. Of course, DirectX is the way to go if you need to completely eliminate flickering.

这篇关于用数组中的RGB数据重复填充窗口的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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