- public class glu
- {
- private const string GLUDLLName="GLU32.DLL";
- public const int TESS_BEGIN = 100100;
- public const int TESS_VERTEX = 100101;
- public const int TESS_END = 100102;
- public const int TESS_ERROR = 100103;
- public const int TESS_COMBINE = 100105;
- public const int TESS_WINDING_RULE = 100140;
- public const int TESS_WINDING_ODD = 100130;
- public const int TESS_WINDING_NONZERO = 100131;
- public const int TESS_WINDING_POSITIVE = 100132;
- public const int TESS_WINDING_NEGATIVE = 100133;
- public const int TESS_WINDING_ABS_GEQ_TWO = 100134;
- [StructLayout(LayoutKind.Sequential)]
- public struct Tesselator
- {
- /// Keeps the struct from being garbage collected prematurely.
- private IntPtr Data;
- }
- public delegate void TessBeginCallback(int type);
- public delegate void TessEndCallback();
- public delegate void TessVertexCallback([MarshalAs(UnmanagedType.LPArray, SizeConst = 3)] double[] vertexData);
- public delegate void TessErrorCallback(int errorCode);
- public delegate void TessCombineCallback([In, MarshalAs(UnmanagedType.LPArray, SizeConst = 3)] double[] coordinates, [In, MarshalAs(UnmanagedType.LPArray, SizeConst = 4)] double[] vertexData, [In, MarshalAs(UnmanagedType.LPArray, SizeConst = 4)] float[] weight, ref double[] outData);
- /// local copy of the degates, prevents the GC from collecting them
- private static TessBeginCallback _tessBeginCallback;
- private static TessEndCallback _tessEndCallback;
- private static TessVertexCallback _tessVertexCallback;
- private static TessErrorCallback _tessErrorCallback;
- private static TessCombineCallback _tessCombineCallback;
- [DllImport(GLUDLLName, EntryPoint = "gluErrorString")]
- private static extern IntPtr ErrorString_(int errCode);
- [DllImport(GLUDLLName, EntryPoint = "gluGetString")]
- private static extern IntPtr GetString_(int errCode);
- [DllImport(GLUDLLName, EntryPoint = "gluOrtho2D")]
- public static extern void Ortho2D(double left, double right, double bottom,double top);
- [DllImport(GLUDLLName, EntryPoint = "gluPerspective")]
- public static extern void Perspective(double fovy, double aspect, double zNear,double zFar);
- [DllImport(GLUDLLName, EntryPoint = "gluPickMatrix")]
- public static extern void PickMatrix(double x, double y, double width,double height, int[] viewport);
- [DllImport(GLUDLLName, EntryPoint = "gluLookAt")]
- public static extern void LookAt(double eyex, double eyey, double eyez,double centerx,double centery,double centerz,double upx, double upy, double upz);
- [DllImport(GLUDLLName, EntryPoint = "gluProject")]
- public static extern void Project(double objx, double objy, double objz, double[] modelMatrix, double[] projMatrix, int[] viewport, out double winx, out double winy, out double winz);
- [DllImport(GLUDLLName, EntryPoint = "gluUnProject")]
- public static extern void UnProject(double winx, double winy, double winz, double[] modelMatrix, double[] projMatrix, int[] viewport, out double objx, out double objy, out double objz);
- [DllImport(GLUDLLName, EntryPoint = "ScaleImage")]
- public static extern void ScaleImage(int format, int widthin, int heightin,int typein, IntPtr datain, int widthout, int heightout, int typeout, IntPtr dataout);
- [DllImport(GLUDLLName, EntryPoint = "gluBuild1DMipmaps")]
- public static extern int Build1DMipmaps(int target, int components, int width, int format, int type, IntPtr data);
- [DllImport(GLUDLLName, EntryPoint = "gluBuild2DMipmaps")]
- public static extern int Build2DMipmaps(int target, int components, int width, int height, int format, int type, IntPtr data);
- [DllImport(GLUDLLName, EntryPoint = "gluNewTess")]
- public static extern Tesselator NewTess();
- [DllImport(GLUDLLName, EntryPoint = "gluTessCallback")]
- private static extern void _TessCallback(Tesselator tess, int which, TessBeginCallback func);
- public static void TessCallback(Tesselator tess, int which, TessBeginCallback func)
- {
- _tessBeginCallback = func;
- _TessCallback(tess, which, _tessBeginCallback);
- }
- [DllImport(GLUDLLName, EntryPoint = "gluTessCallback")]
- private static extern void _TessCallback(Tesselator tess, int which, TessEndCallback func);
- public static void TessCallback(Tesselator tess, int which, TessEndCallback func)
- {
- _tessEndCallback = func;
- _TessCallback(tess, which, _tessEndCallback);
- }
- [DllImport(GLUDLLName, EntryPoint = "gluTessCallback")]
- private static extern void _TessCallback(Tesselator tess, int which, TessVertexCallback func);
- public static void TessCallback(Tesselator tess, int which, TessVertexCallback func)
- {
- _tessVertexCallback = func;
- _TessCallback(tess, which, _tessVertexCallback);
- }
- [DllImport(GLUDLLName, EntryPoint = "gluTessCallback")]
- private static extern void _TessCallback(Tesselator tess, int which, TessErrorCallback func);
- public static void TessCallback(Tesselator tess, int which, TessErrorCallback func)
- {
- _tessErrorCallback = func;
- _TessCallback(tess, which, _tessErrorCallback);
- }
- [DllImport(GLUDLLName, EntryPoint = "gluTessCallback")]
- private static extern void _TessCallback(Tesselator tess, int which, TessCombineCallback func);
- public static void TessCallback(Tesselator tess, int which, TessCombineCallback func)
- {
- _tessCombineCallback = func;
- _TessCallback(tess, which, _tessCombineCallback);
- }
- [DllImport(GLUDLLName, EntryPoint = "gluTessBeginPolygon")]
- public static extern void TessBeginPolygon(Tesselator tess, double[] data);
- [DllImport(GLUDLLName, EntryPoint = "gluTessEndPolygon")]
- public static extern void TessEndPolygon(Tesselator tess);
- [DllImport(GLUDLLName, EntryPoint = "gluTessBeginContour")]
- public static extern void TessBeginContour(Tesselator tess);
- [DllImport(GLUDLLName, EntryPoint = "gluTessEndContour")]
- public static extern void TessEndContour(Tesselator tess);
- [DllImport(GLUDLLName, EntryPoint = "gluTessVertex")]
- public static extern void TessVertex(Tesselator tess, double[] location, double[] data);
- [DllImport(GLUDLLName, EntryPoint = "gluTessProperty")]
- public static extern void TessProperty(Tesselator tess, int which, double data);
- public static string GetString(int name)
- {
- IntPtr i = GetString_(name);
- return Marshal.PtrToStringAnsi(i);
- }
- public static string ErrorString(int name)
- {
- IntPtr i = ErrorString_(name);
- return Marshal.PtrToStringAnsi(i);
- }
- }