{"id":208221,"date":"2025-07-08T09:12:44","date_gmt":"2025-07-08T01:12:44","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208221\/"},"modified":"2025-07-08T09:12:44","modified_gmt":"2025-07-08T01:12:44","slug":"opengl3-%e4%b8%ad%e7%ba%b9%e7%90%86%e5%a6%82%e4%bd%95%e6%98%be%e7%a4%ba%e4%b8%ba%e5%bd%a9%e8%89%b2%e8%80%8c%e4%b8%8d%e6%98%af%e7%81%b0%e5%ba%a6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208221\/","title":{"rendered":"OpenGL3 \u4e2d\u7eb9\u7406\u5982\u4f55\u663e\u793a\u4e3a\u5f69\u8272\u800c\u4e0d\u662f\u7070\u5ea6\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>OpenGL3 \u4e2d\u7eb9\u7406\u5982\u4f55\u663e\u793a\u4e3a\u5f69\u8272\u800c\u4e0d\u662f\u7070\u5ea6\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-30 14:24: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>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aOpenGL3 \u4e2d\u7eb9\u7406\u5982\u4f55\u663e\u793a\u4e3a\u5f69\u8272\u800c\u4e0d\u662f\u7070\u5ea6\uff1f\u300b\uff0c\u8986\u76d6\u4e86Golang\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u4f7f\u7528 golang \u5f00\u53d1 gui \u7a0b\u5e8f\u3002<\/p>\n<p>\u6211\u6b63\u5728\u4e3a\u6211\u7684 gui \u4f7f\u7528 imgui-go \u6846\u67b6\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u6211\u9047\u5230\u4e86\u989c\u8272\u7eb9\u7406\u663e\u793a\u95ee\u9898\u3002<\/p>\n<p>\u6211\u5df2\u7ecf\u4ece\u6587\u4ef6\u4e2d\u52a0\u8f7d\u4e86\u56fe\u50cf\uff0c\u5e76\u5c06\u56fe\u50cf\u4f5c\u4e3a\u7eb9\u7406\uff0c\u7136\u540e\u9644\u52a0\u5230 gui \u4e0a\u3002<\/p>\n<p>\u56fe\u50cf\u80af\u5b9a\u662f\u5f69\u8272\u7684\uff0c\u4f46\u5b83\u5728 gui \u4e0a\u663e\u793a\u7070\u5ea6\u3002<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u6709\u6700\u597d\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f<\/p>\n<p>\u8c22\u8c22\u3002<\/p>\n<p>opengl \u7247\u6bb5\u7740\u8272\u5668\uff1a<\/p>\n<pre>uniform int imagetype;\nuniform sampler2d texture;\nuniform sampler2d palette;\nin vec2 frag_uv;\nin vec4 frag_color;\nout vec4 out_color;\nvoid main()\n{\n     \n    out_color = vec4(frag_color.rgb, frag_color.a * texture( texture, frag_uv.st).r); \n}<\/pre>\n<p>\u56fe\u50cf\u7eb9\u7406\uff1a<\/p>\n<pre>gl.BindTexture(gl.TEXTURE_2D, texture)\n\nwidth := int32(bm.W)\nheight := int32(bm.H) \ndataPtr := gl.Ptr(bm.Data)\n\ngl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)\ngl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)\ngl.PixelStorei(gl.UNPACK_ROW_LENGTH, 0)\ngl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height),\n    0, gl.RGBA, gl.UNSIGNED_BYTE, dataPtr)<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u6211\u4e0d\u77e5\u9053\u4ec0\u4e48\u662f <code>Frag_Color<\/code> \u4f46\u60a8\u5c06\u5176\u4f5c\u4e3a <code>Frag_Color.rgb<\/code> \u653e\u5165\u8f93\u51fa\u989c\u8272\u4e2d\uff0c\u8fd9\u4f7f\u5f97\u7eb9\u7406\u7684\u989c\u8272\u53d6\u51b3\u4e8e\u5176\u503c\u3002\u60a8\u4ec5\u5c06 <code>Texture<\/code> \u653e\u5165 alpha \u503c\uff0c\u5373\u900f\u660e\u5ea6\/\u53ef\u89c1\u6027\u3002\u8bd5\u8bd5\u8fd9\u4e2a\u4ee3\u7801\uff0c\u5b83\u5e94\u8be5\u53ef\u4ee5\u5de5\u4f5c\uff1a <code>Out_Color = \u7eb9\u7406(Texture, Frag_UV.st);<\/code> \u5982\u679c\u8be5\u4ee3\u7801\u4e0d\u8d77\u4f5c\u7528\uff0c\u60a8\u4e5f\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u64cd\u4f5c\uff1a <code>Out_Color = Frag_Color * \u7eb9\u7406(Texture, Frag_UV.st);<\/code><\/p>\n<p>\u5f88\u62b1\u6b49\u683c\u5f0f\u5316\uff0c\u5f53\u6211\u5728\u624b\u673a\u4e0a\u4e66\u5199\u65f6\u5b83\u6548\u679c\u4e0d\u4f73<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aOpenGL3 \u4e2d\u7eb9\u7406\u5982\u4f55\u663e\u793a\u4e3a\u5f69\u8272\u800c\u4e0d\u662f\u7070\u5ea6\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/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-208221","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208221","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=208221"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208221\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}