{"id":3899,"date":"2018-03-31T20:23:03","date_gmt":"2018-03-31T12:23:03","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=3899"},"modified":"2018-10-14T21:21:16","modified_gmt":"2018-10-14T13:21:16","slug":"opengl_environment","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/opengl_environment\/","title":{"rendered":"OpenGL\u4e4b\u74b0\u5883\u6620\u5c04"},"content":{"rendered":"<figure id=\"attachment_3900\" aria-describedby=\"caption-attachment-3900\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_Environment.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3900\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_Environment.jpg\" alt=\"\" width=\"1024\" height=\"768\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_Environment.jpg 1024w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_Environment-300x225.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGL_Environment-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-3900\" class=\"wp-caption-text\">OpenGL\u4e4b\u74b0\u5883\u6620\u5c04<\/figcaption><\/figure>\n<p>\u74b0\u5883\u6620\u5c04\u5373\u5728\u8868\u9762\u300e\u6620\u5c04\u300f\u5176\u5b83\u7269\u9ad4,\u5982\u6e56\u9762\u4e0a\u300e\u6620\u5c04\u300f\u51fa\u300e\u6a39\u3001\u96f2\u3001\u5929\u3001\u4eba\u300f,\u800cOpenGL\u4e26\u4e0d\u662f\u771f\u6b63\u5730\u5c0d\u74b0\u5883\u9032\u884c\u53cd\u5c04\u7372\u5f97\u7684\u6548\u679c.\u6f14\u793a\u51fd\u5f0f<a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/03\/OpenGLEnvironment.zip\">\u4e0b\u8f09<\/a>:<\/p>\n<ol>\n<li>\u5275\u5efa\u7269\u9ad4\u8868\u9762\u7684\u7d0b\u7406\u5716<\/li>\n<li>\u4f7f\u7528OpenGL\u81ea\u52d5\u751f\u6210\u76f8\u61c9\u7684\u7d0b\u7406\u5ea7\u6a19,\u53ef\u4ee5\u4f7f\u7528GL_SPHERE_MAP(\u7403\u9ad4\u6620\u5c04)\u548cGL_REFLECTION_MAP(\u53cd\u5c04\u5149\u6620\u5c04)<\/li>\n<li>\u79fb\u52d5\u93e1\u982d\u5230\u7269\u9ad4\u4e26\u6307\u5411\u8996\u9ede<\/li>\n<li>\u96a8\u8457\u7269\u9ad4\u7684\u79fb\u52d5\u800c\u751f\u6210\u65b0\u7684\u7d0b\u7406\u5ea7\u6a19,\u4f7f\u5f97\u74b0\u5883\u53cd\u5c04\u6548\u679c\u96a8\u8457\u7269\u9ad4\u79fb\u52d5\u800c\u8b8a\u5316,\u4f7f\u7528glCopyTexImage2D()\u548cglCopyTexSubImage2D()\u5f9e\u5c4f\u5e55\u4e0a\u62f7\u8c9d\u4e26\u751f\u6210\u7d0b\u7406<\/li>\n<li>\u5982\u679c\u8981\u586b\u5145\u591a\u908a\u5f62\u984f\u8272,\u4f60\u8981\u7981\u7528\u7d0b\u7406glDisable(GL_TEXTURE_2D);\u624d\u80fd\u6b63\u78ba\u6e32\u67d3.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>\u7d0b\u7406\u5ea7\u6a19\u751f\u6210\u51fd\u5f0f:<\/p>\n<p>void glTexGenf(GLenum coord,GLenum pname, GLenum param)<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"277\">glTexGenf()\u51fd\u5f0fcoord:<\/td>\n<td width=\"277\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">GL_S<\/td>\n<td width=\"277\">s\u7d0b\u7406\u5750\u6a19<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">GL_T<\/td>\n<td width=\"277\">t\u7d0b\u7406\u5750\u6a19<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">GL_R<\/td>\n<td width=\"277\">r\u7d0b\u7406\u5750\u6a19<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">GL_Q<\/td>\n<td width=\"277\">q\u7d0b\u7406\u5750\u6a19<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"277\">glTexGenf()\u51fd\u5f0fpname:<\/td>\n<td width=\"277\">param\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">GL_TEXTURE_GEN_MODE<\/td>\n<td width=\"277\">GL_SPHERE_MAP<\/p>\n<p>GL_REFLECTION_MAP<\/p>\n<p>GL_OBJECT_LINEAR<\/p>\n<p>GL_EYE_LINEAR<\/p>\n<p>GL_NORMAL_MAP<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">GL_OBJECT_PLANE<\/td>\n<td width=\"277\">Param\u6307\u5411\u751f\u6210\u7d0b\u7406\u5750\u6a19\u6240\u9700\u76844\u500b\u5143\u7d20,\u914d\u5408GL_OBJECT_LINEAR\u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">GL_EYE_PLANE<\/td>\n<td width=\"277\">Param\u6307\u5411\u751f\u6210\u7d0b\u7406\u5750\u6a19\u6240\u9700\u76844\u500b\u5143\u7d20,\u914d\u5408GL_EYE_LINEAR\u4f7f\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u751f\u6210\u74b0\u5883\u6620\u5c04\u7d0b\u7406\u4ee3\u78bc<\/p>\n<p>glGenTextures(1, &amp;texture.ID);<\/p>\n<p>glBindTexture(GL_TEXTURE_CUBE_MAP, texture.ID);<\/p>\n<p>\u8a2d\u5b9a\u7d0b\u7406\u53c3\u6578\u4ee3\u78bc<\/p>\n<p>glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);<\/p>\n<p>glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);<\/p>\n<p>glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);<\/p>\n<p>glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);<\/p>\n<p>\u5c07\u7d0b\u7406\u5750\u6a19\u751f\u6210\u6a21\u5f0f\u8a2d\u7f6e\u70ba\u74b0\u5883\u6620\u5c04(\u53cd\u5c04\u5149)\u51fd\u5f0f<\/p>\n<p>glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);<\/p>\n<p>glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);<\/p>\n<p>glTexGenf(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);<\/p>\n<p>&nbsp;<\/p>\n<p>\u79fb\u52d5\u93e1\u982d\u5230\u7269\u9ad4\u4e26\u6307\u5411\u8996\u9ede,\u8a2d\u7f6e\u5c4f\u5e55\u4ee5\u5339\u914d\u74b0\u5883\u6620\u5c04\u7684\u5927\u5c0f<\/p>\n<p>glViewport(0, 0, 256,256);<\/p>\n<p>glMatrixMode(GL_PROJECTION);<\/p>\n<p>glLoadIdentity();<\/p>\n<p>\u8a2d\u7f6e90\u5ea6\u8996\u53e3<\/p>\n<p>gluPerspective(90, 1, 0.1, 500);<\/p>\n<p>glMatrixMode(GL_MODELVIEW);<\/p>\n<p>glClear(GL_DEPTH_BUFFER_BIT);<\/p>\n<p>\u8f09\u5165\u55ae\u4f4d\u77e9\u9663<\/p>\n<p>glLoadIdentity();<\/p>\n<p>\u8a2d\u5b9a\u76f8\u6a5f<\/p>\n<p>gluLookAt(0.0, 0.0, 0.0,posx,posy,posz,neggx,negy,negz);<\/p>\n<p>\u901a\u904eglCopyTexImage2D()\u548cglCopyTexSubImage2D()\u5f9e\u5c4f\u5e55\u4e0a\u62f7\u8c9d\u4e26\u751f\u6210\u74b0\u93e1\u6620\u5c04\u7d0b\u7406<\/p>\n<p>\u5f9e\u7de9\u885d\u5340\u4e2d\u62f7\u8c9d\u50cf\u7d20\u5275\u5efa\u7d0b\u7406\u51fd\u5f0f<\/p>\n<p>typedef void glCopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);<\/p>\n<p>\u5f9e\u7de9\u885d\u5340\u4e2d\u62f7\u8c9d\u90e8\u5206\u50cf\u7d20\u5275\u5efa\u7d0b\u7406\u51fd\u5f0f<\/p>\n<p>typedef void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);<\/p>\n<p>&nbsp;<\/p>\n<p>\u6e32\u67d3\u74b0\u93e1\u6620\u5c04\u4ee3\u78bc<\/p>\n<p>glEnable(GL_TEXTURE_GEN_S);<\/p>\n<p>glEnable(GL_TEXTURE_GEN_T);<\/p>\n<p>glEnable(GL_TEXTURE_GEN_R);<\/p>\n<p>\u4f7f\u7528\u7acb\u65b9\u9ad4\u6620\u5c04<\/p>\n<p>glEnable(GL_TEXTURE_CUBE_MAP);<\/p>\n<p>glBindTexture(GL_TEXTURE_CUBE_MAP, texture.ID);<\/p>\n<p>glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);<\/p>\n<p>gluSphere(quadric, 1.0, 64, 64);\/\/ \u7e6a\u756b\u5927\u7403\u7403\u9ad4<\/p>\n<p>glDisable(GL_TEXTURE_CUBE_MAP);<\/p>\n<p>glDisable(GL_TEXTURE_GEN_S);<\/p>\n<p>glDisable(GL_TEXTURE_GEN_T);<\/p>\n<p>glDisable(GL_TEXTURE_GEN_R);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u74b0\u5883\u6620\u5c04\u5373\u5728\u8868\u9762\u300e\u6620\u5c04\u300f\u5176\u5b83\u7269\u9ad4,\u5982\u6e56\u9762\u4e0a\u300e\u6620\u5c04\u300f\u51fa\u300e\u6a39\u3001\u96f2\u3001\u5929\u3001\u4eba\u300f,\u800cOpenGL\u4e26\u4e0d\u662f\u771f\u6b63\u5730\u5c0d\u74b0\u5883\u9032\u884c\u53cd &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_environment\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">OpenGL\u4e4b\u74b0\u5883\u6620\u5c04<\/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-3899","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\/3899","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=3899"}],"version-history":[{"count":1,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3899\/revisions"}],"predecessor-version":[{"id":3902,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3899\/revisions\/3902"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=3899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=3899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=3899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}