Search code examples
c++texture-mappingcinder

Cinder how to texture an .obj trimesh


I am new to c++/cinder and I am trying to import a 3ds .obj file into cinder and apply a simple texture. I really cant find any simple tutorials on how to do this and it seems to be slightly different to freeGLUT.

  gl::Texture sTexture;
  sTexture = gl::Texture(loadImage(loadAsset("texture.jpg")));

  cinder::TriMesh mySphere;
  ObjLoader loader( loadFile( "mySphere/sphere.obj" ) );
  loader.load( &mySphere );
  gl::draw( mySphere );

I understand that mySphere constains the texture co-ords as a vector and I need to bind the texture to the object, but I cant find a clear example of how? Everything I have tried has left me with a white circle.

Thanks.


Solution

  • Found my solution. I was using sTexture.bind(); but sTexture.enableAndBind(); is needed.

     gl::Texture sTexture;
     sTexture = gl::Texture(loadImage(loadAsset("texture.jpg")));
     sTexture.enableAndBind();
     cinder::TriMesh mySphere;
     ObjLoader loader( loadFile( "mySphere/sphere.obj" ) );
     loader.load( &mySphere );
     gl::draw( mySphere );
     sTexture.unbind();