{"id":3504,"date":"2018-01-08T19:45:37","date_gmt":"2018-01-08T11:45:37","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=3504"},"modified":"2018-10-14T21:32:09","modified_gmt":"2018-10-14T13:32:09","slug":"opengl_line","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/opengl_line\/","title":{"rendered":"OpenGL\u4e4b\u7e6a\u756b\u76f4\u7dda"},"content":{"rendered":"<figure id=\"attachment_3519\" aria-describedby=\"caption-attachment-3519\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_Line.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3519\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_Line.jpg\" alt=\"\" width=\"1024\" height=\"768\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_Line.jpg 1024w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_Line-300x225.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_Line-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-3519\" class=\"wp-caption-text\">OpenGL\u4e4b\u7e6a\u756b\u76f4\u7dda<\/figcaption><\/figure>\n<p>OpenGL\u652f\u6301\u57fa\u672c\u5e7e\u4f55\u76f4\u7dda\u7e6a\u756b,\u4f7f\u7528glVertex()\u751f\u6210\u7e6a\u756b\u76f8\u9023\u76f4\u7dda\u7684\u6f14\u793a\u7a0b\u5f0f\u5982\u4e0a\u5716:<a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGLLine.zip\">\u4e0b\u8f09<\/a><\/p>\n<ol>\n<li>\u6309\u9f20\u6a19\u5de6\u9375\u9ede\u64ca\u7e6a\u756b\u76f8\u9023\u76f4\u7dda<\/li>\n<li>\u6309+\u9375\u52a0\u5927\u76f4\u7dda\u5bec\u5ea6<\/li>\n<li>\u6309-\u9375\u6e1b\u5c0f\u76f4\u7dda\u5bec\u5ea6<\/li>\n<li>\u6309S\u9375\u5207\u63db\u76f4\u7dda\u6297\u92f8\u9f52\u529f\u80fd<\/li>\n<li>\u6309.\u9375\u5207\u63db\u76f4\u7dda\u9ede\u756b\u6a21\u5f0f(\u865b\u7dda)<\/li>\n<li>\u63091\u9375\u5207\u63db\u4e3a\u767d\u8272<\/li>\n<li>\u63092\u9375\u5207\u63db\u4e3a\u9ec4\u8272<\/li>\n<li>\u63093\u9375\u5207\u63db\u4e3a\u7ea2\u8272<\/li>\n<li>\u63094\u9375\u6bcf\u5169\u500b\u9802\u9ede\u7d44\u6210\u7684\u76f4\u7dda<\/li>\n<li>\u63095\u9375\u7531\u591a\u500b\u9802\u9ede\u7d44\u6210\u7684\u76f8\u9023\u76f4\u7dda<\/li>\n<li>\u63096\u9375\u7531\u591a\u500b\u9802\u9ede\u7d44\u6210\u76f8\u9023\u7684\u9589\u5408\u76f4\u7dda<\/li>\n<\/ol>\n<p>\u7e6a\u756b\u76f4\u7dda<\/p>\n<ol>\n<li>glLineWidth(width);\u8a2d\u7f6e\u76f4\u7dda\u5bec\u5ea6<\/li>\n<li>glBegin(GL_LINE_STRIP);\u6e96\u5099\u7e6a\u756b\u9023\u7e8c\u76f4\u7dda<\/li>\n<li>glVertex3f(x1,y1,z1);\u7e6a\u756b\u76f4\u7dda\u9802\u9ede1<\/li>\n<li>glVertex3f(x2,y2,z2);\u7e6a\u756b\u76f4\u7dda\u9802\u9ede2<\/li>\n<li>glEnd();\u7d50\u675f\u7e6a\u756b<\/li>\n<\/ol>\n<table>\n<tbody>\n<tr>\n<td width=\"284\">glBegin()\u7e6a\u756b\u76f4\u7dda\u53c3\u6578<\/td>\n<td width=\"284\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"284\">GL_LINES<\/td>\n<td width=\"284\">\u7531\u5169\u500b\u9802\u9ede\u7d44\u6210\u7684\u76f4\u7dda<\/td>\n<\/tr>\n<tr>\n<td width=\"284\">GL_LINE_STRIP<\/td>\n<td width=\"284\">\u7531\u591a\u500b\u9802\u9ede\u7d44\u6210\u7684\u76f8\u9023\u76f4\u7dda<\/td>\n<\/tr>\n<tr>\n<td width=\"284\">GL_LINE_LOOP<\/td>\n<td width=\"284\">\u7531\u591a\u500b\u9802\u9ede\u7d44\u6210\u76f8\u9023\u7684\u9589\u5408\u76f4\u7dda,\u7b2c\u4e00\u500b\u8207\u6700\u5f8c\u4e00\u500b\u9802\u9ede\u81ea\u52d5\u76f8\u9023<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u56e0\u5c4f\u5e55\u7531\u50cf\u7d20\u7d44\u6210,\u76f4\u7dda\u908a\u7de3\u6703\u7522\u751f\u92f8\u9f52,OpenGL\u6709\u6297\u92f8\u9f52\u7b97\u6cd5,\u555f\u7528\u5f8c\u76f4\u7dda\u6703\u8b8a\u5f97\u5e73\u6ed1,\u4e26\u4fee\u6539\u908a\u7de3\u50cf\u7d20\u7684\u984f\u8272:<\/p>\n<ol>\n<li>glEnable(GL_LINE_SMOOTH);\u555f\u7528\u76f4\u7dda\u7684\u5e73\u6ed1\u6a21\u5f0f(\u6297\u92f8\u9f52\u529f\u80fd)<\/li>\n<li>glEnable(GL_BLEND);\u555f\u7528\u6df7\u5408<\/li>\n<\/ol>\n<p>\u9ede\u756b\u6a21\u5f0f\u901a\u5e38\u7528\u7e6a\u756b\u865b\u7dda<\/p>\n<p>void glLineStipple(GLint factor,GLushort pattern);<\/p>\n<p>factor:\u6a21\u677f\u6bcfBIT\u5c0d\u61c9\u50cf\u7d20\u91cf<\/p>\n<p>pattern:\u75312\u500bBtye\u7d44\u6210\u9ede\u756b\u6a21\u677f<\/p>\n<ol>\n<li>glEnable(GL_LINE_STIPPLE);\u8a2d\u7f6e\u9ede\u756b\u6a21\u5f0f(\u865b\u7dda)<\/li>\n<li>glLineStipple(5,0xfafa);\u8a2d\u7f6e\u6a21\u677f<\/li>\n<\/ol>\n<p>\u958b\u555f\u76f4\u7dda\u6297\u92f8\u9f52\u7b97\u6cd5\u5f8c,\u76f4\u7dda\u5bec\u5ea6\u7bc4\u570d\u53d7\u5230\u9650\u5236,\u82e5\u8f38\u5165\u4e0d\u53d7\u652f\u6301\u76f4\u7dda\u5bec\u5ea6,\u6703\u6539\u70ba\u6700\u63a5\u8fd1\u7684\u652f\u6301\u6578\u503c:<\/p>\n<ol>\n<li>GLfloat widths[2];\u6d6e\u9ede\u6578\u6578\u7d44<\/li>\n<li>glGetFloatv(GL_LINE_WIDTH_RANGE, widths);\u63d0\u53d6\u76f4\u7dda\u5bec\u5ea6\u7684\u7bc4\u570d<\/li>\n<li>GLfloat min = widths[0];\u6700\u5c0f<\/li>\n<li>GLfloat max = widths[1];\u6700\u5927<\/li>\n<li>GLfloat granularity;<\/li>\n<li>glGetFloatv(GL_LINE_WIDTH_GRANULARITY,&amp;granularity);\u63d0\u53d6\u76f4\u7dda\u5bec\u5ea6\u7684\u7c92\u5ea6<\/li>\n<li>GLfloat width;<\/li>\n<li>glGetFloatv(GL_LINE_WIDTH,&amp;width);\u7372\u53d6\u7576\u524d\u76f4\u7dda\u5bec\u5ea6<\/li>\n<li>width = width + granularity;\u52a0\u5927<\/li>\n<li>width = width &#8211; granularity;\u6e1b\u5c0f<\/li>\n<li>glPointSize(width);\u8a2d\u7f6e\u7576\u524d\u76f4\u7dda\u5bec\u5ea6,\u4f46\u4e0d\u80fd\u5728glBegin()\u8207glEnd()\u4e4b\u9593\u8abf\u7528<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>OpenGL\u652f\u6301\u57fa\u672c\u5e7e\u4f55\u76f4\u7dda\u7e6a\u756b,\u4f7f\u7528glVertex()\u751f\u6210\u7e6a\u756b\u76f8\u9023\u76f4\u7dda\u7684\u6f14\u793a\u7a0b\u5f0f\u5982\u4e0a\u5716:\u4e0b\u8f09 \u6309\u9f20\u6a19\u5de6\u9375\u9ede &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_line\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">OpenGL\u4e4b\u7e6a\u756b\u76f4\u7dda<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[50],"class_list":["post-3504","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\/3504","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=3504"}],"version-history":[{"count":10,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3504\/revisions"}],"predecessor-version":[{"id":3529,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3504\/revisions\/3529"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=3504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=3504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=3504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}