Mesh entity displayed as wireframe object

You can have a mesh entity displayed always in wireframe mode, regardless of the DisplayMode, by using the following class derived from Mesh: 

Capture.PNG 

class MyWireMesh : Mesh
    {
        public MyWireMesh(Mesh another)
            : base(another)
        {
        }

        protected override void Draw(DrawParams data)
        {
            Pre();
            gl.Color3fv(Utility.ColorToFloatArray(Color));
            base.Draw(data);
            Post();
        }

        protected override void SetShader(DrawParams data)
        {
            if (data != null)
            {
                bool prevLighting = data.ShaderParams.Lighting;
                data.ShaderParams.Lighting = false;
                base.SetShader(data);
                data.ShaderParams.Lighting = prevLighting;
            }
        }

        protected override void DrawForShadow(RenderParams data)
        {
            Pre();
            base.DrawForShadow(data);
            Post();
        }
        

        protected override void Render(RenderParams data)
        {
            Pre();
            gl.Color3fv(Utility.ColorToFloatArray(Color));
            base.Render(data);
            Post();
        }

        protected override void DrawSelected(DrawParams drawParams)
        {
            Pre();
            gl.Color3f(1, 1, 0); // Set the Selection color 
            base.DrawSelected(drawParams);
            Post();
        }

        protected override void DrawForSelection(GfxDrawForSelectionParams data)
        {
            Pre();
            base.DrawForSelection(data);
            Post();
        }

        private static void Post()
        {
            gl.PopAttrib();
            gl.PopAttrib();
            gl.PopAttrib();
        }

        private void Pre()
        {
            gl.PushAttrib(gl.ENABLE_BIT);
            gl.PushAttrib(gl.POLYGON_BIT);
            gl.PushAttrib(gl.CURRENT_BIT);

            gl.Disable(gl.LIGHTING);
            gl.Disable(gl.CULL_FACE);
            gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE);
        }
 }
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.