{"id":3663,"date":"2018-01-30T17:17:35","date_gmt":"2018-01-30T09:17:35","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=3663"},"modified":"2018-10-14T21:23:31","modified_gmt":"2018-10-14T13:23:31","slug":"opengl_fog","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/opengl_fog\/","title":{"rendered":"OpenGL\u4e4b\u7159\u9727"},"content":{"rendered":"<figure id=\"attachment_3664\" aria-describedby=\"caption-attachment-3664\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_FOG.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3664\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_FOG.jpg\" alt=\"\" width=\"1024\" height=\"768\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_FOG.jpg 1024w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_FOG-300x225.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGL_FOG-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-3664\" class=\"wp-caption-text\">OpenGL\u4e4b\u7159\u9727<\/figcaption><\/figure>\n<p>\u7159\u9727(Fog)\u4f7f\u9060\u8ddd\u96e2\u7684\u7269\u9ad4\u8b8a\u6697,\u8fd1\u8ddd\u96e2\u7684\u7269\u9ad4\u8b8a\u5f97\u6e05\u6670.\u662f\u904a\u6232\u4e2d\u5e38\u7528\u7279\u6548.OpenGL\u7159\u9727\u5c07\u6bcf\u500b\u50cf\u7d20\u7159\u9727\u8272\u9032\u884c\u6df7\u5408\u8655\u7406.<\/p>\n<p>\u7159\u9727\u6f14\u793a\u7a0b\u5f0f:<a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/01\/OpenGLFog.zip\">\u4e0b\u8f09<\/a><\/p>\n<ol>\n<li>\u6309+\/-\u9375\u79fb\u52d5\u7159\u9727\u8ddd\u96e2<\/li>\n<li>\u6309ESC\u9375\u91cd\u7f6e\u805a\u7159\u9727<\/li>\n<\/ol>\n<p>\u7159\u9727\u51fd\u5f0f\u6f14\u793a:<\/p>\n<ol>\n<li>glEnable(GL_FOG);<\/li>\n<li>GLfloat fogColor[] = { 0f, 0.0f, 0.0f };<\/li>\n<li>glFogfv(GL_FOG_COLOR, fogColor);<\/li>\n<li>glFogi(GL_FOG_MODE, GL_LINEAR);<\/li>\n<li>glFogi(GL_FOG_COORD_SRC,GL_FRAGMENT_DEPTH);<\/li>\n<li>glFogf(GL_FOG_START, start);<\/li>\n<li>glFogf(GL_FOG_END, end);<\/li>\n<li>glFogf(GL_FOG_DENSITY, 2f);<\/li>\n<li>Draw_Terrain();<\/li>\n<li>glDisable(GL_FOG);<\/li>\n<\/ol>\n<p>OpenGL\u901a\u904eglFog()\u51fd\u5f0f\u8a2d\u5b9a\u7684\u8ddd\u96e2\u3001\u984f\u8272\u3001\u5bc6\u5ea6\u751f\u6210\u7159\u9727<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"361\">\u53c3\u6578<\/td>\n<td width=\"284\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"361\">glFogi(GL_FOG_MODE, GL_LINEAR);<\/td>\n<td width=\"284\">\u8a2d\u5b9a\u6df7\u5408\u65b9\u7a0b\u5f0f<\/p>\n<p>GL_LINEAR:\u7dda\u6027\u6df7\u5408<\/p>\n<p>GL_EXP:\u6307\u6578\u6df7\u5408(\u9ed8\u8a8d\u503c)<\/p>\n<p>GL_EXP2:\u4e8c\u6b21\u6307\u6578\u6307\u6578\u6df7\u5408<\/td>\n<\/tr>\n<tr>\n<td width=\"361\">glFogf(GL_FOG_DENSITY, 1.2f);<\/td>\n<td width=\"284\">\u7159\u9727\u7684\u55ae\u4f4d\u5bc6\u5ea6,\u6578\u503c\u9700\u70ba\u6b63,\u9ed8\u8a8d\u503c\u70ba1.0<\/td>\n<\/tr>\n<tr>\n<td width=\"361\">glFogf(GL_FOG_START, start);<\/td>\n<td width=\"284\">\u7159\u9727\u8ddd\u96e2\u8996\u53e3\u7684\u8fd1\u7aef\u8ddd\u96e2<\/td>\n<\/tr>\n<tr>\n<td width=\"361\">glFogf(GL_FOG_END, end);<\/td>\n<td width=\"284\">\u7159\u9727\u8ddd\u96e2\u8996\u53e3\u7684\u9060\u7aef\u8ddd\u96e2<\/td>\n<\/tr>\n<tr>\n<td width=\"361\">glFogi(GL_FOG_INDEX, 0);<\/td>\n<td width=\"284\">\u8a2d\u5b9a\u7159\u9727\u984f\u82728\u4f4d\u8abf\u8272\u7248\u7d22\u5f15<\/td>\n<\/tr>\n<tr>\n<td width=\"361\">GLfloat fogColor[] = { 0.5f, 0.5f, 0.5f };<\/p>\n<p>glFogfv(GL_FOG_COLOR, fogColor);<\/td>\n<td width=\"284\">\u8a2d\u5b9a\u7159\u9727\u984f\u8272(RGB),\u9ed8\u8a8d\u70ba\u9ed1\u8272.<\/td>\n<\/tr>\n<tr>\n<td width=\"361\">glFogi(GL_FOG_COORD_SRC,<\/p>\n<p>GL_FRAGMENT_DEPTH);<\/td>\n<td width=\"284\">\u6df1\u5ea6\u503c<\/p>\n<p>GL_FRAGMENT_DEPTH:\u8996\u53e3\u8207\u7159\u9727\u7684\u8ddd\u96e2(\u9ed8\u8a8d\u503c)<\/p>\n<p>GL_FOG_COORD:\u4f7f\u7528glFogCoordf();\u8a2d\u5b9a\u7159\u9727\u5750\u6a19<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"359\">\u6df7\u5408\u65b9\u7a0b\u5f0f<\/td>\n<td width=\"209\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"359\">Color=blendFactor*in + (1-blendFactor)*fog<\/td>\n<td width=\"209\">\u6df7\u5408\u65b9\u7a0b\u5f0f<\/td>\n<\/tr>\n<tr>\n<td width=\"359\">blendFactor<\/td>\n<td width=\"209\">\u6df7\u5408\u56e0\u5b50<\/td>\n<\/tr>\n<tr>\n<td width=\"359\">in<\/td>\n<td width=\"209\">\u8f38\u5165\u984f\u8272<\/td>\n<\/tr>\n<tr>\n<td width=\"359\">fog<\/td>\n<td width=\"209\">\u7159\u9727\u984f\u8272<\/td>\n<\/tr>\n<tr>\n<td width=\"359\">Color<\/td>\n<td width=\"209\">\u8f38\u51fa\u984f\u8272<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"119\">\u6df7\u5408\u56e0\u5b50\u65b9\u7a0b\u5f0f<\/td>\n<td width=\"449\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"119\">GL_LINEAR<\/td>\n<td width=\"449\">\u7dda\u6027\u6df7\u5408<\/p>\n<p>blendFactor=(end-depth)\/(end-start)<\/td>\n<\/tr>\n<tr>\n<td width=\"119\">GL_EXP<\/td>\n<td width=\"449\">\u6307\u6578\u6df7\u5408(\u9ed8\u8a8d\u503c)<\/p>\n<p>blendFactor= EXP (e, -density*depth)<\/td>\n<\/tr>\n<tr>\n<td width=\"119\">GL_EXP2<\/td>\n<td width=\"449\">\u4e8c\u6b21\u6307\u6578\u6307\u6578\u6df7\u5408<\/p>\n<p>blendFactor= EXP(EXP (e, -density*depth),2)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7159\u9727(Fog)\u4f7f\u9060\u8ddd\u96e2\u7684\u7269\u9ad4\u8b8a\u6697,\u8fd1\u8ddd\u96e2\u7684\u7269\u9ad4\u8b8a\u5f97\u6e05\u6670.\u662f\u904a\u6232\u4e2d\u5e38\u7528\u7279\u6548.OpenGL\u7159\u9727\u5c07\u6bcf\u500b\u50cf\u7d20\u7159\u9727\u8272\u9032\u884c &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_fog\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">OpenGL\u4e4b\u7159\u9727<\/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-3663","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\/3663","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=3663"}],"version-history":[{"count":2,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3663\/revisions"}],"predecessor-version":[{"id":3667,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3663\/revisions\/3667"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=3663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=3663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=3663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}