为了账号安全,请及时绑定邮箱和手机立即绑定

Golang OpenGL线在Linux上绘制,但在Windows10上不绘制

Golang OpenGL线在Linux上绘制,但在Windows10上不绘制

Go
一只斗牛犬 2023-07-10 18:02:09
我使用用 Golang 编写的相同 OpenGL 代码在 640x480 像素空间中绘制两条线。我很困惑,因为在 Linux 中两条线都正确绘制,但在 Windows10 中只绘制了其中一条。是什么导致了 OpenGL 行为的差异?第 1 行:0,0 - 639,479(仅适用于 Linux)第 2 行:50,0 - 0,50(适用于 Linux 和 Windows10)在 Linux 上,两条线都正确绘制:来自 Linux 的应用程序日志:2019/08/15 02:44:12 requesting window for OpenGL 3.32019/08/15 02:44:12 graphicsStart(9): 640 x 4802019/08/15 02:44:12 OpenGL version 3.3 (Core Profile) Mesa 18.2.82019/08/15 02:44:12 OpenGL program: 32019/08/15 02:44:12 pixelToClip: 0 x 0 => -1.000000 x 1.0000002019/08/15 02:44:12 pixelToClip: 639 x 479 => 1.000000 x -1.0000002019/08/15 02:44:12 pixelToClip: 50 x 0 => -0.843506 x 1.0000002019/08/15 02:44:12 pixelToClip: 0 x 50 => -1.000000 x 0.791232在Windows10上,只绘制第二行:Windows10 的应用程序日志:2019/08/15 18:41:19 requesting window for OpenGL 3.32019/08/15 18:41:19 graphicsStart(9): 640 x 4802019/08/15 18:41:19 OpenGL version 3.3.0 - Build 21.20.16.46272019/08/15 18:41:19 OpenGL program: 32019/08/15 18:41:19 pixelToClip: 0 x 0 => -1.000000 x 1.0000002019/08/15 18:41:19 pixelToClip: 639 x 479 => 1.000000 x -1.0000002019/08/15 18:41:19 pixelToClip: 50 x 0 => -0.843506 x 1.0000002019/08/15 18:41:19 pixelToClip: 0 x 50 => -1.000000 x 0.791232这是该应用程序的完整源代码:$ cat a.go// # recipe for running a.go (Go 1.11 or higher)// mkdir tmp                                    ;# create dir for module// cp a.go tmp                                  ;# put app in dir// cd tmp                                       ;# enter dir// go mod init tmp                              ;# init module// go get -u github.com/udhos/basgo@mainthread  ;# get lib from branch mainthread// go run a.go                                  ;# runpackage mainimport (        "github.com/faiface/mainthread"        "github.com/udhos/basgo/baslib")func main() {        mainthread.Run(run)}函数 baslib.Line() 是负责绘制的主要部分,可在此处使用:https://github.com/udhos/basgo/blob/mainthread/baslib/graphics.go#L269
查看完整描述

1 回答

?
米脂

TA贡献1836条经验 获得超3个赞

实际上,我认为问题比我最初想象的要简单:每次绘制一条线时,您都在调用 window.SwapBuffers() ,而实际上您应该在一帧末尾调用它一次。

现代系统上的缓冲区交换意味着“在显示器上显示帧缓冲区的当前内容,并为我提供一个新的屏幕外缓冲区来绘制”。没有定义这个新的离屏缓冲区是否为空,因为 OpenGL 标准无论如何都会调用 glClear。在我的双启动笔记本电脑上进行的快速 C 测试对于 Linux 和 MS Windows确实有不同的行为。

因此,您的程序绘制第一行,交换缓冲区,绘制第二行,再次交换缓冲区。在我看来,Linux 实现似乎保留了帧缓冲区内容,因此当绘制第二行时,第一行仍然存在。在 MS Windows 上,我猜想新的帧缓冲区已被清除,因此第一行被非常非常短暂地“显示”,然后被第二个帧缓冲区覆盖,仅显示第二行。


查看完整回答
反对 回复 2023-07-10
  • 1 回答
  • 0 关注
  • 82 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信