{"id":66,"date":"2021-01-08T16:15:55","date_gmt":"2021-01-08T08:15:55","guid":{"rendered":"http:\/\/liyanliang.net\/?p=66"},"modified":"2021-01-11T14:06:00","modified_gmt":"2021-01-11T06:06:00","slug":"opengl%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba-glfw%e4%b8%8eglad%e9%85%8d%e7%bd%ae-%e8%b6%85%e8%af%a6%e7%bb%86","status":"publish","type":"post","link":"http:\/\/liyanliang.net\/index.php\/2021\/01\/08\/opengl%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba-glfw%e4%b8%8eglad%e9%85%8d%e7%bd%ae-%e8%b6%85%e8%af%a6%e7%bb%86\/","title":{"rendered":"OpenGL\u5f00\u53d1\u73af\u5883\u642d\u5efa-GLFW\u4e0eGLAD\u914d\u7f6e \u8d85\u8be6\u7ec6"},"content":{"rendered":"\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#GLFW\"><span class=\"toc_number toc_depth_1\">1<\/span> \u4e00\u3001\u6784\u5efaGLFW<\/a><ul><li><ul><li><a href=\"#1GLFW\"><span class=\"toc_number toc_depth_3\">1.0.1<\/span> \uff081\uff09\u4e0b\u8f7dGLFW\u8d44\u6e90\u5305<\/a><\/li><li><a href=\"#2CMake\"><span class=\"toc_number toc_depth_3\">1.0.2<\/span> \uff082\uff09\u4e0b\u8f7d\u5b89\u88c5CMake<\/a><\/li><li><a href=\"#3\"><span class=\"toc_number toc_depth_3\">1.0.3<\/span> \uff083\uff09 \u7f16\u8bd1<\/a><\/li><\/ul><\/li><\/ul><\/li><li><a href=\"#GLAD\"><span class=\"toc_number toc_depth_1\">2<\/span> \u4e8c\u3001\u83b7\u53d6GLAD<\/a><ul><li><ul><li><a href=\"#1_GLAD\"><span class=\"toc_number toc_depth_3\">2.0.1<\/span> \uff081\uff09\u6253\u5f00 GLAD \u7684\u5728\u7ebf\u670d\u52a1<\/a><\/li><\/ul><\/li><\/ul><\/li><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">3<\/span> \u4e09\u3001\u914d\u7f6e\u89e3\u51b3\u65b9\u6848<\/a><ul><li><ul><li><a href=\"#1includelibs\"><span class=\"toc_number toc_depth_3\">3.0.1<\/span> \uff081\uff09\u5728\u8be5\u9879\u76ee\u7684\u6587\u4ef6\u5939\u4e0b\u65b0\u5efa\u4e24\u4e2a\u6587\u4ef6\u5939\uff0c\u4e00\u4e2ainclude,\u4e00\u4e2alibs.<\/a><\/li><li><a href=\"#2\"><span class=\"toc_number toc_depth_3\">3.0.2<\/span> \uff082\uff09\u914d\u7f6e\u5c5e\u6027<\/a><\/li><\/ul><\/li><\/ul><\/li><li><a href=\"#OpenGL\"><span class=\"toc_number toc_depth_1\">4<\/span> \u56db\u3001\u6d4b\u8bd5\uff1a\u521b\u5efa\u4e00\u4e2aOpenGL\u7a97\u53e3<\/a><\/li><\/ul><\/div>\n<h2 class=\"wp-block-heading\"><span id=\"GLFW\">\u4e00\u3001\u6784\u5efaGLFW<\/span><\/h2>\n\n\n\n<p>\u9996\u5148\u9700\u8981\u83b7\u53d6glfw3.lib\u6587\u4ef6\uff0c\u83b7\u53d6glfw3.lib\u6587\u4ef6\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p><strong>\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff1a\u76f4\u63a5\u5728\u5b98\u7f51\u4e0b\u8f7d<\/strong><\/p>\n\n\n\n<p>\u5efa\u8bae\u4e0b\u8f7d32\u4f4d\u7684\u3002\u8fd9\u4e2a\u662fRelease\u7248\u672c\uff0c\u6240\u4ee5\u53ea\u80fd\u5728Release\u4e0b\u4f7f\u7528<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022152454.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022152629.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528CMake\u7f16\u8bd1\u83b7\u53d6\uff08\u5efa\u8bae\u4f7f\u7528\u6b64\u65b9\u6cd5\uff09<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span id=\"1GLFW\">\uff081\uff09\u4e0b\u8f7dGLFW\u8d44\u6e90\u5305<\/span><\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022152940.png\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span id=\"2CMake\">\uff082\uff09\u4e0b\u8f7d\u5b89\u88c5CMake<\/span><\/h4>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u8981\u7528CMake\uff1f \u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\u5e93\u53ef\u4ee5\u4fdd\u8bc1\u751f\u6210\u7684\u5e93\u662f\u517c\u5bb9\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u548c CPU \u7684\uff0c\u800c\u9884\u7f16\u8bd1\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u53ef\u80fd\u4f1a\u51fa\u73b0\u517c\u5bb9\u95ee\u9898\uff08\u751a\u81f3\u6709\u65f6\u5019\u6ca1\u63d0\u4f9b\u652f\u6301\u4f60\u7cfb\u7edf\u7684\u6587\u4ef6\uff09\u3002\u63d0\u4f9b\u6e90\u4ee3\u7801\u6240\u4ea7\u751f\u7684\u4e00\u4e2a\u95ee\u9898\u5728\u4e8e\u4e0d\u662f\u6bcf\u4e2a\u4eba\u90fd\u7528\u76f8\u540c\u7684 IDE \u5f00\u53d1\u7a0b\u5e8f\uff0c\u56e0\u800c\u63d0\u4f9b\u7684\u5de5\u7a0b\/\u89e3\u51b3\u65b9\u6848\u6587\u4ef6\u53ef\u80fd\u548c\u4e00\u4e9b\u4eba\u7684 IDE \u4e0d\u517c\u5bb9\u3002\u6240\u4ee5\u4eba\u4eec\u53ea\u80fd\u4ece.c\/.cpp\u548c.h\/.hpp \u6587\u4ef6\u6765\u81ea\u5df1\u5efa\u7acb\u5de5\u7a0b\/\u89e3\u51b3\u65b9\u6848\uff0c\u8fd9\u662f\u4e00\u9879\u67af\u71e5\u7684\u5de5\u4f5c\u3002\u4f46\u56e0\u6b64\u4e5f\u8bde\u751f\u4e86\u4e00\u4e2a\u53eb\u505a CMake \u7684\u5de5\u5177\u3002 1\u3001\u5b98\u7f51\u4e0b\u8f7d\uff1a<a href=\"https:\/\/cmake.org\/download\/\">https:\/\/cmake.org\/download\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022153257.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>2\u3001\u542f\u52a8 CMake \u5728CMake\u5b89\u88c5\u76ee\u5f55\u7684bin\u6587\u4ef6\u5939\u4e0b\u53cc\u51fbcmake-gui.exe\u542f\u52a8CMake\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022153430.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u6e90\u4ee3\u7801\u76ee\u5f55\u6211\u4eec\u9009\u62e9 GLFW \u7684\u6e90\u4ee3\u7801\u7684\u6839\u76ee\u5f55\uff0c\u7136\u540e\u6211\u4eec\u5728\u6839\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2a build \u6587\u4ef6\u5939\uff0c\u9009\u4e2d\u4f5c\u4e3a\u76ee\u6807\u76ee\u5f55\u3002<\/p>\n\n\n\n<p>\u5176\u4ed6\u90fd\u4e0d\u52a8\uff0c\u70b9Configure\uff08\u8bbe\u7f6e\uff09<\/p>\n\n\n\n<p>\u7136\u540e\u4f1a\u8ba9\u6211\u4eec\u9009\u62e9\u5de5\u7a0b\u7684\u751f\u6210\u5668\uff0c\u6211\u7528\u7684vs2012\uff0c\u6240\u4ee5\u662f\u90092012\uff0c\u5176\u4f59\u9ed8\u8ba4 \u4e4b\u540e\u7b49\u5f85\u8bbe\u7f6e\u5b8c\u6210\u540e\uff1a\u518d\u6b21\u70b9\u51fbConfigure\uff08\u8bbe\u7f6e\uff09<\/p>\n\n\n\n<p>\u5b8c\u6210\u540e\u518d\u70b9Generate\u5373\u53ef.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/01.png\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span id=\"3\">\uff083\uff09 \u7f16\u8bd1<\/span><\/h4>\n\n\n\n<p>\u5728\u521a\u624d\u5728glfw\u65b0\u5efa\u7684build \u6587\u4ef6\u5939\u91cc\u53ef\u4ee5\u627e\u5230 GLFW.sln \u6587\u4ef6\uff0c\u7528 Visual Studio 2010 \u6253\u5f00\u3002\u56e0\u4e3a CMake \u5df2\u7ecf\u914d\u7f6e\u597d\u4e86\u9879\u76ee\uff0c\u6240\u4ee5\u6211\u4eec\u76f4\u63a5\u70b9\u51fb Build Solution(\u751f\u6210\u89e3\u51b3\u65b9\u6848)<\/p>\n\n\n\n<p>\u6b64\u65f6\u4f1a\u6709\u4e00\u4e9b\u7f16\u8bd1\u4ea7\u751f\u7684error\uff0c\u53ef\u4ee5\u4e0d\u7528\u7ba1\uff0c\u4ea7\u751ferror\u7684\u539f\u56e0\u662fTest\u9879\u76ee\u4e2d\u7684\u4e00\u4e9b\u5b9e\u4f8b\u9020\u6210\u4e86\uff0c\u6b64\u65f6glfw3.lib\u5df2\u7ecf\u751f\u6210\u5b8c\u6210\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022153858.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u5206\u522b\u7f16\u8bd1Debug\u548cRelease\u7248\u672c:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022155457.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022155622.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"GLAD\">\u4e8c\u3001\u83b7\u53d6GLAD<\/span><\/h2>\n\n\n\n<p>\u5230\u8fd9\u91cc\u8fd8\u6ca1\u6709\u7ed3\u675f\uff0c\u6211\u4eec\u4ecd\u7136\u8fd8\u6709\u4e00\u4ef6\u4e8b\u8981\u505a\u3002\u56e0\u4e3a OpenGL \u53ea\u662f\u4e00\u4e2a\u6807\u51c6\/\u89c4\u8303\uff0c\u5177\u4f53\u7684\u5b9e\u73b0\u662f\u7531\u9a71\u52a8\u5f00\u53d1\u5546\u9488\u5bf9\u7279\u5b9a\u663e\u5361\u5b9e\u73b0\u7684\u3002\u7531\u4e8e OpenGL \u9a71\u52a8\u7248\u672c\u4f17\u591a\uff0c\u5b83\u5927\u591a\u6570\u51fd\u6570\u7684\u4f4d\u7f6e\u90fd\u65e0\u6cd5\u5728\u7f16\u8bd1\u65f6\u786e\u5b9a\u4e0b\u6765\uff0c\u9700\u8981\u5728\u8fd0\u884c\u65f6\u67e5\u8be2\u3002\u6240\u4ee5\u4efb\u52a1\u5c31\u843d\u5728\u4e86\u5f00\u53d1\u8005\u8eab\u4e0a\uff0c\u5f00\u53d1\u8005\u9700\u8981\u5728\u8fd0\u884c\u65f6\u83b7\u53d6\u51fd\u6570\u5730\u5740\u5e76\u5c06\u5176\u4fdd\u5b58\u5728\u4e00\u4e2a\u51fd\u6570\u6307\u9488\u4e2d\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002\u53d6\u5f97\u5730\u5740\u7684\u65b9\u6cd5\u56e0\u5e73\u53f0\u800c\u5f02\uff0c\u4ee3\u7801\u975e\u5e38\u590d\u6742\uff0c\u800c\u4e14\u5f88\u7e41\u7410\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5bf9\u6bcf\u4e2a\u53ef\u80fd\u4f7f\u7528\u7684\u51fd\u6570\u90fd\u8981\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u6709\u4e9b\u5e93\u80fd\u7b80\u5316\u6b64\u8fc7\u7a0b\uff0c\u5176\u4e2d GLAD \u662f\u76ee\u524d\u6700\u65b0\uff0c\u4e5f\u662f\u6700\u6d41\u884c\u7684\u5e93\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span id=\"1_GLAD\">\uff081\uff09\u6253\u5f00 GLAD \u7684\u5728\u7ebf\u670d\u52a1<\/span><\/h4>\n\n\n\n<p>\u5b98\u7f51\uff1a<a href=\"https:\/\/glad.dav1d.de\/\">https:\/\/glad.dav1d.de\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022160420.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022160502.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"i\">\u4e09\u3001\u914d\u7f6e\u89e3\u51b3\u65b9\u6848<\/span><\/h2>\n\n\n\n<p>\u4f7f\u7528VS\u65b0\u5efa\u4e00\u4e2awin32\u7684\u63a7\u5236\u53f0\u9879\u76eeConsoleOpenGL.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span id=\"1includelibs\">\uff081\uff09\u5728\u8be5\u9879\u76ee\u7684\u6587\u4ef6\u5939\u4e0b\u65b0\u5efa\u4e24\u4e2a\u6587\u4ef6\u5939\uff0c\u4e00\u4e2ainclude,\u4e00\u4e2alibs.<\/span><\/h4>\n\n\n\n<p>\u628aGLFW\u548cGLAD\u7684include\u4e0b\u7684\u6587\u4ef6\u5939\u590d\u5236\u5230\u6211\u4eec\u65b0\u5efa\u7684include<\/p>\n\n\n\n<p>\u628a\u6211\u4eec\u521a\u624d\u7684\u751f\u6210\u7684glfw3.lib\u642c\u5230libs\u6587\u4ef6\u5939\u3002<\/p>\n\n\n\n<p>\u628aGLAD\u7684include\/src\u4e0b\u7684*.c\u6587\u4ef6\u590d\u5236\u5230\u5de5\u7a0b\u6587\u4ef6\u5939\uff0c\u6dfb\u52a0\u5230\u5de5\u7a0b\u91cc\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022161033.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022161059.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022161205.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022161239.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022161313.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022161346.png\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><span id=\"2\">\uff082\uff09\u914d\u7f6e\u5c5e\u6027<\/span><\/h4>\n\n\n\n<p>\u4e3a\u4e86\u4f7f\u6211\u4eec\u7684\u7a0b\u5e8f\u4f7f\u7528 GLFW\uff0c\u6211\u4eec\u9700\u8981\u628a GLFW \u5e93\u94fe\u63a5(Link)\u8fdb\u5de5\u7a0b\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728\u94fe\u63a5\u5668\u7684\u8bbe\u7f6e\u91cc\u6307\u5b9a\u6211\u4eec\u8981\u4f7f\u7528 glfw3.lib \u6765\u5b8c\u6210\uff0c\u4f46\u662f\u7531\u4e8e\u6211\u4eec\u5c06\u7b2c\u4e09\u65b9\u5e93\u653e\u5728\u53e6\u5916\u7684\u76ee\u5f55\u4e2d\uff0c\u6211\u4eec\u7684\u5de5\u7a0b\u8fd8\u4e0d\u77e5\u9053\u5728\u54ea\u5bfb\u627e\u8fd9\u4e2a\u6587\u4ef6\u3002\u4e8e\u662f\u6211\u4eec\u9996\u5148\u9700\u8981\u5c06\u6211\u4eec\u653e\u7b2c\u4e09\u65b9\u5e93\u7684\u76ee\u5f55\u6dfb\u52a0\u8fdb\u8bbe\u7f6e\u3002\u8981\u6dfb\u52a0\u8fd9\u4e9b\u76ee\u5f55\uff08\u9700\u8981 VS \u641c\u7d22\u5e93\u548c include \u6587\u4ef6\u7684\u5730\u65b9\uff09\uff0c\u6211\u4eec\u9996\u5148\u8fdb\u5165Project Properties(\u5de5\u7a0b\u5c5e\u6027\uff0c\u5728\u89e3\u51b3\u65b9\u6848\u7a97\u53e3\u91cc\u53f3\u952e\u9879\u76ee)\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022155921.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u7136\u540e\u9009\u62e9 VC++ Directories(VC++ \u76ee\u5f55)\u9009\u9879\u5361\uff08\u5982\u4e0b\u56fe\uff09\u3002\u5728\u4e0b\u9762\u7684\u4e24\u680f(Include Directories \u5305\u542b\u76ee\u5f55\u548c Library Directories \u5e93\u76ee\u5f55)\u6dfb\u52a0\u76ee\u5f55\uff1a\u628a\u81ea\u5df1\u7684\u76ee\u5f55\uff08\u4e5f\u5c31\u662finclude\u3001\u548clib\u4e24\u4e2a\u90fd\u52a0\uff09\u52a0\u8fdb\u53bb\uff0c\u8ba9\u5de5\u7a0b\u77e5\u9053\u5230\u54ea\u53bb\u641c\u7d22\u3002\u4f60\u9700\u8981\u624b\u52a8\u628a\u76ee\u5f55\u52a0\u5728\u540e\u9762\u3002<\/p>\n\n\n\n<p>\u5305\u542b\u6587\u4ef6\u5939\uff1ainclude<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022161730.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u5305\u542b\u6587\u4ef6\u5939\uff1alib<\/p>\n\n\n\n<p>Debug\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022162303.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Release\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022162519.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022162623.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"OpenGL\">\u56db\u3001\u6d4b\u8bd5\uff1a\u521b\u5efa\u4e00\u4e2aOpenGL\u7a97\u53e3<\/span><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/\u4e0b\u9762\u4e24\u4e2a\u5934\u6587\u4ef6\u5fc5\u987b\u5728include\u7684\u5404\u81ea\u7684\u6587\u4ef6\u5939\uff08glad\u548cGLFW\uff09\u4e0b\u624d\u884c\uff01\uff01\uff01<br>#include &lt;glad\/glad.h&gt; <br>#include &lt;GLFW\/glfw3.h&gt;<br>#include &lt;iostream&gt;<br>#include \"glad.c\"<br>void framebuffer_size_callback(GLFWwindow* window, int width, int height);<br>void processInput(GLFWwindow *window);<br>\u200b<br>\/\/ settings<br>const unsigned int SCR_WIDTH = 800;<br>const unsigned int SCR_HEIGHT = 600;<br>\u200b<br>int main()<br>{<br>    \/\/ glfw: initialize and configure<br>    \/\/ ------------------------------<br>    glfwInit();<br>    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);<br>    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);<br>    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);<br>\u200b<br>#ifdef __APPLE__<br>    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); \/\/ uncomment this statement to fix compilation on OS X<br>#endif<br>\u200b<br>    \/\/ glfw window creation<br>    \/\/ --------------------<br>    GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, \"LearnOpenGL\", NULL, NULL);<br>    if (window == NULL)<br>    {<br>        std::cout &lt;&lt; \"Failed to create GLFW window\" &lt;&lt; std::endl;<br>        glfwTerminate();<br>        return -1;<br>    }<br>    glfwMakeContextCurrent(window);<br>    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);<br>\u200b<br>    \/\/ glad: load all OpenGL function pointers<br>    \/\/ ---------------------------------------<br>    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))<br>    {<br>        std::cout &lt;&lt; \"Failed to initialize GLAD\" &lt;&lt; std::endl;<br>        return -1;<br>    } &nbsp; &nbsp;<br>\u200b<br>    \/\/ render loop<br>    \/\/ -----------<br>    while (!glfwWindowShouldClose(window))<br>    {<br>        \/\/ input<br>        \/\/ -----<br>        processInput(window);<br>\u200b<br>        \/\/ render<br>        \/\/ ------<br>        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);<br>        glClear(GL_COLOR_BUFFER_BIT);<br>\u200b<br>        \/\/ glfw: swap buffers and poll IO events (keys pressed\/released, mouse moved etc.)<br>        \/\/ -------------------------------------------------------------------------------<br>        glfwSwapBuffers(window);<br>        glfwPollEvents();<br>    }<br>\u200b<br>    \/\/ glfw: terminate, clearing all previously allocated GLFW resources.<br>    \/\/ ------------------------------------------------------------------<br>    glfwTerminate();<br>    return 0;<br>}<br>\u200b<br>\/\/ process all input: query GLFW whether relevant keys are pressed\/released this frame and react accordingly<br>\/\/ ---------------------------------------------------------------------------------------------------------<br>void processInput(GLFWwindow *window)<br>{<br>    if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)<br>        glfwSetWindowShouldClose(window, true);<br>}<br>\u200b<br>\/\/ glfw: whenever the window size changed (by OS or user resize) this callback function executes<br>\/\/ ---------------------------------------------------------------------------------------------<br>void framebuffer_size_callback(GLFWwindow* window, int width, int height)<br>{<br>    \/\/ make sure the viewport matches the new window dimensions; note that width and <br>    \/\/ height will be significantly larger than specified on retina displays.<br>    glViewport(0, 0, width, height);<br>}<br>\u200b<\/pre>\n\n\n\n<p>\u6548\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/liyanliangpublic.oss-cn-hongkong.aliyuncs.com\/img\/20201022162942.png\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u4e00\u3001\u6784\u5efaGLFW1.0.1 \uff081\uff09\u4e0b\u8f7dGLFW\u8d44\u6e90\u53051.0.2 \uff082\uff09\u4e0b\u8f7d\u5b89\u88c5CMake1.0.3 \uff083\uff09 \u7f16\u8bd12 \u4e8c\u3001\u83b7\u53d6GLAD2.0.1 \uff081\uff09\u6253\u5f00 GLAD \u7684\u5728\u7ebf\u670d\u52a13 \u4e09\u3001\u914d\u7f6e\u89e3\u51b3\u65b9\u68483.0.1 \uff081\uff09\u5728\u8be5\u9879\u76ee\u7684\u6587\u4ef6\u5939\u4e0b\u65b0\u5efa\u4e24\u4e2a\u6587\u4ef6\u5939\uff0c\u4e00\u4e2ainclude,\u4e00\u4e2alibs.3.0.2 \uff082\uff09\u914d\u7f6e\u5c5e\u60274 \u56db\u3001\u6d4b\u8bd5\uff1a\u521b\u5efa\u4e00\u4e2aOpenGL\u7a97\u53e3 \u4e00\u3001\u6784\u5efaGLFW \u9996\u5148\u9700\u8981\u83b7\u53d6glfw3.lib\u6587\u4ef6\uff0c\u83b7\u53d6glfw3.lib\u6587\u4ef6\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a \u7b2c\u4e00\u79cd\u65b9\u6cd5\uff1a\u76f4\u63a5\u5728\u5b98\u7f51\u4e0b\u8f7d \u5efa\u8bae\u4e0b\u8f7d32\u4f4d\u7684\u3002\u8fd9\u4e2a\u662fRelease\u7248\u672c\uff0c\u6240\u4ee5\u53ea\u80fd\u5728Release\u4e0b\u4f7f\u7528 \u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528CMake\u7f16\u8bd1\u83b7\u53d6\uff08\u5efa\u8bae\u4f7f\u7528\u6b64\u65b9\u6cd5\uff09 \uff081\uff09\u4e0b\u8f7dGLFW\u8d44\u6e90\u5305 \uff082\uff09\u4e0b\u8f7d\u5b89\u88c5CMake \u4e3a\u4ec0\u4e48\u8981\u7528CMake\uff1f \u4ece\u6e90\u4ee3\u7801\u7f16\u8bd1\u5e93\u53ef\u4ee5\u4fdd\u8bc1\u751f\u6210\u7684\u5e93\u662f\u517c\u5bb9\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\u548c CPU \u7684\uff0c\u800c\u9884\u7f16\u8bd1\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u53ef\u80fd\u4f1a\u51fa\u73b0\u517c\u5bb9\u95ee\u9898\uff08\u751a\u81f3\u6709\u65f6\u5019\u6ca1\u63d0\u4f9b\u652f\u6301\u4f60\u7cfb\u7edf\u7684\u6587\u4ef6\uff09\u3002\u63d0\u4f9b\u6e90\u4ee3\u7801\u6240\u4ea7\u751f\u7684\u4e00\u4e2a\u95ee\u9898\u5728\u4e8e\u4e0d\u662f\u6bcf\u4e2a\u4eba\u90fd\u7528\u76f8\u540c\u7684 IDE \u5f00\u53d1\u7a0b\u5e8f\uff0c\u56e0\u800c\u63d0\u4f9b\u7684\u5de5\u7a0b\/\u89e3\u51b3\u65b9\u6848\u6587\u4ef6\u53ef\u80fd\u548c\u4e00\u4e9b\u4eba\u7684 IDE \u4e0d\u517c\u5bb9\u3002\u6240\u4ee5\u4eba\u4eec\u53ea\u80fd\u4ece.c\/.cpp\u548c.h&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"http:\/\/liyanliang.net\/index.php\/2021\/01\/08\/opengl%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba-glfw%e4%b8%8eglad%e9%85%8d%e7%bd%ae-%e8%b6%85%e8%af%a6%e7%bb%86\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[15],"class_list":["post-66","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opengl","tag-opengl"],"_links":{"self":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":3,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":131,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/posts\/66\/revisions\/131"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/media\/137"}],"wp:attachment":[{"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/liyanliang.net\/index.php\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}