OpenGL CubeMap 纹理尺寸

发布于 2024-09-24 04:32:24 字数 1427 浏览 0 评论 0原文

alt text经过整个周末的努力,我终于在 OpenGL 中得到了一个反映其环境的球体。看起来几乎不错。问题是,某些功能不一致。除了红皮书中的两页部分和一些零散且大部分未完成的论坛主题之外,我找不到关于 OpenGL 球体映射主题的太多信息。不确定是否有必要,但我在加载纹理的地方包含了我的代码。经过反复试验,我发现具有 0 到 512 之间的对称尺寸可以获得最佳结果,但它们仍然不完美(并且尺寸必须是 2 的幂,否则会崩溃)。有谁知道有什么策略可以使纹理更正确地排列吗?

void loadCubemapTextures(){

  glGenTextures(1, &cubemap);
  glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  glDrawBuffer(GL_AUX1);
  glReadBuffer(GL_AUX1);

  glMatrixMode(GL_MODELVIEW);

  //Generate cube map textures
  for(int i = 0; i < 6; i++){

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();
      //Viewing Transformation
      gluLookAt(pos[0], pos[1], pos[2],
           view_pos[i][0], view_pos[i][1], view_pos[i][2],
         top[i][0], top[i][1], top[i][2]);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity(); 
      gluPerspective(90.0, 1.0, cubemapRadius + 1, 200.0);
      glMatrixMode(GL_MODELVIEW);

      render();

      glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 0, 0, 256, 256, 0);
  }

alt textAfter struggling all weekend, I finally have a sphere reflecting its environment in OpenGL. It almost looks good. Problem is, certain features don't line up. I can't find much information on the topic of OpenGL sphere mapping, outside of a two page section in the Red Book and a few scattered, and mostly unfinished forum topics. Not sure it's necessary, but I included my code where I load the textures. After trial and error, I found that having symmetrical dimensions freom 0 to 512 gets the best results, but they still aren't perfect (and the dimensions have to be powers of two, or it crashes). Does any one know of any strategies to get textures that line up more correctly?

void loadCubemapTextures(){

  glGenTextures(1, &cubemap);
  glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  glDrawBuffer(GL_AUX1);
  glReadBuffer(GL_AUX1);

  glMatrixMode(GL_MODELVIEW);

  //Generate cube map textures
  for(int i = 0; i < 6; i++){

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();
      //Viewing Transformation
      gluLookAt(pos[0], pos[1], pos[2],
           view_pos[i][0], view_pos[i][1], view_pos[i][2],
         top[i][0], top[i][1], top[i][2]);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity(); 
      gluPerspective(90.0, 1.0, cubemapRadius + 1, 200.0);
      glMatrixMode(GL_MODELVIEW);

      render();

      glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 0, 0, 256, 256, 0);
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尬尬 2024-10-01 04:32:24

你的墙壁缺乏足够的功能来明确它们的方向和位置,但我敢打赌这些就是问题所在。

view_postop 中的值定义了它们。其中看起来可疑的事情之一是:

  • 该区域底部的黑色来自于拍摄前视图的脸部。它应该位于顶部(即翻转或旋转 180 度)。
  • 同样,来自视图背面(位于球体中心)的黑色看起来旋转了四分之一圆(因为黑色位于左侧而不是顶部)。
  • 地图球体的反射看起来很奇怪。它缺乏分辨率来弄清楚这到底是什么。

无论如何,要修复它,您可以确保您的值是正确的立方体贴图定义所期望的值(如检查所有规范),或者在添加足够的几何图形后进行大量试验和错误来找出答案每个面的方向是什么。

Your walls lack enough features to make their orientation and location clear, but I would bet those are the issue.

The values you have in view_pos and top are what define those. Among the things that look suspicious:

  • the black at the bottom of the shere comes from the face that captured the front view. It should be at the top (ie it's either flipped, or rotated 180).
  • likewise, the black that comes from the back of the view (in the center of the sphere) looks turned by a quarter of a circle (as black goes on the left rather than being on the top).
  • the reflection of the map sphere looks weird. It lacks resolution to figure out exactly what this is.

Anyways, to fix it, you can either make sure your values are what is expected from a proper cube-map definition (as in check all the specification), or just do a bunch of trial and error, after adding enough geometry to figure out what the orientation of each face is.

ぇ气 2024-10-01 04:32:24

该问题与坐标无关,但感谢您的输入。我忘记设置视图矩阵...在 for 循环中对 gluViewport 的简单调用为我修复了它。

The problem had nothing to do with coordinates, thanks for the input though. I had forgotten to set the view matrix... a simple call to gluViewport inside the for-loop fixed it for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文