private void TestZ(GLMatrixCalc c, Vector4[] boundingbox, float zpoint) { Vector4[] modelboundingbox = boundingbox.Transform(c.ModelMatrix); Vector4[] intercepts = new Vector4[6]; Vector3[] texpoints = new Vector3[6]; int count = 0; modelboundingbox[0].FindVectorFromZ(modelboundingbox[1], ref intercepts, ref texpoints, new Vector3(0, 9, 0), ref count, zpoint); modelboundingbox[1].FindVectorFromZ(modelboundingbox[2], ref intercepts, ref texpoints, new Vector3(9, 1, 0), ref count, zpoint); modelboundingbox[3].FindVectorFromZ(modelboundingbox[2], ref intercepts, ref texpoints, new Vector3(1, 9, 0), ref count, zpoint); modelboundingbox[0].FindVectorFromZ(modelboundingbox[3], ref intercepts, ref texpoints, new Vector3(9, 0, 0), ref count, zpoint); modelboundingbox[4].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref texpoints, new Vector3(0, 9, 1), ref count, zpoint); modelboundingbox[5].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref texpoints, new Vector3(9, 1, 1), ref count, zpoint); modelboundingbox[7].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref texpoints, new Vector3(1, 9, 1), ref count, zpoint); modelboundingbox[4].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref texpoints, new Vector3(9, 0, 1), ref count, zpoint); modelboundingbox[0].FindVectorFromZ(modelboundingbox[4], ref intercepts, ref texpoints, new Vector3(0, 0, 9), ref count, zpoint); modelboundingbox[1].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref texpoints, new Vector3(0, 1, 9), ref count, zpoint); modelboundingbox[2].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref texpoints, new Vector3(1, 1, 9), ref count, zpoint); modelboundingbox[3].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref texpoints, new Vector3(1, 0, 9), ref count, zpoint); if (count >= 3) { Vector4 avg = intercepts.Average(); float[] angles = new float[6]; for (int i = 0; i < count; i++) { angles[i] = -(float)Math.Atan2(intercepts[i].Y - avg.Y, intercepts[i].X - avg.X); // all on the same z plane, so x/y only need be considered System.Diagnostics.Debug.WriteLine("C" + intercepts[i].ToStringVec() + " ang " + angles[i].Degrees() + " t " + texpoints[i]); } } }
///<summary> Execute a RenderableItem. /// Use to execute outside of the normal RenderableItemList system. For a compute shader for instance. Or for a finder. /// appliedstate if not null overrides this.RenderState and uses that instead </summary> public void Execute(IGLProgramShader shader, GLRenderState glstate, GLMatrixCalc c = null, GLRenderState appliedstate = null, bool noshaderstart = false) { System.Diagnostics.Debug.Assert(glstate != null && shader != null); if (shader.Enable) { if (!noshaderstart) { shader.Start(c); } GLRenderState curstate = RenderState; if (appliedstate != null) { RenderState = appliedstate; } Bind(glstate, shader, c); Render(); if (!noshaderstart) { shader.Finish(); } RenderState = curstate; } }
// code from the volumetric testers to help debug stuff private void Test(GLMatrixCalc c, Vector4[] boundingbox, float percent) { Vector4[] modelboundingbox = boundingbox.Transform(c.ModelMatrix); float minzv = float.MaxValue, maxzv = float.MinValue; foreach (var m in modelboundingbox) { if (m.Z < minzv) { minzv = m.Z; } if (m.Z > maxzv) { maxzv = m.Z; } Vector4[] proj = modelboundingbox.Transform(c.ProjectionMatrix); System.Diagnostics.Debug.WriteLine("Model {0} -> {1}", m, proj); } System.Diagnostics.Debug.WriteLine("Min {0} Max {1}", minzv, maxzv); float zpoint = minzv + (maxzv - minzv) * percent; TestZ(c, boundingbox, zpoint); }
/// <summary> </summary> public override void Start(GLMatrixCalc c) { Matrix4 a = ModelTranslation; GL.ProgramUniformMatrix4(Id, 22, false, ref a); GLOFC.GLStatics.Check(); }
/// <summary> Start shader </summary> public override void Start(GLMatrixCalc c) { base.Start(c); GL.ProgramUniform1(Id, 15, TimeDelta); GLOFC.GLStatics.Check(); }
/// <summary> Start shader </summary> public override void Start(GLMatrixCalc c) { base.Start(c); Matrix4 t = Transform.Transform; GL.ProgramUniformMatrix4(Id, 23, false, ref t); GLOFC.GLStatics.Check(); }
/// <summary> /// Construct a control display /// </summary> /// <param name="items">Items to store GL data to</param> /// <param name="win">GLWindowControl to hook to</param> /// <param name="mc">Matrix Calc to use</param> /// <param name="depthtest">Enable depth test</param> /// <param name="startz">Start Z for nearest top level window</param> /// <param name="deltaz">Delta Z between each top level window</param> /// <param name="arbbufferid">ARB buffer to use for texture bindless storage</param> public GLControlDisplay(GLItemsList items, GLWindowControl win, GLMatrixCalc mc, bool depthtest = true, // do depth testing or not float startz = 0.001f, // z for the deepest window (only will apply if depth testing float deltaz = 0.001f, // delta betwwen them int arbbufferid = 10 ) : base("displaycontrol", new Rectangle(0, 0, mc.ScreenCoordMax.Width, mc.ScreenCoordMax.Height)) { glwin = win; MatrixCalc = mc; context = GLStatics.GetContext(); this.items = items; vertexes = items.NewBuffer(); vertexarray = items.NewVertexArray(); vertexes.Bind(vertexarray, 0, 0, vertexesperentry * sizeof(float)); // bind to 0, from 0, 2xfloats. Must bind after vertexarray is made as its bound during construction vertexarray.Attribute(0, 0, vertexesperentry, OpenTK.Graphics.OpenGL4.VertexAttribType.Float); // bind 0 on attr 0, 2 components per vertex GLRenderState rc = GLRenderState.Tri(); rc.PrimitiveRestart = 0xff; rc.DepthTest = depthtest; this.startz = startz; this.deltaz = deltaz; ri = new GLRenderableItem(PrimitiveType.TriangleStrip, rc, 0, vertexarray); // create a renderable item ri.CreateRectangleElementIndexByte(items.NewBuffer(), 255 / 5); // note this limits top level controls number to 255/5. ri.DrawCount = 0; // nothing to draw at this point shader = new GLShaderPipeline(new GLPLVertexShaderScreenTexture(), new GLPLFragmentShaderBindlessTexture(arbbufferid, true, discardiftransparent: true)); items.Add(shader); textures = new Dictionary <GLBaseControl, GLTexture2D>(); size = new Dictionary <GLBaseControl, Size>(); visible = new Dictionary <GLBaseControl, bool>(); texturebinds = items.NewBindlessTextureHandleBlock(arbbufferid); glwin.MouseMove += Gc_MouseMove; glwin.MouseClick += Gc_MouseClick; glwin.MouseDoubleClick += Gc_MouseDoubleClick; glwin.MouseDown += Gc_MouseDown; glwin.MouseUp += Gc_MouseUp; glwin.MouseEnter += Gc_MouseEnter; glwin.MouseLeave += Gc_MouseLeave; glwin.MouseWheel += Gc_MouseWheel; glwin.KeyDown += Gc_KeyDown; glwin.KeyUp += Gc_KeyUp; glwin.KeyPress += Gc_KeyPress; glwin.Resize += Gc_Resize; glwin.Paint += Gc_Paint; suspendLayoutCount = 0; }
/// <summary> Called by render list and executes the operation </summary> public override void Execute(GLMatrixCalc c) { if (QueryBuffer != null) { QueryBuffer.BindQuery(); } GL.BeginQueryIndexed(Target, Index, Id); GLStatics.Check(); }
/// <summary> Start shader </summary> public override void Start(GLMatrixCalc c) { Matrix4 a = ModelTranslation; GL.ProgramUniformMatrix4(Id, 22, false, ref a); Vector3 b = WorldPositionOffset; GL.ProgramUniform3(Id, 23, ref b); GLOFC.GLStatics.Check(); }
/// <inheritdoc cref="GLOFC.GL4.GLScissors.SetToScreenCoords(int, GLMatrixCalc)"/> public GLOperationScissors(int viewport, GLMatrixCalc matrixcalc) { this.viewport = viewport; float leftoffset = matrixcalc.ScreenCoordClipSpaceOffset.X - (-1); float topoffset = 1 - matrixcalc.ScreenCoordClipSpaceOffset.Y; int left = (int)(leftoffset / 2.0f * matrixcalc.ViewPort.Width) + matrixcalc.ViewPort.Left; int top = (int)(topoffset / 2.0f * matrixcalc.ViewPort.Height) + matrixcalc.ViewPort.Top; int width = (int)(matrixcalc.ScreenCoordClipSpaceSize.Width / 2.0f * matrixcalc.ViewPort.Width); int height = (int)(matrixcalc.ScreenCoordClipSpaceSize.Height / 2.0f * matrixcalc.ViewPort.Height); this.rect = new Rectangle(left, top, width, height); }
/// <summary> Called before Render (normally by RenderList::Render) to set up data for the render. /// currentstate may be null, meaning, don't apply /// RenderState may be null, meaning don't change</summary> public void Bind(GLRenderState currentstate, IGLProgramShader shader, GLMatrixCalc matrixcalc) { if (currentstate != null && RenderState != null) // if either null, it means the last render state applied is the same as our render state, so no need to apply { currentstate.ApplyState(RenderState); // else go to this state } VertexArray?.Bind(); // give the VA a chance to bind to GL RenderData?.Bind(this, shader, matrixcalc); // optional render data supplied by the user to bind ElementBuffer?.BindElement(); // if we have an element buffer, give it a chance to bind IndirectBuffer?.BindIndirect(); // if we have an indirect buffer, give it a chance to bind ParameterBuffer?.BindParameter(); // if we have a parameter buffer, give it a chance to bind }
/// <summary> Called by render list and executes the operation </summary> public override void Execute(GLMatrixCalc c) { GLTransformFeedback.End(); for (int i = 0; i < TransformFeedbackOperation.VaryingBuffers.Length; i++) { //System.Diagnostics.Debug.WriteLine($"TF {TransformFeedbackOperation.Id} bp {i}"); GLBuffer.UnbindTransformFeedback(i, TransformFeedbackOperation.Id); } GLStatics.Check(); GLTransformFeedback.UnBind(); GLStatics.Check(); }
/// <summary> /// Setup scissors to screen defined by MatrixCalc /// </summary> /// <param name="viewport">Viewport to scissor</param> /// <param name="matrixcalc">MatrixCalc with current screen setup</param> static public void SetToScreenCoords(int viewport, GLMatrixCalc matrixcalc) { float leftoffset = matrixcalc.ScreenCoordClipSpaceOffset.X - (-1); float topoffset = 1 - matrixcalc.ScreenCoordClipSpaceOffset.Y; int left = (int)(leftoffset / 2.0f * matrixcalc.ViewPort.Width) + matrixcalc.ViewPort.Left; int top = (int)(topoffset / 2.0f * matrixcalc.ViewPort.Height) + matrixcalc.ViewPort.Top; int width = (int)(matrixcalc.ScreenCoordClipSpaceSize.Width / 2.0f * matrixcalc.ViewPort.Width); int height = (int)(matrixcalc.ScreenCoordClipSpaceSize.Height / 2.0f * matrixcalc.ViewPort.Height); GL.ScissorIndexed(viewport, left, matrixcalc.ScreenSize.Height - (top + height), width, height); GL.Enable(IndexedEnableCap.ScissorTest, viewport); }
/// <summary> Start the shader. Bind the program and call Start on each sumcomponent. Then invoke StartAction</summary> public virtual void Start(GLMatrixCalc c) { GL.UseProgram(0); // ensure no active program - otherwise the stupid thing picks it GL.BindProgramPipeline(pipelineid); foreach (var x in shaders) // let any programs do any special set up { x.Value.Start(c); } StartAction?.Invoke(this, c); // any shader hooks get a chance. }
/// <summary> /// Minimal set - ProjectionModelMatrix only /// </summary> /// <param name="matrixcalc">The current matrix calc to store information from </param> public void SetMinimal(GLMatrixCalc matrixcalc) { if (lastmccount != matrixcalc.CountMatrixCalcs) { if (NotAllocated) { AllocateBytes(MatrixCalcUse, BufferUsageHint.DynamicCopy); } StartWrite(0, Length); // the whole schebang Write(matrixcalc.ProjectionModelMatrix); StopReadWrite(); // and complete.. lastmccount = matrixcalc.CountMatrixCalcs; } }
public virtual void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c) // called per renderable item.. { GLOFC.GLStatics.Check(); if (texture.Id >= 0) { if (texture.MipMapAutoGenNeeded) { texture.GenMipMapTextures(); texture.MipMapAutoGenNeeded = false; } texture.Bind(1); GLOFC.GLStatics.Check(); } }
/// <summary> Called by render list and executes the operation </summary> public override void Execute(GLMatrixCalc c) { TransformFeedback.Bind(); // bind this transformfeedback to target transform feedback GLStatics.Check(); // bind these buffer at offset/set and binding index starting at 0 for (int i = 0; i < VaryingBuffers.Length; i++) { //System.Diagnostics.Debug.WriteLine($"TF {TransformFeedback.Id} bp {i} to buf {VaryingBuffers[i].Id}"); VaryingBuffers[i].BindTransformFeedback(i, TransformFeedback.Id, Offsets == null ? 0 : Offsets[i], Sizes == null ? 0 : Sizes[i]); } GLStatics.Check(); GLTransformFeedback.Begin(PrimitiveType); // and start GLStatics.Check(); }
/// <summary> Start shader</summary> public override void Start(GLMatrixCalc c) { if (UpdateControls) { GL.ProgramUniform1(Id, 10, Frequency); GL.ProgramUniform1(Id, 11, UnRadius); GL.ProgramUniform1(Id, 12, Scutoff); GL.ProgramUniform1(Id, 13, Blackdeepness); GL.ProgramUniform1(Id, 14, Concentrationequator); UpdateControls = false; } GL.ProgramUniform1(Id, 15, TimeDeltaSurface); GL.ProgramUniform1(Id, 16, TimeDeltaSpots); GLOFC.GLStatics.Check(); }
/// <summary>Bind data to uniforms </summary> public virtual void Bind(IGLRenderableItem ri, IGLProgramShader shader, GLMatrixCalc c) { int sid = shader.GetShader(ShaderType.VertexShader).Id; GL.ProgramUniformMatrix4(sid, TransformUniform, false, ref transform); if (lookatangle) { Vector2 res = pos.AzEl(c.EyePosition, false); System.Diagnostics.Debug.WriteLine("Object Bind eye " + c.EyePosition + " to " + pos + " az " + res.Y.Degrees() + " inc " + res.X.Degrees()); Matrix4 tx2 = Matrix4.Identity; tx2 *= Matrix4.CreateRotationX((-res.X)); tx2 *= Matrix4.CreateRotationY(((float)Math.PI + res.Y)); GL.ProgramUniformMatrix4(sid, LookAtUniform, false, ref tx2); } GLStatics.Check(); }
/// <summary> /// All set - All fields /// </summary> /// <param name="matrixcalc">The current matrix calc to store information from</param> public void SetFull(GLMatrixCalc matrixcalc) { if (lastmccount != matrixcalc.CountMatrixCalcs) { if (NotAllocated) { AllocateBytes(MatrixCalcUse, BufferUsageHint.DynamicCopy); } StartWrite(0, Length); // the whole schebang Write(matrixcalc.ProjectionModelMatrix); //0, 64 long Write(matrixcalc.ProjectionMatrix); //64, 64 long Write(matrixcalc.ModelMatrix); //128, 64 long Write(matrixcalc.LookAt, 0); //192, vec4, 16 long Write(matrixcalc.EyePosition, 0); // 208, vec4, 16 long Write(matrixcalc.EyeDistance); // 224, float, 4 long Write(matrixcalc.MatrixScreenCoordToClipSpace()); // 240-303, into the project model matrix slot, used for text StopReadWrite(); // and complete.. lastmccount = matrixcalc.CountMatrixCalcs; } }
/// <summary> /// Normal set - All up to EyeDistance inclusive /// </summary> /// <param name="matrixcalc">The current matrix calc to store information from </param> public void Set(GLMatrixCalc matrixcalc) { if (lastmccount != matrixcalc.CountMatrixCalcs) { if (NotAllocated) { AllocateBytes(MatrixCalcUse, BufferUsageHint.DynamicCopy); } StartWrite(0, Length); // the whole schebang Write(matrixcalc.ProjectionModelMatrix); // 0- 63 Write(matrixcalc.ProjectionMatrix); // 64-127 Write(matrixcalc.ModelMatrix); // 128-191 Write(matrixcalc.LookAt, 0); // 192-207 Write(matrixcalc.EyePosition, 0); // 208-223 Write(matrixcalc.EyeDistance); // 224-239 StopReadWrite(); // and complete.. lastmccount = matrixcalc.CountMatrixCalcs; } }
/// <summary> /// Start shader /// </summary> public override void Start(GLMatrixCalc c) { base.Start(c); Matrix4 t = CommonTransform.Transform; GL.ProgramUniformMatrix4(Id, 20, false, ref t); int image1 = (int)Math.Floor(Blend); // compute first and next image indexes int image2 = BlendImages > 0 ? (image1 + 1) % BlendImages : 0; float mix = Blend - image1; // and the mix between them GL.ProgramUniform1(Id, 25, mix); GL.ProgramUniform1(Id, 26, image1); GL.ProgramUniform1(Id, 27, image2); // System.Diagnostics.Debug.WriteLine("Blend " + image1 + " to " + image2 + " Mix of" + mix); GLStatics.Check(); }
/// <summary> Shader start </summary> public override void Start(GLMatrixCalc c) { GL.ProgramUniform2(Id, 24, TexOffset); }
/// <summary> Start shader </summary> public override void Start(GLMatrixCalc c) { GL.ProgramUniform1(Id, 30, Blend); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); Closed += ShaderTest_Closed; items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block int front = -20000, back = front + 90000, left = -45000, right = left + 90000, vsize = 2000; Vector4[] displaylines = new Vector4[] { new Vector4(left, -vsize, front, 1), new Vector4(left, +vsize, front, 1), new Vector4(left, +vsize, front, 1), new Vector4(right, +vsize, front, 1), new Vector4(right, +vsize, front, 1), new Vector4(right, -vsize, front, 1), new Vector4(right, -vsize, front, 1), new Vector4(left, -vsize, front, 1), new Vector4(left, -vsize, back, 1), new Vector4(left, +vsize, back, 1), new Vector4(left, +vsize, back, 1), new Vector4(right, +vsize, back, 1), new Vector4(right, +vsize, back, 1), new Vector4(right, -vsize, back, 1), new Vector4(right, -vsize, back, 1), new Vector4(left, -vsize, back, 1), new Vector4(left, -vsize, front, 1), new Vector4(left, -vsize, back, 1), new Vector4(left, +vsize, front, 1), new Vector4(left, +vsize, back, 1), new Vector4(right, -vsize, front, 1), new Vector4(right, -vsize, back, 1), new Vector4(right, +vsize, front, 1), new Vector4(right, +vsize, back, 1), }; GLRenderState rl = GLRenderState.Lines(1); { items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW"); rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl, displaylines)); } float h = 0; if (h != -1) { items.Add(new GLColorShaderWorld(), "COS-1L"); int dist = 1000; Color cr = Color.FromArgb(100, Color.White); rObjects.Add(items.Shader("COS-1L"), // horizontal GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl, GLShapeObjectFactory.CreateLines(new Vector3(left, h, front), new Vector3(left, h, back), new Vector3(dist, 0, 0), (back - front) / dist + 1), new Color4[] { cr }) ); rObjects.Add(items.Shader("COS-1L"), GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl, GLShapeObjectFactory.CreateLines(new Vector3(left, h, front), new Vector3(right, h, front), new Vector3(0, 0, dist), (right - left) / dist + 1), new Color4[] { cr }) ); } GLMatrixCalc mc = new GLMatrixCalc(); mc.PerspectiveNearZDistance = 1f; mc.PerspectiveFarZDistance = 500000f; if (true) { bool testform1 = true; mc.ResizeViewPort(this, glwfc.Size); // must establish size before starting displaycontrol = new GLControlDisplay(items, glwfc, mc); // hook form to the window - its the master, it takes its size fro mc.ScreenCoordMax displaycontrol.Focusable = true; // we want to be able to focus and receive key presses. displaycontrol.Name = "displaycontrol"; if (testform1) { GLForm pform = new GLForm("Form1", "GL Menu demonstration", new Rectangle(10, 10, 600, 200)); displaycontrol.Add(pform); if (true) { GLMenuStrip menubar = new GLMenuStrip("Menubar", new Rectangle(0, 0, 500, 24)); menubar.AutoOpenDelay = 1000; menubar.Font = new Font("Euro Caps", 12); menubar.Dock = DockingType.Top; menubar.SubMenuBorderWidth = 1; GLMenuItem l1 = new GLMenuItem("MI-0A", "MenuA"); menubar.Add(l1); GLMenuItem l1a = new GLMenuItem("A-1", "MenuA-1"); GLMenuItem l1b = new GLMenuItem("A-2", "MenuA-2"); l1b.CheckOnClick = true; l1b.Checked = true; GLMenuItem l1c = new GLMenuItem("A-3", "MenuA-3") { Image = Properties.Resources.GoToHomeSystem }; l1c.CheckOnClick = true; l1.SubMenuItems = new List <GLBaseControl>() { l1a, l1b, l1c }; GLMenuItem l1a1 = new GLMenuItem("A-1-1", "MenuA-1-1"); GLMenuItem l1a2 = new GLMenuItem("A-1-2", "MenuA-1-2"); GLMenuItem l1a21 = new GLMenuItem("A-1-2-1", "MenuA-1-2-1"); GLMenuItem l1a22 = new GLMenuItem("A-1-2-2", "MenuA-1-2-2"); l1a2.SubMenuItems = new List <GLBaseControl>() { l1a21, l1a22 }; GLCheckBox l1a3 = new GLCheckBox("A-1-3", new Rectangle(0, 0, 0, 0), "CheckBox A-1-3"); l1a3.CheckOnClick = true; l1a3.CheckChanged += (bc) => { menubar.CloseMenus(); }; // need to associate check changed with closing menus - optional GLComboBox l1a4 = new GLComboBox("A-1-4", new Rectangle(0, 0, 0, 0), new List <string>() { "one", "two", "three" }); l1a4.SelectedIndexChanged += (c) => { menubar.CloseMenus(); }; l1a4.DisableChangeKeys = true; l1a.SubMenuItems = new List <GLBaseControl>() { l1a1, l1a2, l1a3, l1a4 }; GLMenuItem l2 = new GLMenuItem("MI-0B", "MenuB"); menubar.Add(l2); GLMenuItem l2a = new GLMenuItem("B-1", "MenuB-1"); l2a.Click += (s) => { System.Diagnostics.Debug.WriteLine("Clicked Menu " + s.Name); }; GLMenuItem l2b = new GLMenuItem("B-2", "MenuB-2"); l2.SubMenuItems = new List <GLBaseControl>() { l2a, l2b }; GLMenuItem l3 = new GLMenuItem("MI-0C", "MenuC"); menubar.Add(l3); pform.Add(menubar); } } if (true) { GLContextMenu ctx1, ctx2; ctx1 = new GLContextMenu("CM1"); GLMenuItem cm1 = new GLMenuItem("CM1A", "Menu-1"); cm1.CheckOnClick = true; GLMenuItem cm2 = new GLMenuItem("CM1B", "Menu-2"); cm2.CheckOnClick = true; GLMenuItem cm3 = new GLMenuItem("CM1C", "Menu-3"); GLMenuItem l1a1 = new GLMenuItem("CM1C-1", "Menu-1-1"); l1a1.CheckOnClick = true; GLMenuItem l1a2 = new GLMenuItem("CM1C-2", "MenuA-1-2"); GLCheckBox l1a3 = new GLCheckBox("CM1C-3", new Rectangle(0, 0, 0, 0), "CheckBox A-1-3"); l1a3.CheckOnClick = true; cm3.SubMenuItems = new List <GLBaseControl>() { l1a1, l1a2, l1a3 }; int count = 0; ctx1.Opening += (c1, c2) => { bool on = count++ % 2 == 0; System.Diagnostics.Debug.WriteLine($"Set cm2 state {on}"); cm2.Visible = on; }; ctx1.Add(cm1); ctx1.Add(cm2); ctx1.Add(cm3); Color tc = Color.Orange; ctx2 = new GLContextMenu("CM1", new GLMenuItem[] { new GLMenuItem("CM1A", "MenuR1") { CheckOnClick = true, ForeColor = tc }, new GLMenuItem("CM1B", "MenuR2") { CheckOnClick = true, Enabled = false, ForeColor = tc }, new GLMenuItem("CM1C", "MenuR3") { CheckOnClick = true }, new GLMenuItem("CM1C", "MenuR4") { CheckOnClick = true }, new GLMenuItem("CM1C", "MenuR5") { }, }); ctx2.Font = new Font("Euro caps", 18f); displaycontrol.MouseClick += (s, ev) => { if (ev.Button == GLMouseEventArgs.MouseButtons.Left) { System.Diagnostics.Debug.WriteLine($"*********************** OPEN"); ctx1.Show(displaycontrol, ev.ScreenCoord); } else if (ev.Button == GLMouseEventArgs.MouseButtons.Right) { ctx2.Show(displaycontrol, ev.ScreenCoord); } }; } } gl3dcontroller = new Controller3D(); gl3dcontroller.ZoomDistance = 5000F; gl3dcontroller.YHoldMovement = true; gl3dcontroller.PaintObjects = Controller3dDraw; gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) => { return((float)ms * 10.0f); }; gl3dcontroller.MatrixCalc.InPerspectiveMode = true; if (displaycontrol != null) { gl3dcontroller.Start(mc, displaycontrol, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F); // HOOK the 3dcontroller to the form so it gets Form events displaycontrol.Paint += (o, ts) => // subscribing after start means we paint over the scene, letting transparency work { displaycontrol.Render(glwfc.RenderState, ts); // we use the same matrix calc as done in controller 3d draw }; } else { gl3dcontroller.Start(glwfc, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F); // HOOK the 3dcontroller to the form so it gets Form events } systemtimer.Interval = 25; systemtimer.Tick += new EventHandler(SystemTick); systemtimer.Start(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); Closed += ShaderTest_Closed; items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block int front = -20000, back = front + 90000, left = -45000, right = left + 90000, vsize = 2000; Vector4[] displaylines = new Vector4[] { new Vector4(left, -vsize, front, 1), new Vector4(left, +vsize, front, 1), new Vector4(left, +vsize, front, 1), new Vector4(right, +vsize, front, 1), new Vector4(right, +vsize, front, 1), new Vector4(right, -vsize, front, 1), new Vector4(right, -vsize, front, 1), new Vector4(left, -vsize, front, 1), new Vector4(left, -vsize, back, 1), new Vector4(left, +vsize, back, 1), new Vector4(left, +vsize, back, 1), new Vector4(right, +vsize, back, 1), new Vector4(right, +vsize, back, 1), new Vector4(right, -vsize, back, 1), new Vector4(right, -vsize, back, 1), new Vector4(left, -vsize, back, 1), new Vector4(left, -vsize, front, 1), new Vector4(left, -vsize, back, 1), new Vector4(left, +vsize, front, 1), new Vector4(left, +vsize, back, 1), new Vector4(right, -vsize, front, 1), new Vector4(right, -vsize, back, 1), new Vector4(right, +vsize, front, 1), new Vector4(right, +vsize, back, 1), }; GLRenderState rl = GLRenderState.Lines(1); { items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW"); rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl, displaylines)); } float h = 0; if (h != -1) { items.Add(new GLColorShaderWorld(), "COS-1L"); int dist = 1000; Color cr = Color.FromArgb(100, Color.White); rObjects.Add(items.Shader("COS-1L"), // horizontal GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl, GLShapeObjectFactory.CreateLines(new Vector3(left, h, front), new Vector3(left, h, back), new Vector3(dist, 0, 0), (back - front) / dist + 1), new Color4[] { cr }) ); rObjects.Add(items.Shader("COS-1L"), GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl, GLShapeObjectFactory.CreateLines(new Vector3(left, h, front), new Vector3(right, h, front), new Vector3(0, 0, dist), (right - left) / dist + 1), new Color4[] { cr }) ); } GLMatrixCalc mc = new GLMatrixCalc(); mc.PerspectiveNearZDistance = 1f; mc.PerspectiveFarZDistance = 500000f; mc.ResizeViewPort(this, glwfc.Size); // must establish size before starting displaycontrol = new GLControlDisplay(items, glwfc, mc); // hook form to the window - its the master, it takes its size fro mc.ScreenCoordMax displaycontrol.Focusable = true; // we want to be able to focus and receive key presses. displaycontrol.Name = "displaycontrol"; displaycontrol.Font = new Font("Times", 8); GLForm pform = new GLForm("Form1", "GL Form demonstration", new Rectangle(0, 0, 1000, 800)); int taborder = 0; if (true) { string l = "Hello there ggg qqq jjj" + Environment.NewLine + "And the ggg next line"; GLMultiLineTextBox mtb = new GLMultiLineTextBox("mltb", new Rectangle(10, 10, 400, 200), l); mtb.Font = new Font("Ms Sans Serif", 24.25f); //mtb.Font = new Font("Arial", 25f); mtb.LineColor = Color.Green; mtb.EnableVerticalScrollBar = true; mtb.EnableHorizontalScrollBar = true; mtb.SetSelection(16 * 2 + 2, 16 * 3 + 4); mtb.TabOrder = taborder++; mtb.RightClickMenuFont = new Font("Euro Caps", 14f); mtb.FlashingCursor = false; pform.Add(mtb); } if (true) { string l = ""; for (int i = 0; i < 5; i++) { string s = string.Format("Line " + i); if (i == 0) { s += "And a much much longer Line which should break the width"; } l += s + "\r\n"; } l += "trail "; // l = ""; GLMultiLineTextBox mtb = new GLMultiLineTextBox("mltb", new Rectangle(0, 400, 400, 200), l); mtb.Font = new Font("Ms Sans Serif", 16); mtb.LineColor = Color.Green; mtb.EnableVerticalScrollBar = true; mtb.EnableHorizontalScrollBar = true; mtb.SetSelection(16 * 2 + 2, 16 * 3 + 4); mtb.TabOrder = taborder++; mtb.RightClickMenuFont = new Font("Euro Caps", 14f); pform.Add(mtb); //mtb.FlashingCursor = false; //mtb.ReadOnly = true; GLMultiLineTextBox mtb2 = new GLMultiLineTextBox("mltb2", new Rectangle(500, 400, 495, 200), l); mtb2.Font = new Font("Ms Sans Serif", 11); mtb2.LineColor = Color.Green; mtb2.EnableVerticalScrollBar = true; mtb2.EnableHorizontalScrollBar = true; mtb2.SetSelection(16 * 2 + 2, 16 * 3 + 4); mtb2.TabOrder = taborder++; mtb2.RightClickMenuFont = new Font("Arial", 14f); pform.Add(mtb2); } if (true) { GLTextBox tb1 = new GLTextBox("TB1", new Rectangle(0, 300, 350, 40), "Text Box Which is a very long string of very many many characters"); tb1.Font = new Font("Arial", 12); tb1.ReturnPressed += (c1) => { System.Diagnostics.Debug.WriteLine($"Return pressed on text box"); }; tb1.TabOrder = taborder++; pform.Add(tb1); } displaycontrol.Add(pform); gl3dcontroller = new Controller3D(); gl3dcontroller.ZoomDistance = 5000F; gl3dcontroller.YHoldMovement = true; gl3dcontroller.PaintObjects = Controller3dDraw; gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) => { return((float)ms * 10.0f); }; gl3dcontroller.MatrixCalc.InPerspectiveMode = true; if (displaycontrol != null) { gl3dcontroller.Start(mc, displaycontrol, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F); // HOOK the 3dcontroller to the form so it gets Form events displaycontrol.Paint += (o, ts) => // subscribing after start means we paint over the scene, letting transparency work { displaycontrol.Render(glwfc.RenderState, ts); // we use the same matrix calc as done in controller 3d draw }; } else { gl3dcontroller.Start(glwfc, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F); // HOOK the 3dcontroller to the form so it gets Form events } systemtimer.Start(); }
public override void Start(GLMatrixCalc c) { base.Start(c); texcoords.Bind(1); }
public void ComputeUniforms(int gridwidth, GLMatrixCalc mc, Vector2 cameradir, Color textcol, Color?backcol = null) { float sy = mc.LookAt.Y.Clamp(-2000, 2000); float multgrid = mc.EyeDistance / gridwidth; int tw = 10; if (multgrid < 2) { tw = 1; } else if (multgrid < 5) { tw = 5; } // System.Diagnostics.Debug.WriteLine("Mult " + multgrid + " tw "+ tw); int majorlines = (gridwidth * tw).Clamp(0, 10000); int sx = (int)((mc.LookAt.X - majorlines).Clamp(-50000, 50000 - majorlines * 2)) + 50000; //move to positive rep so rounding next is always down if (sx % majorlines > majorlines / 2) // if we are over 1/2 way across, move over { sx += majorlines; } sx = sx / majorlines * majorlines - 50000; // round and adjust back bool lookbackwards = (cameradir.Y > 90 || cameradir.Y < -90); int zoffset = lookbackwards ? majorlines : 0; int sz = (int)((mc.LookAt.Z - zoffset).Clamp(-20000, 70000 - majorlines * 2)) + 50000; //move to positive rep so rounding next is always down sz = sz / majorlines * majorlines - 50000; // round and adjust back Vector3 start = new Vector3(sx, sy, sz); GL.ProgramUniform1(this.Id, 11, majorlines); GL.ProgramUniform3(this.Id, 12, ref start); GL.ProgramUniform1(this.Id, 13, lookbackwards ? 1 : 0); //System.Diagnostics.Debug.WriteLine(majorlines + " " + start + " " + lookbackwards); if (lastsx != sx || lastsz != sz || lastsy != (int)sy || lasttextcol != textcol) { for (int i = 0; i < texcoords.Depth; i++) { int bsx = sx + majorlines * (i / 3); int bsz = sz + majorlines * (i % 3); string label = bsx.ToStringInvariant() + "," + sy.ToStringInvariant("0") + "," + bsz.ToStringInvariant(); GLOFC.Utils.BitMapHelpers.DrawTextIntoFixedSizeBitmap(ref texcoords.BitMaps[i], label, gridfnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, textcol, backcol); texcoords.LoadBitmap(texcoords.BitMaps[i], i, true, 1); //System.Diagnostics.Debug.WriteLine("At {0} Draw {1}", i, label); } lastsx = sx; lastsz = sz; lastsy = (int)sy; lasttextcol = textcol; } }
public void Start(GLWinFormControl glwfc) { this.glwfc = glwfc; matrixcalc = new GLMatrixCalc(); matrixcalc.PerspectiveNearZDistance = 1f; matrixcalc.PerspectiveFarZDistance = worldsize * 2; matrixcalc.InPerspectiveMode = true; matrixcalc.ResizeViewPort(this, glwfc.Size); items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block displaycontrol = new GLControlDisplay(items, glwfc, matrixcalc); // hook form to the window - its the master, it takes its size from mc.ScreenCoordMax displaycontrol.Focusable = true; // we want to be able to focus and receive key presses. displaycontrol.Name = "displaycontrol"; displaycontrol.Font = new Font("Arial", 12); gl3dcontroller = new Controller3Dd(); gl3dcontroller.PaintObjects = ControllerDraw; gl3dcontroller.ZoomDistance = 20e6 * 1000 * mscaling; // zoom 1 is X km gl3dcontroller.PosCamera.ZoomMin = 0.001f; gl3dcontroller.PosCamera.ZoomMax = 300f; gl3dcontroller.PosCamera.ZoomScaling = 1.08f; gl3dcontroller.Start(matrixcalc, displaycontrol, new Vector3d(0, 0, 0), new Vector3d(135f, 0, 0f), 0.025F, registermouseui: false, registerkeyui: true); gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) => { double eyedistr = Math.Pow(eyedist, 1.0); float v = (float)Math.Max(eyedistr / 1200, 0); //System.Diagnostics.Debug.WriteLine("Speed " + eyedistr + " "+ v); return((float)ms * v); }; for (int i = 1; i <= 10; i++) { int v = i * i; double f = (gl3dcontroller.PosCamera.ZoomMax - gl3dcontroller.PosCamera.ZoomMin) * v / 100.0 + gl3dcontroller.PosCamera.ZoomMin; System.Diagnostics.Debug.WriteLine($"{i} {v} {f}"); } displaycontrol.Paint += (o, ts) => // subscribing after Controller start means we paint over the scene { // MCUB set up by Controller3DDraw which did the work first // System.Diagnostics.Debug.WriteLine("Controls Draw"); displaycontrol.Render(glwfc.RenderState, ts); }; displaycontrol.MouseClick += MouseClickOnMap; // grab mouse UI displaycontrol.MouseUp += MouseUpOnMap; displaycontrol.MouseDown += MouseDownOnMap; displaycontrol.MouseMove += MouseMoveOnMap; displaycontrol.MouseWheel += MouseWheelOnMap; double startspeed = 60 * 60 * 6; // in sec GLImage minus = new GLImage("timeplus1y", new Rectangle(0, 0, 32, 32), Properties.Resources.GoBackward); minus.MouseClick += (e1, m1) => { currentjd -= 365; }; displaycontrol.Add(minus); GLImage back = new GLImage("timeback", new Rectangle(40, 0, 32, 32), Properties.Resources.Backwards); back.MouseClick += (e1, m1) => { if (jdscaling > 0) { jdscaling /= 2; } else if (jdscaling < 0) { jdscaling *= 2; } else { jdscaling = -startspeed; } }; displaycontrol.Add(back); GLImage pause = new GLImage("timepause", new Rectangle(80, 0, 32, 32), Properties.Resources.Pause); pause.MouseClick += (e1, m1) => { jdscaling = 0; }; displaycontrol.Add(pause); GLImage fwd = new GLImage("timefwd", new Rectangle(120, 0, 32, 32), Properties.Resources.Forward); fwd.MouseClick += (e1, m1) => { if (jdscaling < 0) { jdscaling /= 2; } else if (jdscaling > 0) { jdscaling *= 2; } else { jdscaling = startspeed; } }; displaycontrol.Add(fwd); GLImage plus = new GLImage("timeplus1y", new Rectangle(160, 0, 32, 32), Properties.Resources.GoForward); plus.MouseClick += (e1, m1) => { currentjd += 365; }; displaycontrol.Add(plus); GLImage sysleft = new GLImage("sysleft", new Rectangle(200, 0, 32, 32), Properties.Resources.GoBackward); sysleft.MouseClick += (e1, m1) => { DisplayNode(-1); }; displaycontrol.Add(sysleft); mastersystem = new GLLabel("sysname", new Rectangle(230, 6, 70, 20), "All", Color.DarkOrange); mastersystem.TextAlign = ContentAlignment.MiddleCenter; displaycontrol.Add(mastersystem); GLImage sysright = new GLImage("sysright", new Rectangle(300, 0, 32, 32), Properties.Resources.GoForward); sysright.MouseClick += (e1, m1) => { DisplayNode(1); }; displaycontrol.Add(sysright); timedisplay = new GLLabel("state", new Rectangle(340, 6, 800, 20), "Label", Color.DarkOrange); displaycontrol.Add(timedisplay); datalabel = new GLLabel("datalabel", new Rectangle(0, 40, 400, 100), "", Color.DarkOrange); datalabel.TextAlign = ContentAlignment.TopLeft; displaycontrol.Add(datalabel); status = new GLLabel("Status", new Rectangle(0, 0, 2000, 24), "x"); status.Dock = DockingType.BottomLeft; status.ForeColor = Color.Orange; status.BackColor = Color.FromArgb(50, 50, 50, 50); displaycontrol.Add(status); rightclickmenubody = new GLContextMenu("RightClickMenuBody", new GLMenuItem("RCMInfo", "Information") { MouseClick = (s, e) => { } }, new GLMenuItem("RCMZoomIn", "Track") { MouseClick = (s, e) => { track = (int)rightclickmenubody.Tag; } }, new GLMenuItem("RCMZoomIn", "Track Central Body") { MouseClick = (s, e) => { int body = (int)rightclickmenubody.Tag; if (bodyinfo[body].parentindex >= 0) { track = bodyinfo[body].parentindex; } } }, new GLMenuItem("RCMZoomIn", "Zoom In") { }, new GLMenuItem("RCMUntrack", "Untrack") { MouseClick = (s1, e1) => { track = -1; } } ); rightclickmenubody.Opening += (ms, tag) => { ms["RCMUntrack"].Enabled = track != -1; }; rightclickmenuscreen = new GLContextMenu("RightClickMenuBody", new GLMenuItem("RCMSysDisplay", "System Display") { MouseClick = (s, e) => { } }, new GLMenuItem("RCMUntrack", "Untrack") { MouseClick = (s1, e1) => { track = -1; } } ); rightclickmenuscreen.Opening += (ms, tag) => { ms["RCMUntrack"].Enabled = track != -1; }; if (true) { var shader = new GLColorShaderWorld(); items.Add(shader); GLRenderState lines = GLRenderState.Lines(1); lines.DepthTest = false; int gridsize = (int)(worldsize * mscaling); int gridoffset = (int)(gridlines * mscaling); int nolines = gridsize / gridoffset * 2 + 1; Color gridcolour = Color.FromArgb(80, 80, 80, 80); rObjects.Add(shader, GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines, GLShapeObjectFactory.CreateLines(new Vector3(-gridsize, -0, -gridsize), new Vector3(-gridsize, -0, gridsize), new Vector3(gridoffset, 0, 0), nolines), new Color4[] { gridcolour }) ); rObjects.Add(shader, GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines, GLShapeObjectFactory.CreateLines(new Vector3(-gridsize, -0, -gridsize), new Vector3(gridsize, -0, -gridsize), new Vector3(0, 0, gridoffset), nolines), new Color4[] { gridcolour })); Size bmpsize = new Size(128, 30); var maps = new GLBitmaps("bitmap1", rObjects, bmpsize, 3, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, false, false); using (StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap) { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center }) { float hsize = 40e6f * 1000 * mscaling; // million km -> m -> scaling float vsize = hsize * bmpsize.Height / bmpsize.Width; Font f = new Font("MS sans serif", 12f); long pos = -nolines / 2 * (gridlines / 1000); for (int i = -nolines / 2; i < nolines / 2; i++) { if (i != 0) { double v = Math.Abs(pos * 1000); long p = Math.Abs(pos); maps.Add(i, (p).ToString("N0"), f, Color.White, Color.Transparent, new Vector3(i * gridoffset + hsize / 2, 0, vsize / 2), new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt); maps.Add(i, (v / oneAU_m).ToString("N1") + "AU", f, Color.White, Color.Transparent, new Vector3(i * gridoffset + hsize / 2, 0, -vsize / 2), new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt); maps.Add(i, (p).ToString("N0"), f, Color.White, Color.Transparent, new Vector3(hsize / 2, 0, i * gridoffset + vsize / 2), new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt); maps.Add(i, (v / oneAU_m).ToString("N1") + "AU", f, Color.White, Color.Transparent, new Vector3(hsize / 2, 0, i * gridoffset - vsize / 2), new Vector3(hsize, 0, 0), new Vector3(0, 0, 0), fmt); } pos += 50000000; } } } var orbitlinesvertshader = new GLPLVertexShaderModelWorldUniform(new Color[] { Color.FromArgb(128, 128, 0, 0), Color.FromArgb(128, 128, 128, 0) }); orbitlineshader = new GLShaderPipeline(orbitlinesvertshader, new GLPLFragmentShaderVSColor()); bodyplaneshader = new GLShaderPipeline(orbitlinesvertshader, new GLPLFragmentShaderVSColor()); // model pos in, with uniform world pos, vectors out, with vs_colour selected by worldpos.w // set up ARB IDs for all images we are going to use.. var tbs = items.NewBindlessTextureHandleBlock(arbblock); var texs = items.NewTexture2D(null, Properties.Resources.golden, SizedInternalFormat.Rgba8); var texp = items.NewTexture2D(null, Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8); var texb = items.NewTexture2D(null, Properties.Resources.dotted, SizedInternalFormat.Rgba8); var texs2 = items.NewTexture2D(null, Properties.Resources.wooden, SizedInternalFormat.Rgba8); tbs.WriteHandles(new IGLTexture[] { texs, texp, texb, texs2 }); // using 0 tex coord, 4 image id and arb text binding var bodyfragshader = new GLPLFragmentShaderBindlessTexture(arbblock, discardiftransparent: true, useprimidover2: false); // takes 0:Vector4 model, 1: vec2 text, 4:matrix, out is 0:tex, 1: modelpos, 2: instance, 4 = matrix[3][3] var bodyvertshader = new GLPLVertexShaderModelMatrixTexture(1000000 * 1000 * mscaling, useeyedistance: false); bodyshader = new GLShaderPipeline(bodyvertshader, bodyfragshader); items.Add(bodyshader); // hold shape var sphereshape = GLSphereObjectFactory.CreateTexturedSphereFromTriangles(3, 1.0f); spherebuffer = items.NewBuffer(); // fill buffer with model co-ords spherebuffer.AllocateFill(sphereshape.Item1); spheretexcobuffer = items.NewBuffer(); // fill buffer with tex coords spheretexcobuffer.AllocateFill(sphereshape.Item2); bodymatrixbuffer = items.NewBuffer(); // this holds the matrix to set position and size GLStorageBlock findbufferresults = items.NewStorageBlock(findblock); var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16); // pass thru normal vert/tcs/tes then to geoshader for results findshader = items.NewShaderPipeline(null, bodyvertshader, null, null, geofind, null, null, null); }
/// <summary> Start the class with this matrixcalc. Pass the GL window control, and the initial lookat/cameradirection and zoom. /// Control if registration of mouse and keyboard UI is performed with GL window control /// </summary> public void Start(GLMatrixCalc mc, GLWindowControl win, Vector3 lookat, Vector3 cameradirdegrees, float zoomn, bool registermouseui = true, bool registerkeyui = true) { MatrixCalc = mc; Start(win, lookat, cameradirdegrees, zoomn, registermouseui, registerkeyui); }