如何将列表绘制到Pygame的屏幕上?

发布于 2025-01-29 11:55:52 字数 161 浏览 3 评论 0原文

我正在编写一个程序,该程序在OpenGL着色器中计算一些像素内容。通过该计算,我获得了一个包含需要写入屏幕的每个像素的列表。有没有办法一次绘制所有这些数据,而不是迭代列表并绘制每个像素?我之所以问这个,是因为在列表中迭代包含我屏幕的所有百分比并单独将这些像素写入屏幕的列表非常慢。任何帮助都将不胜感激。谢谢。

I'm writing a program that calculates some pixel stuff in an OpenGL shader. With that calculation, I get a list containing every pixel that needs to be written to the screen. Is there a way I can draw all of this data at once rather than iterating through the list and drawing every pixel? I ask this because it would be extremely slow to iterate through the list that contains all the million pixels for my screen and individually write these pixels to the screen. Any help would be much appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2025-02-05 11:55:52

参阅如何将Pygame场景保存为jpeg?

请 颜色数据在帧缓冲器中,您可以使用代码> 在更新显示之前(pygame.display.flip()pygame.display.update())。使用 pygame> pygame.image.image.image.fromstring() >要从缓冲区创建新表面

size = screen.get_size()
buffer = glReadPixels(0, 0, *size, GL_RGBA, GL_UNSIGNED_BYTE)
pygame.display.flip()
screen_surf = pygame.image.fromstring(buffer, size, "RGBA")

如果数据在纹理中(例如存储在计算着色器中),则可以使用

image_buffer = glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE)
image_surf = pygame.image.fromstring(image_buffer, (width, height), "RGBA")

See How to save pygame scene as jpeg?

If the color data is in the framebuffer you can read it with glReadPixels before the display is updated (before pygame.display.flip() or pygame.display.update()). Use pygame.image.fromstring() to create new Surfaces from the buffer:

size = screen.get_size()
buffer = glReadPixels(0, 0, *size, GL_RGBA, GL_UNSIGNED_BYTE)
pygame.display.flip()
screen_surf = pygame.image.fromstring(buffer, size, "RGBA")

If the data is in a texture (e.g. stored in a compute shader) you can read it with glGetTexImage:

image_buffer = glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE)
image_surf = pygame.image.fromstring(image_buffer, (width, height), "RGBA")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文