In my Android app I need to display a 3D object (that's no problem), but the front edges should be solid and the back edges should be dotted. I need to have something like on the picture. How can I achieve it using OpenGL ES 1 or 2?
I have tried the Tim's idea(using Depth buffer). It works but there are some artefacts like on the pictures, dotted(purple) lines overlap solid(red) lines:
It happens because dotted lines(purple colour(GL_GREATER)) are drawn AFTER red lines(GL_LEQUAL). It there any ideas how to prevent it?
Thank you everyone for helping. Now it looks great!!
Here's a rough outline of what I would do. You'll need one mesh for the object itself, and another mesh of GL_LINES for the 'edge lines' that you want to draw.
This might have problems depending on what other objects are in the scene, as you might get dotted lines drawn in the case where the cube is obscured by something else, but maybe that's not a problem for you or you can somehow cull the mesh if it is obscured.
For the stipple shader, you can set a texcoord of one vertex of the line to be zero, and another endpoint of the line to be one. Then in your shader you can use a step function similar to suggested by tencent, to reject fragments to create a stipple pattern.
You can also skip the messing with the depth buffer if you want to calculate yourself which lines are behind the object, though it could be a lot of work with anything more than a cube.
If you want to use OpenGLES 1 instead of OpenGLES 2, replace the stipple shader with a 1D texture of a stipple pattern, and texture the back lines with that. However I'm not 100% sure you can texture a line in OpenGL, so maybe this won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With