3d object showing through another

I am working on a project where I need one 3d object which is inside another 3d object to show through the object that it is contained within.

I thought that if I simply render the internal object after the object it is contained within, that it will effectively ‘show-through’ the other object because it will be rendered last.

I haven’t worked with OpenGL before, and so I wrote this post in the hope that someone has solved a similar problem, and wouldn’t mind sharing their knowledge.

If the larger object is writing to the Z-Buffer, then the smaller internal object will never actually draw any pixels because it’ll fail the depth test.

2 options depending on what effect you are looking for:

  1. Render the internal object first, then render the 2nd larger object with some translucency so it’s partially see-through.

  2. Render the larger object first, then disable GL_DEPTH_TEST, then render the smaller internal object.