Skip to content

Instantly share code, notes, and snippets.

@sbaer
Created June 19, 2015 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbaer/d3b6660697812b444ead to your computer and use it in GitHub Desktop.
Save sbaer/d3b6660697812b444ead to your computer and use it in GitHub Desktop.
Use OpenGL in Display Conduit
[CommandStyle(Style.Hidden)]
public class TestOpenGlCallCommand : Command
{
public override string EnglishName { get { return "TestGlCall"; } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
m_conduit.Enabled = !m_conduit.Enabled;
doc.Views.Redraw();
return Result.Success;
}
readonly MyGlConduit m_conduit = new MyGlConduit();
}
class MyGlConduit : Rhino.Display.DisplayConduit
{
protected override void PreDrawObject(Rhino.Display.DrawObjectEventArgs e)
{
if (e.Display.IsOpenGL)
{
GL.glEnable(GL.GL_CLIP_PLANE0);
double[] equation = new double[] { 1, 0, 0, 0 };
GL.glClipPlane(GL.GL_CLIP_PLANE0, equation);
}
}
protected override void PostDrawObjects(Rhino.Display.DrawEventArgs e)
{
if( e.Display.IsOpenGL)
GL.glDisable(GL.GL_CLIP_PLANE0);
}
}
static class GL
{
public const uint GL_CLIP_PLANE0 = 0x3000;
[System.Runtime.InteropServices.DllImport("opengl32.dll")]
public static extern void glEnable(uint cap);
[System.Runtime.InteropServices.DllImport("opengl32.dll")]
public static extern void glDisable(uint cap);
[System.Runtime.InteropServices.DllImport("opengl32.dll")]
public static extern void glClipPlane(uint plane, double[] equation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment