{"id":2485,"date":"2020-01-03T23:02:16","date_gmt":"2020-01-03T20:02:16","guid":{"rendered":"http:\/\/demensdeum.com\/blog\/?p=2485"},"modified":"2024-12-16T22:32:30","modified_gmt":"2024-12-16T19:32:30","slug":"flipped-world","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/zh\/2020\/01\/03\/flipped-world\/","title":{"rendered":"\u98a0\u5012\u7684\u4e16\u754c"},"content":{"rendered":"<p>\u4e3a\u4e86\u5f00\u53d1\u4e00\u4e2a\u65b0\u9879\u76ee\uff0cCube Art Project \u91c7\u7528\u4e86\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1\u65b9\u6cd5\u3002\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u9996\u5148\u5b9e\u73b0\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u5b9a\u529f\u80fd\u7684\u6d4b\u8bd5\uff0c\u7136\u540e\u518d\u5b9e\u73b0\u8be5\u7279\u5b9a\u529f\u80fd\u3002\u6211\u8ba4\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u7684\u4e00\u5927\u4f18\u70b9\u662f\u6700\u7ec8\u63a5\u53e3\u7684\u5b9e\u73b0\uff0c\u5728\u529f\u80fd\u5f00\u53d1\u5f00\u59cb\u4e4b\u524d\u5c3d\u53ef\u80fd\u4e0d\u6d89\u53ca\u5b9e\u73b0\u7ec6\u8282\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u5f53\u63a5\u53e3\u662f\u7279\u5b9a\u5b9e\u73b0\u7684\u5951\u7ea6\u65f6\uff0c\u6d4b\u8bd5\u6307\u793a\u8fdb\u4e00\u6b65\u7684\u5b9e\u73b0\uff0c\u6dfb\u52a0\u5951\u7ea6\u7f16\u7a0b\u7684\u6240\u6709\u597d\u5904\u3002<br \/>\u7acb\u65b9\u4f53\u827a\u672f\u9879\u76ee&#8211;\u4e00\u79cd 3D \u7f16\u8f91\u5668\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5176\u4e2d\u4ece\u7acb\u65b9\u4f53\u6784\u5efa\u56fe\u5f62\uff1b\u4e0d\u4e45\u524d\uff0c\u8fd9\u79cd\u7c7b\u578b\u975e\u5e38\u6d41\u884c\u3002\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u56fe\u5f62\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u51b3\u5b9a\u6dfb\u52a0\u5e26\u6709\u5c4f\u5e55\u622a\u56fe\u9a8c\u8bc1\u7684\u6d4b\u8bd5\u3002<br \/>\u8981\u9a8c\u8bc1\u5c4f\u5e55\u622a\u56fe\uff0c\u60a8\u9700\u8981\u4ece OpenGL \u4e0a\u4e0b\u6587\u4e2d\u83b7\u53d6\u5b83\u4eec\uff0c\u8fd9\u662f\u4f7f\u7528 glReadPixels \u51fd\u6570\u5b8c\u6210\u7684\u3002\u51fd\u6570\u53c2\u6570\u7684\u63cf\u8ff0\u5f88\u7b80\u5355&#8211;\u8d77\u59cb\u4f4d\u7f6e\u3001\u5bbd\u5ea6\u3001\u9ad8\u5ea6\u3001\u683c\u5f0f\uff08RGB\/RGBA\/\u7b49\uff09\u3001\u6307\u5411\u8f93\u51fa\u7f13\u51b2\u533a\u7684\u6307\u9488\uff1b\u4efb\u4f55\u4f7f\u7528\u8fc7 SDL \u6216\u5177\u6709 C \u6570\u636e\u7f13\u51b2\u533a\u7ecf\u9a8c\u7684\u4eba\u90fd\u53ef\u4ee5\u7b80\u5355\u5730\u66ff\u6362\u5fc5\u8981\u7684\u53c2\u6570\u3002\u7136\u800c\uff0c\u6211\u8ba4\u4e3a\u6709\u5fc5\u8981\u63cf\u8ff0\u4e00\u4e0b glReadPixels \u8f93\u51fa\u7f13\u51b2\u533a\u7684\u4e00\u4e2a\u6709\u8da3\u7684\u529f\u80fd\uff1b\u50cf\u7d20\u4ece\u4e0b\u5230\u4e0a\u5b58\u50a8\u5728\u5176\u4e2d\uff0c\u800c\u5728 SDL_Surface \u4e2d\uff0c\u6240\u6709\u57fa\u672c\u64cd\u4f5c\u90fd\u662f\u4ece\u4e0a\u5230\u4e0b\u53d1\u751f\u7684\u3002<br \/>\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ece png \u6587\u4ef6\u52a0\u8f7d\u53c2\u8003\u5c4f\u5e55\u622a\u56fe\u540e\uff0c\u6211\u65e0\u6cd5\u76f4\u63a5\u6bd4\u8f83\u4e24\u4e2a\u7f13\u51b2\u533a\uff0c\u56e0\u4e3a\u5176\u4e2d\u4e00\u4e2a\u7f13\u51b2\u533a\u662f\u98a0\u5012\u7684\u3002<br \/>\u8981\u4ece OpenGL \u7ffb\u8f6c\u8f93\u51fa\u7f13\u51b2\u533a\uff0c\u60a8\u9700\u8981\u901a\u8fc7\u51cf\u53bb Y \u5750\u6807\u7684\u5c4f\u5e55\u622a\u56fe\u9ad8\u5ea6\u6765\u586b\u5145\u5b83\u3002\u4f46\u662f\uff0c\u503c\u5f97\u8003\u8651\u7684\u662f\uff0c\u5982\u679c\u5728\u586b\u5145\u65f6\u4e0d\u51cf\u53bb\u5b83\uff0c\u5219\u6709\u53ef\u80fd\u8d85\u51fa\u7f13\u51b2\u533a\u9650\u5236\u3002\u5bfc\u81f4\u5185\u5b58\u635f\u574f\u3002<br \/>\u7531\u4e8e\u6211\u603b\u662f\u5c1d\u8bd5\u4f7f\u7528\u201c\u901a\u8fc7\u63a5\u53e3\u7f16\u7a0b\u201d\u7684 OOP \u8303\u4f8b\uff0c\u800c\u4e0d\u662f\u901a\u8fc7\u6307\u9488\u76f4\u63a5\u8fdb\u884c\u7c7b\u4f3c C \u7684\u5185\u5b58\u8bbf\u95ee\uff0c\u56e0\u6b64\u5f53\u6211\u5c1d\u8bd5\u5728\u7f13\u51b2\u533a\u5916\u90e8\u5199\u5165\u6570\u636e\u65f6\uff0c\u7531\u4e8e\u65b9\u6cd5\u4e2d\u7684\u8fb9\u754c\u9a8c\u8bc1\uff0c\u5bf9\u8c61\u4f1a\u901a\u77e5\u6211\u8fd9\u4e00\u70b9.<br \/>\u81ea\u4e0a\u800c\u4e0b\u7684\u622a\u56fe\u65b9\u6cd5\u6700\u7ec8\u4ee3\u7801\uff1a<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>    auto width = params->width;\n    auto height = params->height;\n\n    auto colorComponentsCount = 3;\n    GLubyte *bytes = (GLubyte *)malloc(colorComponentsCount * width * height);\n    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, bytes);\n\n    auto screenshot = make_shared<Screenshot>(width, height);\n\n    for (auto y = 0; y < height; y++) {\n        for (auto x = 0; x < width; x++) {\n            auto byteX = x * colorComponentsCount;\n            auto byteIndex = byteX + (y * (width * colorComponentsCount));\n            auto redColorByte = bytes[byteIndex];\n            auto greenColorByte = bytes[byteIndex + 1];\n            auto blueColorByte = bytes[byteIndex + 2];\n            auto color = make_shared<Color>(redColorByte, greenColorByte, blueColorByte, 255);\n            screenshot->setColorAtXY(color, x, height - y - 1);\n        }\n    }\n\n    free(bytes);\n\n<\/code><\/pre>\n<\/div>\n<h3>\u6765\u6e90<\/h3>\n<p><a href=\"https:\/\/community.khronos.org\/t\/glreadpixels-fliped-image\/26561\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/community.khronos.org\/ t\/glreadpixels-fliped-image\/26561<\/a><br \/><a href=\"https:\/\/stackoverflow.com\/questions\/8346115\/why-are-bmps-stored-upside-down\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/stackoverflow.com\/questions\/8346115\/why-are-bmps-stored-upside-down<\/a><\/p>\n<h3>\u6e90\u4ee3\u7801<\/h3>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/cube-art-project-bootstrap\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/gitlab.com\/demensdeum\/cube-\u827a\u672f\u9879\u76ee\u5f15\u5bfc<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u5f00\u53d1\u4e00\u4e2a\u65b0\u9879\u76ee\uff0cCube Art Project \u91c7\u7528\u4e86\u6d4b\u8bd5\u9a71\u52a8\u5f00\u53d1\u65b9\u6cd5\u3002\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u9996\u5148\u5b9e\u73b0\u5bf9\u5e94\u7528\u7a0b\u5e8f\u7684\u7279\u5b9a\u529f\u80fd\u7684\u6d4b\u8bd5\uff0c\u7136\u540e\u518d\u5b9e\u73b0\u8be5\u7279\u5b9a\u529f\u80fd\u3002\u6211\u8ba4\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u7684\u4e00\u5927\u4f18\u70b9\u662f\u6700\u7ec8\u63a5\u53e3\u7684\u5b9e\u73b0\uff0c\u5728\u529f\u80fd\u5f00\u53d1\u5f00\u59cb\u4e4b\u524d\u5c3d\u53ef\u80fd\u4e0d\u6d89\u53ca\u5b9e\u73b0\u7ec6\u8282\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u5f53\u63a5\u53e3\u662f\u7279\u5b9a\u5b9e\u73b0\u7684\u5951\u7ea6\u65f6\uff0c\u6d4b\u8bd5\u6307\u793a\u8fdb\u4e00\u6b65\u7684\u5b9e\u73b0\uff0c\u6dfb\u52a0\u5951\u7ea6\u7f16\u7a0b\u7684\u6240\u6709\u597d\u5904\u3002\u7acb\u65b9\u4f53\u827a\u672f\u9879\u76ee&#8211;\u4e00\u79cd 3D \u7f16\u8f91\u5668\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5176\u4e2d\u4ece\u7acb\u65b9\u4f53\u6784\u5efa\u56fe\u5f62\uff1b\u4e0d\u4e45\u524d\uff0c\u8fd9\u79cd\u7c7b\u578b\u975e\u5e38\u6d41\u884c\u3002\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u56fe\u5f62\u5e94\u7528\u7a0b\u5e8f\uff0c\u6211\u51b3\u5b9a\u6dfb\u52a0\u5e26\u6709\u5c4f\u5e55\u622a\u56fe\u9a8c\u8bc1\u7684\u6d4b\u8bd5\u3002\u8981\u9a8c\u8bc1\u5c4f\u5e55\u622a\u56fe\uff0c\u60a8\u9700\u8981\u4ece OpenGL \u4e0a\u4e0b\u6587\u4e2d\u83b7\u53d6\u5b83\u4eec\uff0c\u8fd9\u662f\u4f7f\u7528 glReadPixels \u51fd\u6570\u5b8c\u6210\u7684\u3002\u51fd\u6570\u53c2\u6570\u7684\u63cf\u8ff0\u5f88\u7b80\u5355&#8211;\u8d77\u59cb\u4f4d\u7f6e\u3001\u5bbd\u5ea6\u3001\u9ad8\u5ea6\u3001\u683c\u5f0f\uff08RGB\/RGBA\/\u7b49\uff09\u3001\u6307\u5411\u8f93\u51fa\u7f13\u51b2\u533a\u7684\u6307\u9488\uff1b\u4efb\u4f55\u4f7f\u7528\u8fc7 SDL \u6216\u5177\u6709 C \u6570\u636e\u7f13\u51b2\u533a\u7ecf\u9a8c\u7684\u4eba\u90fd\u53ef\u4ee5\u7b80\u5355\u5730\u66ff\u6362\u5fc5\u8981\u7684\u53c2\u6570\u3002\u7136\u800c\uff0c\u6211\u8ba4\u4e3a\u6709\u5fc5\u8981\u63cf\u8ff0\u4e00\u4e0b glReadPixels \u8f93\u51fa\u7f13\u51b2\u533a\u7684\u4e00\u4e2a\u6709\u8da3\u7684\u529f\u80fd\uff1b\u50cf\u7d20\u4ece\u4e0b\u5230\u4e0a\u5b58\u50a8\u5728\u5176\u4e2d\uff0c\u800c\u5728 SDL_Surface \u4e2d\uff0c\u6240\u6709\u57fa\u672c\u64cd\u4f5c\u90fd\u662f\u4ece\u4e0a\u5230\u4e0b\u53d1\u751f\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ece png \u6587\u4ef6\u52a0\u8f7d\u53c2\u8003\u5c4f\u5e55\u622a\u56fe\u540e\uff0c\u6211\u65e0\u6cd5\u76f4\u63a5\u6bd4\u8f83\u4e24\u4e2a\u7f13\u51b2\u533a\uff0c\u56e0\u4e3a\u5176\u4e2d\u4e00\u4e2a\u7f13\u51b2\u533a\u662f\u98a0\u5012\u7684\u3002\u8981\u4ece OpenGL \u7ffb\u8f6c\u8f93\u51fa\u7f13\u51b2\u533a\uff0c\u60a8\u9700\u8981\u901a\u8fc7\u51cf\u53bb Y \u5750\u6807\u7684\u5c4f\u5e55\u622a\u56fe\u9ad8\u5ea6\u6765\u586b\u5145\u5b83\u3002\u4f46\u662f\uff0c\u503c\u5f97\u8003\u8651\u7684\u662f\uff0c\u5982\u679c\u5728\u586b\u5145\u65f6\u4e0d\u51cf\u53bb\u5b83\uff0c\u5219\u6709\u53ef\u80fd\u8d85\u51fa\u7f13\u51b2\u533a\u9650\u5236\u3002\u5bfc\u81f4\u5185\u5b58\u635f\u574f\u3002\u7531\u4e8e\u6211\u603b\u662f\u5c1d\u8bd5\u4f7f\u7528\u201c\u901a\u8fc7\u63a5\u53e3\u7f16\u7a0b\u201d\u7684 OOP \u8303\u4f8b\uff0c\u800c\u4e0d\u662f\u901a\u8fc7\u6307\u9488\u76f4\u63a5\u8fdb\u884c\u7c7b\u4f3c C \u7684\u5185\u5b58\u8bbf\u95ee\uff0c\u56e0\u6b64\u5f53\u6211\u5c1d\u8bd5\u5728\u7f13\u51b2\u533a\u5916\u90e8\u5199\u5165\u6570\u636e\u65f6\uff0c\u7531\u4e8e\u65b9\u6cd5\u4e2d\u7684\u8fb9\u754c\u9a8c\u8bc1\uff0c\u5bf9\u8c61\u4f1a\u901a\u77e5\u6211\u8fd9\u4e00\u70b9.\u81ea\u4e0a\u800c\u4e0b\u7684\u622a\u56fe\u65b9\u6cd5\u6700\u7ec8\u4ee3\u7801\uff1a auto width = params->width; auto height = params->height; auto colorComponentsCount = 3; GLubyte *bytes = (GLubyte *)malloc(colorComponentsCount * width * height); glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE,<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/zh\/2020\/01\/03\/flipped-world\/\">Continue reading <span class=\"screen-reader-text\">&#8220;\u98a0\u5012\u7684\u4e16\u754c&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[143,142,76],"class_list":["post-2485","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","tag-cube-art-project","tag-glreadpixels","tag-opengl","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"zh","enabled_languages":["en","ru","zh","de","fr","ja","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":false,"content":false,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/posts\/2485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/comments?post=2485"}],"version-history":[{"count":11,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/posts\/2485\/revisions"}],"predecessor-version":[{"id":3925,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/posts\/2485\/revisions\/3925"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/media?parent=2485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/categories?post=2485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/zh\/wp-json\/wp\/v2\/tags?post=2485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}