开发者

OpenGL CubeMap Texture Dimensions

开发者 https://www.devze.com 2023-01-17 01:42 出处:网络
After 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 top

OpenGL CubeMap Texture Dimensions

After 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(); 
      gluPerspecti开发者_如何学运维ve(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);
  }


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消