{"id":3836,"date":"2018-03-02T00:16:10","date_gmt":"2018-03-01T16:16:10","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=3836"},"modified":"2018-10-14T21:22:41","modified_gmt":"2018-10-14T13:22:41","slug":"opengl_mipmap","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/opengl_mipmap\/","title":{"rendered":"OpenGL\u4e4b\u7d0b\u7406\u6620\u5c04\u4f7f\u7528mipmap"},"content":{"rendered":"<figure id=\"attachment_3837\" aria-describedby=\"caption-attachment-3837\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_mipmap.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3837\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_mipmap.jpg\" alt=\"\" width=\"1024\" height=\"768\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_mipmap.jpg 1024w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_mipmap-300x225.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_mipmap-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-3837\" class=\"wp-caption-text\">OpenGL\u4e4b\u7d0b\u7406\u6620\u5c04\u4f7f\u7528mipmap<\/figcaption><\/figure>\n<p>\u7d0b\u7406\u7e6a\u756b\u591a\u908a\u5f62\u7576\u9060\u96e2\u8996\u9ede,\u6703\u51fa\u73fe\u8996\u89ba\u5931\u771f\u6216\u70ab\u76ee\u554f\u984c,\u539f\u56e0\u662fOpenGL\u5c0d\u5169\u500b\u76f8\u9130\u7684\u50cf\u7d20\u9032\u884c\u91c7\u6a23\u6642,\u5f9e\u7d0b\u7406\u5716\u4e2d\u7684\u4e00\u4e9b\u5dee\u5225\u8f03\u5927\u7684\u90e8\u5206\u9032\u884c\u91c7\u6a23\u6240\u7522\u751f\u7684,\u5728\u975c\u6b62\u5834\u666f\u554f\u984c\u4e26\u4e0d\u660e\u986f,\u82e5\u904b\u52d5\u6642\u7d0b\u7406\u7d0b\u7406\u91c7\u6a23\u767c\u751f\u6539\u8b8a\u6642\u70ab\u76ee\u554f\u984c\u5c07\u6703\u66f4\u7279\u51fa,\u4f7f\u7528mipmap\u300e\u7d0b\u7406\u93c8\u300f\u80fd\u6d88\u9664\u90e8\u5206\u5931\u771f,\u56e0\u70ba\u4f4e\u89e3\u91cb\u5ea6\u7684\u7d0b\u7406\u88ab\u61c9\u7528\u5230\u9060\u8ddd\u96e2\u7684\u591a\u908a\u5f62\u4e0a\u6642\u91c7\u6a23\u66f4\u52a0\u7cbe\u51c6.\u56e0\u70ba\u7d0b\u7406\u4e00\u7d1a\u7d1a\u7e2e\u5c0f\u6642\u7d0b\u7406\u53ef\u4ee5\u4fdd\u6301\u5e73\u6ed1,\u4f7f\u7528mipmap\u300e\u7d0b\u7406\u93c8\u300f\u7684\u53e6\u4e00\u500b\u597d\u8655\u662f\u8f03\u5c0f\u7684\u7d0b\u7406\u66f4\u5bb9\u6613\u4fdd\u5b58\u5728\u986f\u5361\u300e\u8a18\u61b6\u9ad4\u300f\u4e2d\u63d0\u9ad8\u547d\u4e2d\u7387.<\/p>\n<p>OpenGL\u7684gluBuild2DMipmaps()\u53ef\u4ee5\u5168\u81ea\u52d5\u7684\u751f\u6210mipmap\u300e\u7d0b\u7406\u93c8\u300f.\u4f46\u4e0d\u4eff\u81ea\u5df2\u52d5\u624b\u751f\u6210.<\/p>\n<p>mipmap\u300e\u7d0b\u7406\u93c8\u300f\u6f14\u793a\u7a0b\u5f0f<a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGLMipmap.zip\">\u4e0b\u8f09<\/a>:<\/p>\n<ol>\n<li>\u6309M\u9375\u53ef\u5207\u63db\u300e\u7d0b\u7406\u93c8\u300f\u555f\u7528\u8207\u7981\u7528,\u7576\u555f\u7528\u6642\u70ab\u76ee\u5931\u771f\u5c07\u5927\u526f\u6e1b\u5c0f.<\/li>\n<li>\u6309ESC\u9375\u76f8\u6a5f\u8fd4\u56de\u539f\u9ede.<\/li>\n<li>\u6309\u65b9\u5411\u9375\u79fb\u52d5\u76f8\u6a5f<\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_texture\/\">\u7d0b\u7406\u7d50\u69cb\u5b9a\u7fa9\u53ef\u68af\u300eOpenGL\u4e4b\u7d0b\u7406\u6620\u5c04\u300f<\/a>OpenGL\u6839\u64da\u76ee\u6a19\u5716\u50cf\u7684\u5927\u5c0f\u9078\u64c7\u7d0b\u7406\u5716\u50cf,\u300e\u7d0b\u7406\u93c8\u300f\u7d22\u5f15\u5f9e0\u958b\u59cb\u5230\u5206\u8fa8\u73871*1 \u7d50\u675f,\u6240\u4ee5\u4f60\u8981\u5c0d\u7d0b\u7406\u8fd1\u884c\u7e2e\u5c0f:<\/p>\n<p>&nbsp;<\/p>\n<p>\u751f\u6210\u7d0b\u7406\u93c8\u4ee3\u78bc<\/p>\n<p>1.\u4e0d\u65b7\u7e2e\u5c0f\u7d0b\u7406\u5716,\u76f4\u5230\u5206\u8fa8\u73871*1<\/p>\n<p>while (width != 1 &amp;&amp; height != 1){<\/p>\n<p>2.\u7372\u53d6\u7d22\u5f15<\/p>\n<p>index = texture-&gt;count;<\/p>\n<p>3.\u7e2e\u5c0f\u7d0b\u7406<\/p>\n<p>texture-&gt;image[index] = Decrease_Image_Texture(texture-&gt;image[index-1], width, height);<\/p>\n<p>4.\u7d0b\u7406\u500b\u6578\u52a0\u4e00<\/p>\n<p>++texture-&gt;count;<\/p>\n<p>5.\u5bec\u8207\u9ad8\u6e1b\u4e00\u534a<\/p>\n<p>width = width \/ 2;<\/p>\n<p>height = height \/ 2;<\/p>\n<p>}<\/p>\n<p>\u7d0b\u7406\u5716\u50cf\u7684\u5bec\u548c\u9ad8\u5747\u7e2e\u5c0f\u4e00\u534a\u7684\u51fd\u5f0f<\/p>\n<p>image:\u7d0b\u7406\u5716<\/p>\n<p>width,height:\u5bec\u548c\u9ad8<\/p>\n<p>PBYTE Decrease_Image_Texture(PBYTE image,int width,int height){<\/p>\n<p>int r1,r2,r3,r4, g1,g2,g3,g4, b1,b2,b3,b4 ;<\/p>\n<p>int index,x,y;<\/p>\n<p>\/\/\u5206\u914d\u7e2e\u5c0f\u7d0b\u7406\u8a18\u61b6\u9ad4<\/p>\n<p>buffer = (PBYTE)malloc(width\/2 * height\/2 * 3);<\/p>\n<p>for (y = 0; y &lt; height; y = y + 2) \/\/\u904d\u6b77Y\u5ea7\u6a19<\/p>\n<p>{<\/p>\n<p>for (x = 0; x &lt; width; x = x + 2)\/\/\u904d\u6b77X\u5ea7\u6a19<\/p>\n<p>{<\/p>\n<p>index = Get_Index_Texture(x, y, 0, 0, width, height) * 3;\/\/ \u63d0\u53d6\u7d0b\u7406\u50cf\u7d20<\/p>\n<p>r1 = image[index + 0];<\/p>\n<p>g1 = image[index + 1];<\/p>\n<p>b1 = image[index + 2];<\/p>\n<p>index = Get_Index_Texture(x, y, 1, 0, width, height) * 3;\/\/ \u63d0\u53d6\u7d0b\u7406\u50cf\u7d20<\/p>\n<p>r2 = image[index + 0];<\/p>\n<p>g2 = image[index + 1];<\/p>\n<p>b2 = image[index + 2];<\/p>\n<p>index = Get_Index_Texture(x, y, 0, 1, width, height) * 3;\/\/ \u63d0\u53d6\u7d0b\u7406\u50cf\u7d20<\/p>\n<p>r3 = image[index + 0];<\/p>\n<p>g3 = image[index + 1];<\/p>\n<p>b3 = image[index + 2];<\/p>\n<p>index = Get_Index_Texture(x, y, 1, 1, width, height) * 3; \/\/\u63d0\u53d6\u7d0b\u7406\u50cf\u7d20<\/p>\n<p>r4 = image[index + 0];<\/p>\n<p>g4 = image[index + 1];<\/p>\n<p>b4 = image[index + 2];<\/p>\n<p>index = (y\/2 * width\/2 + x\/2) * 3;<\/p>\n<p>\/\/\u52a0\u6b0a\u5e73\u5747\u8a08\u7b97\u76ee\u6a19\u7d0b\u7406\u50cf\u7d20<\/p>\n<p>buffer[index + 0] = (r1 + r2 + r3 + r4) \/ 4;<\/p>\n<p>buffer[index + 1] = (g1 + g2 + g3 + g4) \/ 4;<\/p>\n<p>buffer[index + 2] = (b1 + b2 + b3 + b4) \/ 4;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\u8a08\u7b97\u7d0b\u7406\u50cf\u7d20\u7d22\u5f15\u51fd\u5f0f<\/p>\n<p>x,y:\u5ea7\u6a19<\/p>\n<p>dx,dy:\u5ea7\u6a19\u589e\u91cf<\/p>\n<p>wdith,height:\u7d0b\u7406\u5716\u7684\u5bec\u548c\u9ad8<\/p>\n<p>int Get_Index_Texture(int x, int y, int dx, int dy, int width, int height) {<\/p>\n<p>if (x + dx &gt;= width) \/\/\u5224\u65b7x\u5ea7\u6a19\u662f\u5426\u8d8a\u754c<\/p>\n<p>dx = 0;<\/p>\n<p>if (y + dy &gt;= height) \/\/\u5224\u65b7y\u5ea7\u6a19\u662f\u5426\u8d8a\u754c<\/p>\n<p>dy = 0;<\/p>\n<p>int index = (y + dy) * width + (x + dx);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u8a08\u7b97\u7d0b\u7406\u50cf\u7d20\u7d22\u5f15<\/p>\n<p>return index;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u8fd4\u56de\u7d22\u5f15<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\u7d81\u5b9amipmap\u300e\u7d0b\u7406\u93c8\u300f\u4ee3\u78bc\u51fd\u5f0f<\/p>\n<p>bool Bind_Texture(TEXTURE_PTR texture){<\/p>\n<p>glGenTextures(1, &amp;texture-&gt;ID);\/\/\u751f\u6210\u7d0b\u7406<\/p>\n<p>glBindTexture(GL_TEXTURE_2D, texture-&gt;ID);\/\/\u7d81\u5b9a\u7d0b\u7406<\/p>\n<p>glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\/\/ \u91cd\u8907\u7d0b\u7406<\/p>\n<p>glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\/\/ \u91cd\u8907\u7d0b\u7406<\/p>\n<p>glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\/\/\u653e\u5927\u7d0b\u7406\u50cf\u7d20\u63a1\u6a23\u7dda\u6027\u63d2\u503c(\u52a0\u6b0a\u5e73\u5747)<\/p>\n<p>glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);\/\/\u7e2e\u5c0f\u7d0b\u7406\u7d0b\u7406\u93c8\u63a1\u6a23\u4f7f\u7528NEAREST,\u904e\u6ffe\u4f7f\u7528LINEAR<\/p>\n<p>for (int index = 0, v = 1; index &lt; texture-&gt;count; ++index, v = v * 2)\/\/\u904d\u6b77\u7d0b\u7406\u93c8<\/p>\n<p>glTexImage2D(GL_TEXTURE_2D, index, GL_RGB, texture-&gt;width \/ v, texture-&gt;height \/ v, 0, GL_RGB, GL_UNSIGNED_BYTE, texture-&gt;image[index]);\u00a0\u00a0\u00a0 \/\/\u8f09\u5165\u7d0b\u7406<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7d0b\u7406\u7e6a\u756b\u591a\u908a\u5f62\u7576\u9060\u96e2\u8996\u9ede,\u6703\u51fa\u73fe\u8996\u89ba\u5931\u771f\u6216\u70ab\u76ee\u554f\u984c,\u539f\u56e0\u662fOpenGL\u5c0d\u5169\u500b\u76f8\u9130\u7684\u50cf\u7d20\u9032\u884c\u91c7\u6a23\u6642,\u5f9e\u7d0b\u7406\u5716\u4e2d\u7684 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_mipmap\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">OpenGL\u4e4b\u7d0b\u7406\u6620\u5c04\u4f7f\u7528mipmap<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[50],"class_list":["post-3836","post","type-post","status-publish","format-standard","hentry","category-opengl","tag-opengl","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/comments?post=3836"}],"version-history":[{"count":3,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3836\/revisions"}],"predecessor-version":[{"id":4002,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3836\/revisions\/4002"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=3836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=3836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=3836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}