OpenGL mapping texture to sphere

心已入冬 提交于 2019-11-30 20:14:04

I haven't done any professional GL programming, but I've been working with 3D software quite a lot.

  • your UVs are most likely bad
  • your texture is a bad fit to project on a sphere
  • considering UVs are bad, you might want to check your normals as well
  • consider an ISOSPHERE instead of a regular one to make more efficient use of polygons

You are currently using a flat texture with flat mapping, which may give you very ugly results, since you will have very low resolution in the "outer" perimeter and most likely a nasty seam artifact where the two projections meet if you like... rotate the planet or something.

Note that you don't have to have any particular UV map, it just needs to be correct with the geometry, which it doesn't look like it is right now. The spherical mapping will take care for the rest. You could probably get away with a cylindrical map as well, since most Earth textures are in a suitable projection.

Finally, I've got the answer. Error was there:

bool Program::InitTextures(string texturePath)
{
  textureID = LoadTextureBMP_custom(texturePath);
  // GLuint TBO_ID; _ERROR_
  glGenBuffers(1,&TBO_ID);
  glBindBuffer(GL_ARRAY_BUFFER,TBO_ID);
  glBufferData(GL_ARRAY_BUFFER,uv.size()*sizeof(vec2),&uv[0],GL_STATIC_DRAW);
}

There is the part of Program class declaration:

class Program
{
 private:
  Shader shader;
  GLuint textureID;

  GLuint VAO_ID;
  GLuint VBO_ID;
  GLuint TBO_ID; // Member covered with local variable declaration in InitTextures()
  ...
}

I've erroneously declared local TBO_ID that covered TBO_ID in class scope. UVs were generated with crummy precision and seams are horrible, but they weren't problem.

I have to admit that information I've supplied is too small to enable help. I should have put all the code of Program class. Thanks everybody who tried to.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!