{"id":688,"date":"2022-06-23T18:10:41","date_gmt":"2022-06-23T10:10:41","guid":{"rendered":"https:\/\/www.acgloby.com\/?p=688"},"modified":"2022-06-23T18:10:41","modified_gmt":"2022-06-23T10:10:41","slug":"opengl-%e7%ba%b9%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.acgloby.com\/index.php\/2022\/06\/23\/opengl-%e7%ba%b9%e7%90%86\/","title":{"rendered":"OpenGL- \u7eb9\u7406"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u7eb9\u7406\u73af\u7ed5\u65b9\u5f0f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7eb9\u7406\u5750\u6807\u7684\u8303\u56f4\u901a\u5e38\u662f\u4ece(0, 0)\u5230(1, 1)\uff0c\u90a3\u5982\u679c\u6211\u4eec\u628a\u7eb9\u7406\u5750\u6807\u8bbe\u7f6e\u5728\u8303\u56f4\u4e4b\u5916OpenGL\u9ed8\u8ba4\u7684\u884c\u4e3a\u662f\u91cd\u590d\u8fd9\u4e2a\u7eb9\u7406\u56fe\u50cf\uff0c\u540c\u6837\u53ef\u4ee5\u8bbe\u7f6e\u73af\u7ed5\u65b9\u5f0f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u73af\u7ed5\u65b9\u5f0f<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td>GL_REPEAT<\/td><td>\u5bf9\u7eb9\u7406\u7684\u9ed8\u8ba4\u884c\u4e3a\u3002\u91cd\u590d\u7eb9\u7406\u56fe\u50cf\u3002<\/td><\/tr><tr><td>GL_MIRRORED_REPEAT<\/td><td>\u548cGL_REPEAT\u4e00\u6837\uff0c\u4f46\u6bcf\u6b21\u91cd\u590d\u56fe\u7247\u662f\u955c\u50cf\u653e\u7f6e\u7684\u3002<\/td><\/tr><tr><td>GL_CLAMP_TO_EDGE<\/td><td>\u7eb9\u7406\u5750\u6807\u4f1a\u88ab\u7ea6\u675f\u57280\u52301\u4e4b\u95f4\uff0c\u8d85\u51fa\u7684\u90e8\u5206\u4f1a\u91cd\u590d\u7eb9\u7406\u5750\u6807\u7684\u8fb9\u7f18\uff0c\u4ea7\u751f\u4e00\u79cd\u8fb9\u7f18\u88ab\u62c9\u4f38\u7684\u6548\u679c\u3002<\/td><\/tr><tr><td>GL_CLAMP_TO_BORDER<\/td><td>\u8d85\u51fa\u7684\u5750\u6807\u4e3a\u7528\u6237\u6307\u5b9a\u7684\u8fb9\u7f18\u989c\u8272\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-3.png\" alt=\"\" class=\"wp-image-691\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e2a\u9009\u9879\u90fd\u53ef\u4ee5\u4f7f\u7528glTexParameter*\u51fd\u6570\u5bf9\u5355\u72ec\u7684\u4e00\u4e2a\u5750\u6807\u8f74\u8bbe\u7f6e\uff08<code>s<\/code>\u3001<code>t<\/code>\uff08\u5982\u679c\u662f\u4f7f\u75283D\u7eb9\u7406\u90a3\u4e48\u8fd8\u6709\u4e00\u4e2a<code>r<\/code>\uff09\u5b83\u4eec\u548c<code>x<\/code>\u3001<code>y<\/code>\u3001<code>z<\/code>\u662f\u7b49\u4ef7\u7684\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u4e86\u7eb9\u7406\u76ee\u6807\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u5750\u6807\u8f74\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u662f\u8bbe\u7f6e\u73af\u7ed5\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6211\u4eec\u9009\u62e9GL_CLAMP_TO_BORDER\u9009\u9879\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u6307\u5b9a\u4e00\u4e2a\u8fb9\u7f18\u7684\u989c\u8272\u3002\u8fd9\u9700\u8981\u4f7f\u7528glTexParameter\u51fd\u6570\u7684fv\u540e\u7f00\u5f62\u5f0f\uff0c\u7528GL_TEXTURE_BORDER_COLOR\u4f5c\u4e3a\u5b83\u7684\u9009\u9879\uff0c\u5e76\u4e14\u4f20\u9012\u4e00\u4e2afloat\u6570\u7ec4\u4f5c\u4e3a\u8fb9\u7f18\u7684\u989c\u8272\u503c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float borderColor&#91;] = { 1.0f, 1.0f, 0.0f, 1.0f };\nglTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u7eb9\u7406\u8fc7\u6ee4(Texture Filtering)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">GL_NEAREST\uff08\u4e5f\u53eb\u90bb\u8fd1\u8fc7\u6ee4\uff0cNearest Neighbor Filtering\uff09\u662fOpenGL\u9ed8\u8ba4\u7684\u7eb9\u7406\u8fc7\u6ee4\u65b9\u5f0f\u3002\u5f53\u8bbe\u7f6e\u4e3aGL_NEAREST\u7684\u65f6\u5019\uff0cOpenGL\u4f1a\u9009\u62e9\u4e2d\u5fc3\u70b9\u6700\u63a5\u8fd1\u7eb9\u7406\u5750\u6807\u7684\u90a3\u4e2a\u50cf\u7d20\u3002\u4e0b\u56fe\u4e2d\u4f60\u53ef\u4ee5\u770b\u5230\u56db\u4e2a\u50cf\u7d20\uff0c\u52a0\u53f7\u4ee3\u8868\u7eb9\u7406\u5750\u6807\u3002\u5de6\u4e0a\u89d2\u90a3\u4e2a\u7eb9\u7406\u50cf\u7d20\u7684\u4e2d\u5fc3\u8ddd\u79bb\u7eb9\u7406\u5750\u6807\u6700\u8fd1\uff0c\u6240\u4ee5\u5b83\u4f1a\u88ab\u9009\u62e9\u4e3a\u6837\u672c\u989c\u8272\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-5.png\" alt=\"\" class=\"wp-image-697\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">GL_LINEAR\uff08\u4e5f\u53eb\u7ebf\u6027\u8fc7\u6ee4\uff0c(Bi)linear Filtering\uff09\u5b83\u4f1a\u57fa\u4e8e\u7eb9\u7406\u5750\u6807\u9644\u8fd1\u7684\u7eb9\u7406\u50cf\u7d20\uff0c\u8ba1\u7b97\u51fa\u4e00\u4e2a\u63d2\u503c\uff0c\u8fd1\u4f3c\u51fa\u8fd9\u4e9b\u7eb9\u7406\u50cf\u7d20\u4e4b\u95f4\u7684\u989c\u8272\u3002\u4e00\u4e2a\u7eb9\u7406\u50cf\u7d20\u7684\u4e2d\u5fc3\u8ddd\u79bb\u7eb9\u7406\u5750\u6807\u8d8a\u8fd1\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7eb9\u7406\u50cf\u7d20\u7684\u989c\u8272\u5bf9\u6700\u7ec8\u7684\u6837\u672c\u989c\u8272\u7684\u8d21\u732e\u8d8a\u5927\u3002\u4e0b\u56fe\u4e2d\u4f60\u53ef\u4ee5\u770b\u5230\u8fd4\u56de\u7684\u989c\u8272\u662f\u90bb\u8fd1\u50cf\u7d20\u7684\u6df7\u5408\u8272\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-6.png\" alt=\"\" class=\"wp-image-700\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/v2-6f9328f107258bbc7346b6ffbb43d963_r-1024x773.jpg\" alt=\"\" class=\"wp-image-706\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">GL_NEAREST\u4ea7\u751f\u4e86\u9897\u7c92\u72b6\u7684\u56fe\u6848\uff0c\u6211\u4eec\u80fd\u591f\u6e05\u6670\u770b\u5230\u7ec4\u6210\u7eb9\u7406\u7684\u50cf\u7d20\uff0c\u800cGL_LINEAR\u80fd\u591f\u4ea7\u751f\u66f4\u5e73\u6ed1\u7684\u56fe\u6848\uff0c\u5f88\u96be\u770b\u51fa\u5355\u4e2a\u7684\u7eb9\u7406\u50cf\u7d20\u3002GL_LINEAR\u53ef\u4ee5\u4ea7\u751f\u66f4\u771f\u5b9e\u7684\u8f93\u51fa\uff0c\u4f46\u6709\u4e9b\u5f00\u53d1\u8005\u66f4\u559c\u6b228-bit\u98ce\u683c\uff0c\u6240\u4ee5\u4ed6\u4eec\u4f1a\u7528GL_NEAREST\u9009\u9879\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-7.png\" alt=\"\" class=\"wp-image-702\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fdb\u884c\u653e\u5927(Magnify)\u548c\u7f29\u5c0f(Minify)\u64cd\u4f5c\u7684\u65f6\u5019\u53ef\u4ee5\u8bbe\u7f6e\u7eb9\u7406\u8fc7\u6ee4\u7684\u9009\u9879\uff0c\u6bd4\u5982\u4f60\u53ef\u4ee5\u5728\u7eb9\u7406\u88ab\u7f29\u5c0f\u7684\u65f6\u5019\u4f7f\u7528\u90bb\u8fd1\u8fc7\u6ee4\uff0c\u88ab\u653e\u5927\u65f6\u4f7f\u7528\u7ebf\u6027\u8fc7\u6ee4\u3002\u6211\u4eec\u9700\u8981\u4f7f\u7528glTexParameter*\u51fd\u6570\u4e3a\u653e\u5927\u548c\u7f29\u5c0f\u6307\u5b9a\u8fc7\u6ee4\u65b9\u5f0f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406(Mipmap)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u7f29\u5c0f\u56fe\u7247\u65f6\u6211\u4eec\u4f7f\u7528mipmap\uff0cmipmap\u662f\u63d0\u524d\u5b58\u5165\u5185\u5b58\u4e2d\u7684\uff0c\u4e0d\u9700\u8981\u5b9e\u65f6\u91c7\u6837\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mipmap\u662f\u54482\u7684\u5e42\u6b21\u65b9\u7f29\u5c0f\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u5bfc\u5165\u7684\u56fe\u7247\u4f1a\u6e38\u620f\u5f15\u64ce\u4f1a\u81ea\u52a8\u5e2e\u6211\u4eec\u628a\u957f\u5bbd\u62c9\u62102\u7684\u5e42\u6b21\u65b9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OpenGL\u4e2d\u751f\u6210Mipmap\u51fd\u6570glGenerateMipmaps\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-8.png\" alt=\"\" class=\"wp-image-703\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6e32\u67d3\u4e2d\u5207\u6362\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u7ea7\u522b(Level)\u65f6\uff0cOpenGL\u5728\u4e24\u4e2a\u4e0d\u540c\u7ea7\u522b\u7684\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u5c42\u4e4b\u95f4\u4f1a\u4ea7\u751f\u4e0d\u771f\u5b9e\u7684\u751f\u786c\u8fb9\u754c\u3002\u5c31\u50cf\u666e\u901a\u7684\u7eb9\u7406\u8fc7\u6ee4\u4e00\u6837\uff0c\u5207\u6362\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u7ea7\u522b\u65f6\u4f60\u4e5f\u53ef\u4ee5\u5728\u4e24\u4e2a\u4e0d\u540c\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u7ea7\u522b\u4e4b\u95f4\u4f7f\u7528NEAREST\u548cLINEAR\u8fc7\u6ee4\u3002\u4e3a\u4e86\u6307\u5b9a\u4e0d\u540c\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u7ea7\u522b\u4e4b\u95f4\u7684\u8fc7\u6ee4\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u56db\u4e2a\u9009\u9879\u4e2d\u7684\u4e00\u4e2a\u4ee3\u66ff\u539f\u6709\u7684\u8fc7\u6ee4\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fc7\u6ee4\u65b9\u5f0f<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td>GL_NEAREST_MIPMAP_NEAREST<\/td><td>\u4f7f\u7528\u6700\u90bb\u8fd1\u7684\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u6765\u5339\u914d\u50cf\u7d20\u5927\u5c0f\uff0c\u5e76\u4f7f\u7528\u90bb\u8fd1\u63d2\u503c\u8fdb\u884c\u7eb9\u7406\u91c7\u6837<\/td><\/tr><tr><td>GL_LINEAR_MIPMAP_NEAREST<\/td><td>\u4f7f\u7528\u6700\u90bb\u8fd1\u7684\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u7ea7\u522b\uff0c\u5e76\u4f7f\u7528\u7ebf\u6027\u63d2\u503c\u8fdb\u884c\u91c7\u6837<\/td><\/tr><tr><td>GL_NEAREST_MIPMAP_LINEAR<\/td><td>\u5728\u4e24\u4e2a\u6700\u5339\u914d\u50cf\u7d20\u5927\u5c0f\u7684\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u4e4b\u95f4\u8fdb\u884c\u7ebf\u6027\u63d2\u503c\uff0c\u4f7f\u7528\u90bb\u8fd1\u63d2\u503c\u8fdb\u884c\u91c7\u6837<\/td><\/tr><tr><td>GL_LINEAR_MIPMAP_LINEAR<\/td><td>\u5728\u4e24\u4e2a\u90bb\u8fd1\u7684\u591a\u7ea7\u6e10\u8fdc\u7eb9\u7406\u4e4b\u95f4\u4f7f\u7528\u7ebf\u6027\u63d2\u503c\uff0c\u5e76\u4f7f\u7528\u7ebf\u6027\u63d2\u503c\u8fdb\u884c\u91c7\u6837<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bbe\u7f6e\u7eb9\u7406\u8fc7\u6ee4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u52a0\u8f7d\u521b\u5efa\u7eb9\u7406<\/h3>\n\n\n\n<h6 class=\"wp-block-heading\" style=\"font-size:16px\">stb_image.h<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">std_image.h\u662f<a href=\"https:\/\/github.com\/nothings\" target=\"_blank\"  rel=\"nofollow\" >Sean Barrett<\/a>\u7684\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u5355\u5934\u6587\u4ef6\u56fe\u50cf\u52a0\u8f7d\u5e93      <a href=\"https:\/\/github.com\/nothings\/stb\/blob\/master\/stb_image.h\" target=\"_blank\"  rel=\"nofollow\" >\u4e0b\u8f7d\u5730\u5740<\/a>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a0\u8f7d\u5230\u9879\u76ee\u91cc\u5bfc\u5165\u5934\u6587\u4ef6\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"<\/code><\/pre>\n\n\n\n<h6 class=\"wp-block-heading\" style=\"font-size:16px\">\u52a0\u8f7d\u4e00\u5f20\u56fe\u7247<\/h6>\n\n\n\n<pre class=\"wp-block-code\"><code>unsigned int texture;\nglGenTextures(1, &amp;texture);\nglBindTexture(GL_TEXTURE_2D, texture);\n\/\/ \u4e3a\u5f53\u524d\u7ed1\u5b9a\u7684\u7eb9\u7406\u5bf9\u8c61\u8bbe\u7f6e\u73af\u7ed5\u3001\u8fc7\u6ee4\u65b9\u5f0f\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);   \nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\nglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\n\/\/ \u52a0\u8f7d\u5e76\u751f\u6210\u7eb9\u7406\nint width, height, nrChannels;\nunsigned char *data = stbi_load(\"container.jpg\", &amp;width, &amp;height, &amp;nrChannels, 0);\nif (data)\n{\n    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);\n    glGenerateMipmap(GL_TEXTURE_2D);\n}\nelse\n{\n    std::cout &lt;&lt; \"Failed to load texture\" &lt;&lt; std::endl;\n}\nstbi_image_free(data);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u9876\u70b9\u5c5e\u6027\uff0c\u52a0\u5165\u7eb9\u7406\u5750\u6807\uff0c\u540c\u65f6\u9700\u8981\u4fee\u6539\u9876\u70b9\u5c5e\u6027\u6307\u9488<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float vertices&#91;] = {\n\/\/     ---- \u4f4d\u7f6e ----       ---- \u989c\u8272 ----     - \u7eb9\u7406\u5750\u6807 -\n     0.5f,  0.5f, 0.0f,   1.0f, 0.0f, 0.0f,   1.0f, 1.0f,   \/\/ \u53f3\u4e0a\n     0.5f, -0.5f, 0.0f,   0.0f, 1.0f, 0.0f,   1.0f, 0.0f,   \/\/ \u53f3\u4e0b\n    -0.5f, -0.5f, 0.0f,   0.0f, 0.0f, 1.0f,   0.0f, 0.0f,   \/\/ \u5de6\u4e0b\n    -0.5f,  0.5f, 0.0f,   1.0f, 1.0f, 0.0f,   0.0f, 1.0f    \/\/ \u5de6\u4e0a\n};<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-9.png\" alt=\"\" class=\"wp-image-710\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\u5c31\u6210\u4e86\u6bcf\u4e2a\u9876\u70b9\u5c5e\u6027\u67098\u4e2afloat\u7ec4\u6210\u3002\u4f4d\u7f6e\u5c5e\u6027\u5bf9\u5e94layout\uff08location = 0\uff09\uff0c\u989c\u8272\u5c5e\u6027\u5bf9\u5e94layout\uff08location = 1\uff09\uff0c\u53d63\u4f4dfloat\uff0c\u7eb9\u7406\u5bf9\u5e94layout\uff08location  =  2\uff09\uff0c\u53d62\u4f4dfloat\uff0c\u6b65\u957f\u503c\u4e3a8\u4e2afloat\uff0c\u5176\u4e2d3\u4e2a\u662f\u4f4d\u7f6e\uff0c3\u4e2a\u662f\u989c\u8272\uff0c2\u4e2a\u662f\u7eb9\u7406\u5750\u6807\u3002\u4f4d\u7f6e\u5c5e\u6027\u4ece0\u5f00\u59cb\uff0c\u6240\u6709\u504f\u79fb\u503c\u4e3a0\uff0c\u989c\u8272\u5c5e\u6027\u4ece3\u5f00\u59cb\uff0c\u504f\u79fb\u503c\u4e3a3\uff0c\u7eb9\u7406\u5750\u6807\u4ece6\u5f00\u59cb\uff0c\u504f\u79fb\u503c\u4e3a6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tglVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);\n\tglEnableVertexAttribArray(0);\n\t\n\tglVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));\n\tglEnableVertexAttribArray(1);\n\n\tglVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));\n\tglEnableVertexAttribArray(2);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u7eb9\u7406\u5355\u5143<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7eb9\u7406\u517116\u4e2a\u901a\u9053\uff0cOpenGL\u5bf9\u5e94GL_TEXTURE0~GL_TEXTURE16\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528\u591a\u5f20\u7eb9\u7406\u8d34\u56fe\u7684\u65f6\u5019\uff0c\u9700\u8981\u5148\u6fc0\u6d3b\u4e00\u4e2a\u7eb9\u7406\u901a\u9053\u540e\u7ed1\u5b9a\u4e00\u5f20\u8d34\u56fe\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>glActiveTexture(GL_TEXTURE0);\nglBindTexture(GL_TEXTURE_2D, texture1);\nglActiveTexture(GL_TEXTURE1);\nglBindTexture(GL_TEXTURE_2D, texture2);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u878d\u5408\u51fd\u6570<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728GLSL\u4e2d\u4f7f\u7528mix\uff08\uff09\u51fd\u6570\u8fdb\u884c\u878d\u5408\uff0c\u7528\u6cd5\u548c\u5176\u4ed6\u8bed\u8a00\u4e2d\u7684lerp\u4e00\u6837\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#version 330 core\n\nout vec4 FragColor;\nin vec4 vertexColor;\nin vec2 TexCoord;\n\nuniform sampler2D texture1;\nuniform sampler2D texture2;\n\nvoid main()\n{\n\tvec4 lerp1 = mix(texture(texture1, TexCoord),texture(texture2, TexCoord),0.2);\n\tFragColor = mix(lerp1,vertexColor,0.2);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h6 class=\"wp-block-heading\" style=\"font-size:16px\">\u6700\u7ec8\u6548\u679c<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-4.png\" alt=\"OpenGL- \u7eb9\u7406\" title=\"OpenGL- \u7eb9\u7406\"><img decoding=\"async\" src=\"https:\/\/www.acgloby.com\/wp-content\/uploads\/2022\/06\/image-4.png\" alt=\"\" class=\"wp-image-690\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7eb9\u7406\u73af\u7ed5\u65b9\u5f0f \u7eb9\u7406\u5750\u6807\u7684\u8303\u56f4\u901a\u5e38\u662f\u4ece(0, 0)\u5230(1, 1)\uff0c\u90a3\u5982\u679c\u6211\u4eec\u628a\u7eb9\u7406\u5750\u6807\u8bbe\u7f6e\u5728\u8303\u56f4\u4e4b\u5916OpenGL\u9ed8\u8ba4\u7684\u884c\u4e3a\u662f\u91cd\u590d\u8fd9\u4e2a &#8230;<\/p>\n","protected":false},"author":1,"featured_media":690,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-688","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-graphics"],"_links":{"self":[{"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/posts\/688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/comments?post=688"}],"version-history":[{"count":0,"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/posts\/688\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/media?parent=688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/categories?post=688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.acgloby.com\/index.php\/wp-json\/wp\/v2\/tags?post=688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}