1
\$\begingroup\$

I am wondering whether its possible to automatically generate texture coordinates for custom obj models to work with cubemaps. Every tutorial I see online is about environment mapping. Is it possible to write a shader that allows me to generate UV's like in this image: https://i.sstatic.net/3jID5.jpg

So far I've loaded cubemap texture:

bool Texture::LoadCubicTexture(vector<string> filenameTable)
{
  glGenTextures(1,&texID);
  glBindTexture(GL_TEXTURE_CUBE_MAP,texID);

  glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);

  int i = 0;
  vector<string>::iterator vsit;

  // There is always six filenames
  for(vsit=filenameTable.begin();vsit!=filenameTable.end();++vsit)
  {
    string filename = *vsit;
    BMPData* bmpData = LoadTextureBMPData_custom(filename);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,GL_RGB,bmpData->width,bmpData->height,0,GL_BGR,GL_UNSIGNED_BYTE,&(bmpData->data[0]));
    i++;
    delete daneObrazu;
  }
  glGenerateMipmap(GL_TEXTURE_CUBE_MAP);

  return true;
}

I've also have my custom .obj posted online here: https://pastebin.com/NVKgrGGZ

\$\endgroup\$
2
  • \$\begingroup\$ Did you have a look at: nvidia.com/object/cube_map_ogl_tutorial.html especially the paragraph Mapping Texture Coordinates to Cube Map Faces \$\endgroup\$ Commented May 22, 2017 at 13:40
  • \$\begingroup\$ Take the point you are trying to map and the center of your object and subtract them. \$\endgroup\$ Commented May 22, 2017 at 14:19

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.