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: http://i.imgur.com/NyWqcRC.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\$
  • \$\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\$ – lyinch May 22 '17 at 13:40
  • \$\begingroup\$ Take the point you are trying to map and the center of your object and subtract them. \$\endgroup\$ – ratchet freak May 22 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.