{"id":208267,"date":"2025-07-08T15:24:38","date_gmt":"2025-07-08T07:24:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208267\/"},"modified":"2025-07-08T15:24:38","modified_gmt":"2025-07-08T07:24:38","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8golang%e5%ba%93%e4%b8%ad%e7%9a%84%e5%9b%9e%e8%b0%83%e5%87%bd%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208267\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528golang\u5e93\u4e2d\u7684\u56de\u8c03\u51fd\u6570\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5982\u4f55\u4f7f\u7528golang\u5e93\u4e2d\u7684\u56de\u8c03\u51fd\u6570\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-30 23:09:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528golang\u5e93\u4e2d\u7684\u56de\u8c03\u51fd\u6570\uff1f\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u5bf9 go \u8fd8\u6bd4\u8f83\u964c\u751f\uff0c\u6211\u51b3\u5b9a\u5c1d\u8bd5\u4e00\u4e9b opengl\uff0c\u56e0\u4e3a\u5b58\u5728\u4e00\u4e2a\u4e3a\u6b64\u63d0\u4f9b\u7ed1\u5b9a\u7684 go \u5e93\u3002\u4f5c\u4e3a\u8bbe\u7f6e opengl \u7684\u4e00\u90e8\u5206\uff0c\u6211\u9700\u8981\u4f7f\u7528 go glfw \u5e93\u3002\u6211\u9700\u8981\u4f7f\u7528glfw\u5e93\u51fd\u6570setframebuffersizecallback\uff0c\u5b83\u9700\u8981\u4e00\u4e2aframebuffersizecallback\u7c7b\u578b\u7684\u53c2\u6570\uff1b\u6240\u4ee5\u6211\u672c\u8d28\u4e0a\u9700\u8981\u4f20\u9012\u4e00\u4e2a\u4e0e\u8be5\u7c7b\u578b\u7684\u7b7e\u540d\u5339\u914d\u7684\u51fd\u6570\uff0c\u6211\u76f8\u4fe1\u6211\u5df2\u7ecf\u5b8c\u6210\u4e86\u3002\u4f46\u662f\uff0c\u6211\u4e0d\u65ad\u6536\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n<p> .\/main.go:43:35\uff1a\u65e0\u6cd5\u5728 window.setframebuffersizecallback \u7684\u53c2\u6570\u4e2d\u4f7f\u7528 fbcallback \uff08\u7c7b\u578b func(*glfw.window, int32, int32)) \u4f5c\u4e3a\u7c7b\u578b glfw.framebuffersizecallback <\/p>\n<p>\u6211\u771f\u7684\u4e0d\u786e\u5b9a\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002\u6211\u5df2\u7ecf\u68c0\u67e5\u8fc7\u6211\u7684 glfw \u7248\u672c\u662f\u5426\u4e0e\u6587\u6863\u5339\u914d\uff1b\u6211\u68c0\u67e5\u4e86github\u4e0a\u7684\u5b9e\u73b0\u4ee3\u7801\u548c\u6211\u7684\u673a\u5668\uff0c\u5b83\u90fd\u662f\u4e00\u81f4\u7684\u3002\u6240\u4ee5\u6211\u4e0d\u77e5\u9053\u6211\u505a\u9519\u4e86\u4ec0\u4e48\u3002\u8fd9\u662f\u6211\u7684\u4ee3\u7801\uff0c\u5982\u679c\u6784\u5efa\u5b83\u4e0d\u5e94\u8be5\u505a\u4efb\u4f55\u6709\u8da3\u7684\u4e8b\u60c5\uff0c\u4f46\u4f1a\u6f14\u793a\u9519\u8bef\uff1a<\/p>\n<pre>package main\n\nimport (\n    \"github.com\/go-gl\/gl\/v3.3-core\/gl\"\n    \"github.com\/go-gl\/glfw\/v3.2\/glfw\"\n    \"log\"\n    \"runtime\"\n)\n\nfunc fbcallback(window *glfw.window, width int32, height int32) {\n    gl.viewport(0, 0, width, height)\n}\n\nfunc init() {\n    runtime.lockosthread()\n}\n\nfunc main() {\n    err := glfw.init()\n    if err != nil {\n        panic(err)\n    }\n\n    defer glfw.terminate()\n\n    glfw.windowhint(glfw.contextversionmajor, 3)\n    glfw.windowhint(glfw.contextversionminor, 3)\n    glfw.windowhint(glfw.openglprofile, glfw.openglcoreprofile)\n\n    window, err := glfw.createwindow(640, 480, \"testing\", nil, nil)\n\n    if err != nil {\n        panic(err)\n    }\n\n    window.makecontextcurrent()\n\n    if err := gl.init(); err != nil {\n        log.fatalln(err)\n    }\n\n    gl.viewport(0, 0, 800, 600)\n    window.setframebuffersizecallback(fbcallback) \/\/does not work\n}<\/pre>\n<p>\u6211\u5bf9\u5b83\u5e94\u8be5\u5982\u4f55\u771f\u6b63\u5de5\u4f5c\u7684\u7406\u89e3\u5728\u4e0b\u9762\u7684\u7b80\u77ed\u7a0b\u5e8f\u4e2d\u5f97\u5230\u4e86\u8bc1\u660e\uff0c\u8be5\u7a0b\u5e8f\u6709\u6548\u3002\u6211\u5f88\u9ad8\u5174\u6709\u4eba\u6307\u51fa\u4e3a\u4ec0\u4e48\u8fd9\u4e2a\u7b80\u77ed\u7684\u793a\u4f8b\u6709\u6548\u800c\u4e0a\u9762\u7684\u793a\u4f8b\u65e0\u6548\u3002\u6211\u7684\u7406\u89e3\u53ef\u80fd\u6709\u4e00\u4e9b\u6f0f\u6d1e\u3002<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n)\n\ntype callback func(int, int) int\n\nfunc sum(x int, y int) int {\n    return x + y\n}\n\nfunc useCallback(cb callback) {\n    result := cb(2, 3)\n    fmt.Println(result)\n}\n\nfunc main() {\n    useCallback(sum)\n}<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<pre>type framebuffersizecallback func(w *window, width int, height int)<\/pre>\n<p>\u5bf9\u6bd4<\/p>\n<pre>func fbCallback(window *glfw.Window, width int32, height int32)<\/pre>\n<p>\u60a8\u7684\u51fd\u6570\u6ca1\u6709\u76f8\u540c\u7684\u7b7e\u540d\uff0c\u5b83\u4f7f\u7528 int32 \u800c\u4e0d\u662f int\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u4f7f\u7528golang\u5e93\u4e2d\u7684\u56de\u8c03\u51fd\u6570\uff1f\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-208267","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208267"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208267\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}