I want to be able to draw an arrow inside a sphere. However I have many of this objects but do not want to see through them to see the other spheres behind them. Ie I want it to act like the spheres are solid but want to see the arrow within it. Is this possible? if so then how?
a) draw the spheres last in your scene
b) draw the sphee
c) disable depth testing
d) draw the arrow that corresponds to the sphere
e) re-enable depth-testing
f) go on with next spere
hmm… you do not have to draw them depth-sorted I hope i understood you right…
the more i think about it the more complicated it gets… you have to draw the polygons that make up the arrow depth-sorted in back-to-front-order (as depth testing ist disabled). and you do indeed have to draw the speres depth sorted as well, so my last post was wrong. and still, you get problems when a sphere is partially covered by a wall, then the arrow also should be covered but isn’t because of the disabled depth testing.
i think you better do it this way:
- still draw the speres as the last thing in the scene
- set depht buffer to read only (glDepthMask)
- draw a sphere, but you have to draw the polygons that make up the spere depth-sorted in back to front oder.
- re-enable depth buffer writing
- draw the arrow (without depth sorting its polygons)
- go on with next sphere.
I have another idea so this is not my last posting
the main problem is that you have to depth sort rather the sphere polygons or the arrow polygons, and i guess the arrow has much less, so it would be better to depth-sort them. but this is not possible due to what i mentioned some postings above. So I would recommend to draw the spheres by using impostors (sprites), and when drawing the sprites, you can draw the sphere with normal depth buffer functionality and only the arrow polygons depth sorted. Also, performance should increase dramatically as you do not have to update each impostor every frame, which in good cases can lead to performance increases of ca. 100x.
sorry for writing so much
You could also considered rendering the inside of the sphere instead. It will look weird but you could probably get around it if you flip the normals & texture coordinates(if any).