private void InitializeGlControl() { // TODO: в более надлежащее место OpenGlApplication.Setup(); _glControl = new GLControl { Parent = openTkControlContainer, Dock = DockStyle.Fill }; _glControl.CreateControl(); _glControl.Resize += GlControlOnResize; GL.Viewport(Point.Empty, _glControl.Size); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); OpenGlApplication.EnableDebugMessages(); // TODO: в более надлежащее место Singleton.Get <OpenClApplication>().SetupUsingOpenGLContext(); _glControl.Paint += GlControlOnPaint; _glControl.MouseClick += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseClickEvent(args)); _glControl.MouseDoubleClick += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseDoubleClickEvent(args)); _glControl.MouseDown += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseDownEvent(args)); _glControl.MouseUp += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseUpEvent(args)); _glControl.MouseMove += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseMoveEvent(args)); _glControl.MouseWheel += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseWheelEvent(args)); }
static void RunSimple() { using (var app = new OpenGlApplication()) { var win = app.CreateSimpleRenderWindow(1); SetScene(win); win.Run(); } }
static void Main(string[] args) { Ag.initialize(); Aardvark.Base.Aardvark.Init(); using (var app = new OpenGlApplication()) { var win = app.CreateSimpleRenderWindow(1); var view = CameraView.LookAt(new V3d(2.0, 2.0, 2.0), V3d.Zero, V3d.OOI); var perspective = win.Sizes.Select(s => FrustumModule.perspective(60.0, 0.1, 10.0, ((float)s.X / (float)s.Y))); var viewTrafo = DefaultCameraController.control(win.Mouse, win.Keyboard, win.Time, view); var index = new[] { 0, 1, 2, 0, 2, 3 }; var positions = new[] { new V3f(-1, -1, 0), new V3f(1, -1, 0), new V3f(1, 1, 0), new V3f(-1, 1, 0) }; var attributes = new SymbolDict <Array>() { { DefaultSemantic.Positions, positions } }; var quad = new IndexedGeometry(IndexedGeometryMode.TriangleList, (Array)index, attributes, new SymbolDict <Object>()); var quadSg = quad.ToSg(); // This is one of the hardest parts in C#. Our FShade interface is rather generic and // works super awesome in F#. In C# however, without proper type inference doing simple function // calls suddenly requires a Phd in CS. Therefore, and especially since shaders cannot be written // in C# anyways, write application setup and shader code in F# ;) // Or don't use FShade. FShade simply does not work in without functional language // features such as type inference and function currying. Func <DefaultSurfaces.Vertex, FSharpExpr <V4d> > whiteShader = HighFun.ApplyArg0 <C4f, DefaultSurfaces.Vertex, FSharpExpr <V4d> >( DefaultSurfaces.constantColor, C4f.White); Func <DefaultSurfaces.Vertex, FSharpExpr <DefaultSurfaces.Vertex> > trafo = c => DefaultSurfaces.trafo(c); var sg = quadSg .WithEffects(new[] { FShadeSceneGraph.toEffect(FSharpFuncUtil.Create(trafo)), FShadeSceneGraph.toEffect(FSharpFuncUtil.Create(whiteShader)), }) .ViewTrafo(viewTrafo.Select(t => t.ViewTrafo)) .ProjTrafo(perspective.Select(t => t.ProjTrafo())); var task = app.Runtime.CompileRender(win.FramebufferSignature, sg); win.RenderTask = DefaultOverlays.withStatistics(task); win.Run(); } }
static void Main(string[] args) { Ag.initialize(); Aardvark.Base.Aardvark.Init(); using (var app = new OpenGlApplication()) { var win = app.CreateSimpleRenderWindow(1); var view = CameraView.LookAt(new V3d(2.0, 2.0, 2.0), V3d.Zero, V3d.OOI); var perspective = win.Sizes.Select(s => FrustumModule.perspective(60.0,0.1,10.0,((float) s.X / (float) s.Y))); var viewTrafo = DefaultCameraController.control(win.Mouse, win.Keyboard, win.Time, view); var index = new[] { 0, 1, 2, 0, 2, 3 }; var positions = new[] { new V3f(-1, -1, 0), new V3f(1, -1, 0), new V3f(1, 1, 0), new V3f(-1, 1, 0) }; var attributes = new SymbolDict<Array>() { { DefaultSemantic.Positions, positions } }; var quad = new IndexedGeometry(IndexedGeometryMode.TriangleList, (Array)index, attributes, new SymbolDict<Object>()); var quadSg = quad.ToSg(); // This is one of the hardest parts in C#. Our FShade interface is rather generic and // works super awesome in F#. In C# however, without proper type inference doing simple function // calls suddenly requires a Phd in CS. Therefore, and especially since shaders cannot be written // in C# anyways, write application setup and shader code in F# ;) // Or don't use FShade. FShade simply does not work in without functional language // features such as type inference and function currying. Func<DefaultSurfaces.Vertex, FSharpExpr<V4d>> whiteShader = HighFun.ApplyArg0<C4f, DefaultSurfaces.Vertex, FSharpExpr<V4d>>( DefaultSurfaces.constantColor, C4f.White); Func<DefaultSurfaces.Vertex, FSharpExpr<DefaultSurfaces.Vertex>> trafo = c => DefaultSurfaces.trafo(c); var sg = quadSg .WithEffects(new[] { FShadeSceneGraph.toEffect(FSharpFuncUtil.Create(trafo)), FShadeSceneGraph.toEffect(FSharpFuncUtil.Create(whiteShader)), }) .ViewTrafo(viewTrafo.Select(t => t.ViewTrafo)) .ProjTrafo(perspective.Select(t => t.ProjTrafo())); var task = app.Runtime.CompileRender(win.FramebufferSignature, sg); win.RenderTask = DefaultOverlays.withStatistics(task); win.Run(); } }
public static void Run() { using (var app = /*new VulkanApplication() */ new OpenGlApplication()) { var win = app.CreateSimpleRenderWindow(samples: 8); win.Run(); } }
public static void Main(string[] args) { Aardvark.Base.Aardvark.Init(); using (var app = /*new VulkanApplication() */ new OpenGlApplication()) { var win = app.CreateGameWindow(samples: 8); // build object from indexgeometry primitives var cone = IndexedGeometryPrimitives.Cone.solidCone( V3d.OOO, V3d.OOI, 1.0, 0.2, 48, C4b.Red ).ToSg(); // or directly using scene graph var cube = SgPrimitives.Sg.box( Mod.Init(C4b.Blue), Mod.Init(Box3d.FromCenterAndSize(V3d.Zero, V3d.III)) ); var initialViewTrafo = CameraView.LookAt(new V3d(0.2, 1.2, 0.9) * 3.0, V3d.OOO, V3d.OOI); var controlledViewTrafo = Aardvark.Application.DefaultCameraController.control(win.Mouse, win.Keyboard, win.Time, initialViewTrafo); var frustum = win.Sizes.Map(size => FrustumModule.perspective(60.0, 0.1, 10.0, size.X / (float)size.Y) ); // of course constructing scene graph nodes manually is tedious. therefore we use // convinience extension functions which can be chaned together, each // wrapping a node around the previously constructed scene graph var scene = cube // next, we apply the shaders (this way, the shader becomes the root node -> all children now use // this so called effect (a pipeline shader which combines all shader stages into one object) .WithEffects(new[] { Aardvark.Base.Rendering.Effects.Trafo.Effect, Aardvark.Base.Rendering.Effects.VertexColor.Effect, Aardvark.Base.Rendering.Effects.SimpleLighting.Effect }) .ViewTrafo(controlledViewTrafo.Map(vt => vt.ViewTrafo)) .ProjTrafo(frustum.Map <Frustum, Trafo3d>(f => f.ProjTrafo())); // next we use the aardvark scene graph compiler to construct a so called render task, // an optimized representation of the scene graph. var renderTask = app.Runtime.CompileRender(win.FramebufferSignature, scene); // next, we assign the rendertask to our render window. win.RenderTask = renderTask; win.Run(); } }
public static void Run() { using (var app = /*new VulkanApplication() */ new OpenGlApplication()) { var win = app.CreateSimpleRenderWindow(samples: 8); var cone = IndexedGeometryPrimitives.Cone.solidCone(V3d.OOO, V3d.OOI, 1.0, 0.2, 48, C4b.Red).ToSg(); // build object from indexgeometry primitives var cube = SgPrimitives.Sg.box(AValModule.constant(C4b.Blue), AValModule.constant(Box3d.FromCenterAndSize(V3d.Zero, V3d.III))); // or directly using scene graph var initialViewTrafo = CameraView.LookAt(V3d.III * 3.0, V3d.OOO, V3d.OOI); var controlledViewTrafo = Aardvark.Application.DefaultCameraController.control(win.Mouse, win.Keyboard, win.Time, initialViewTrafo); var frustum = win.Sizes.Map(size => FrustumModule.perspective(60.0, 0.1, 10.0, size.X / (float)size.Y)); var whiteShader = Aardvark.Rendering.Effects.SimpleLighting.Effect; var trafo = Effects.Trafo.Effect; var currentAngle = 0.0; var angle = win.Time.Map(t => { return(currentAngle += 0.001); }); var rotatingTrafo = angle.Map(a => Trafo3d.RotationZ(a)); var sg = new[] { cone.Trafo(AValModule.constant(Trafo3d.Translation(1.0, 1.0, 0.0))), cube.Trafo(rotatingTrafo) } .ToSg() .WithEffects(new[] { trafo, whiteShader }) .ViewTrafo(controlledViewTrafo.Map(c => c.ViewTrafo)) .ProjTrafo(frustum.Map(f => f.ProjTrafo())); win.RenderTask = Aardvark.Rendering.RenderTask.ofArray( new[] { app.Runtime.CompileClear(win.FramebufferSignature, AValModule.constant(C4f.Gray10)), app.Runtime.CompileRender(win.FramebufferSignature, sg) } ); win.Run(); } }
static void RunUI() { var form = new Form(); form.IsMdiContainer = true; form.Width = 1024; form.Height = 768; form.Padding = new Padding(0); var main = new DockPanel(); main.Dock = DockStyle.Fill; main.DocumentStyle = DocumentStyle.DockingMdi; main.Parent = form; main.Theme = new WeifenLuo.WinFormsUI.Docking.VS2012LightTheme(); var t = new UserInterfaceStuff.Test(); t.Text = "Test Dock Control"; t.Show(main, DockState.DockRight); var f = new UserInterfaceStuff.RenderControlContent(); var app = new OpenGlApplication(); f.Init(app); var config = SetScene(f); f.Show(main, DockState.Document); form.Controls.Add(main); var ctrl = new UserInterfaceStuff.RenderTaskControl(); ctrl.Config = config; ctrl.Show(main, DockState.DockRight); Application.Run(form); }
public static void Run() { using (var app = /*new VulkanApplication() */ new OpenGlApplication()) { var win = app.CreateSimpleRenderWindow(samples: 8); // create CPU side array var indices = new int[] { 0, 1, 2, 0, 2, 3 }; // wrap it into cpu buffer. ArrayBuffer is a CPU buffer (which will be uploaded on demand), // In contrast, BackendBuffer would be a buffer prepared for a specific backend. // both implement the IBuffer interface. var indexBuffer = (IBuffer) new ArrayBuffer(indices); // same applies for vertex data. Here we do not explicitly create an ArrayBuffer since // we use convinience functions which internally create the ArrayBuffer for us var vertices = new V3f[] { new V3f(-1, -1, 0), new V3f(1, -1, 0), new V3f(1, 1, 0), new V3f(-1, 1, 0) }; var colors = new C4b[] { C4b.Green, C4b.Red, C4b.Blue, C4b.White }; // In this low level API, we manually construct a drawCallInfo which essentially map // to the arguments of glDrawElements etc. var drawCallInfo = new DrawCallInfo() { FaceVertexCount = 6, InstanceCount = 1, // DrawCallInfo is a struct and is initialized with zeros. make sure to set instanceCount to 1 FirstIndex = 0, }; // next we create a scene graph node which describes a simple scene which, when rendered // uses the supplied drawCallInfo to render geometry of type TriangleList (in constrast to points, linestrip etc) var drawNode = new Sg.RenderNode(drawCallInfo, IndexedGeometryMode.TriangleList); // the main principle is to use scene graph nodes as small building blocks to build together the // complete scene description - a bit like lego ;) // the same applies for applying geometry data. just like any other attribute (e.g. model trafos), // vertex data can be inherited along the edges in the scene graph. thus the scene graph would look like this // VertexIndexApplicator (applies index buffer to sub graph) // ^ // | // drawNode (performs draw call using attributes inherited along scene graph edges) var sceneWithIndexBuffer = new Sg.VertexIndexApplicator( new BufferView(AValModule.constant(indexBuffer), typeof(int)), drawNode ); // of course constructing scene graph nodes manually is tedious. therefore we use // convinience extension functions which can be chaned together, each // wrapping a node around the previously constructed scene graph var scene = sceneWithIndexBuffer .WithVertexAttribute("Positions", vertices) // there are a lot such extension functions defined to conviniently work with scene graphs .VertexAttribute(DefaultSemantic.Colors, colors) // next, we apply the shaders (this way, the shader becomes the root node -> all children now use // this so called effect (a pipeline shader which combines all shader stages into one object) .WithEffects(new[] { Aardvark.Rendering.Effects.VertexColor.Effect }); // next we use the aardvark scene graph compiler to construct a so called render task, // an optimized representation of the scene graph. var renderTask = app.Runtime.CompileRender(win.FramebufferSignature, scene); // next, we assign the rendertask to our render window. win.RenderTask = renderTask; win.Run(); } }