Created
June 19, 2015 05:38
-
-
Save sbaer/d3b6660697812b444ead to your computer and use it in GitHub Desktop.
Use OpenGL in Display Conduit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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