/// <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; }
public void Create(GLItemsList items, GLRenderProgramSortedList rObjects, float sunsize, GLStorageBlock findbufferresults) { sunvertex = new GLPLVertexShaderModelCoordWorldAutoscale(new Color[] { Color.FromArgb(255, 220, 220, 10), Color.FromArgb(255, 0, 0, 0) }, autoscale: 30, autoscalemin: 1, autoscalemax: 2, useeyedistance: false); sunshader = items.NewShaderPipeline(null, sunvertex, new GLPLStarSurfaceFragmentShader()); shapebuf = items.NewBuffer(false); var shape = GLSphereObjectFactory.CreateSphereFromTriangles(2, sunsize); shapebuf.AllocateFill(shape); GLRenderState starrc = GLRenderState.Tri(); // render is triangles, with no depth test so we always appear starrc.DepthTest = true; starrc.DepthClamp = true; var textrc = GLRenderState.Tri(); textrc.DepthTest = true; textrc.ClipDistanceEnable = 1; // we are going to cull primitives which are deleted int texunitspergroup = 16; textshader = items.NewShaderPipeline(null, new GLPLVertexShaderMatrixTriStripTexture(), new GLPLFragmentShaderTexture2DIndexMulti(0, 0, true, texunitspergroup)); slset = new GLSetOfObjectsWithLabels("SLSet", rObjects, texunitspergroup, 100, 10, sunshader, shapebuf, shape.Length, starrc, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, textshader, BitMapSize, textrc, SizedInternalFormat.Rgba8); items.Add(slset); var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16); findshader = items.NewShaderPipeline(null, sunvertex, null, null, geofind, null, null, null); }
public void Create(GLItemsList items, GLRenderProgramSortedList rObjects, List <SystemClass> incomingsys, float bookmarksize, GLStorageBlock findbufferresults, bool depthtest) { if (ridisplay == null) { //var vert = new GLPLVertexScaleLookat(rotate: dorotate, rotateelevation: doelevation, commontransform: false, texcoords: true, // a look at vertex shader // // var vert = new GLPLVertexShaderWorldCoord(); var vert = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, texcoords: true, generateworldpos: true, autoscale: 500, autoscalemin: 1f, autoscalemax: 20f); // below 500, 1f, above 500, scale up to 20x const int texbindingpoint = 1; var frag = new GLPLFragmentShaderTexture(texbindingpoint); // binding - simple texturer based on vs model coords objectshader = new GLShaderPipeline(vert, null, null, null, frag); items.Add(objectshader); var objtex = items.NewTexture2D("Bookmarktex", TestOpenTk.Properties.Resources.dotted2, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8); objectshader.StartAction += (s, m) => { objtex.Bind(texbindingpoint); // bind tex array to, matching above }; bookmarkposbuf = items.NewBuffer(); // where we hold the vertexes for the suns, used by renderer and by finder GLRenderState rt = GLRenderState.Tri(); rt.DepthTest = depthtest; bookmarksize *= 10; // 0 is model pos, 1 is world pos by a buffer, 2 is tex co-ords ridisplay = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt, GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize), // quad2 4 vertexts as the model positions bookmarkposbuf, 0, // world positions come from here - not filled as yet GLShapeObjectFactory.TexTriStripQuad, ic: 0, seconddivisor: 1); rObjects.Add(objectshader, "bookmarks", ridisplay); var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);//, forwardfacing:false); findshader = items.NewShaderPipeline(null, vert, null, null, geofind, null, null, null); // hook to modelworldbuffer, at modelpos and worldpos. UpdateEnables will fill in instance count rifind = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt, GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize), // quad2 4 vertexts as the model positions bookmarkposbuf, 0, GLShapeObjectFactory.TexTriStripQuad, ic: 0, seconddivisor: 1); } bookmarkposbuf.AllocateFill(incomingsys.Select(x => new Vector4((float)x.X, (float)x.Y, (float)x.Z, 1)).ToArray()); ridisplay.InstanceCount = rifind.InstanceCount = incomingsys.Count; }
public void Start(GLItemsList items, GLRenderProgramSortedList rObjects, float bookmarksize, GLStorageBlock findbufferresults, bool depthtest) { var vert = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, texcoords: true, generateworldpos: true, autoscale: 30, autoscalemin: 1f, autoscalemax: 30f); // above autoscale, 1f const int texbindingpoint = 1; var frag = new GLPLFragmentShaderTexture(texbindingpoint); // binding - simple texturer based on vs model coords objectshader = new GLShaderPipeline(vert, null, null, null, frag); items.Add(objectshader); var objtex = items.NewTexture2D("Bookmarktex", BaseUtils.Icons.IconSet.GetBitmap("GalMap.Bookmark"), OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8); objectshader.StartAction += (s, m) => { objtex.Bind(texbindingpoint); // bind tex array to, matching above }; bookmarkposbuf = items.NewBuffer(); // where we hold the vertexes for the suns, used by renderer and by finder GLRenderState rt = GLRenderState.Tri(); rt.DepthTest = depthtest; // 0 is model pos, 1 is world pos by a buffer, 2 is tex co-ords ridisplay = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt, GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize), // quad2 4 vertexts as the model positions bookmarkposbuf, 0, // world positions come from here - not filled as yet GLShapeObjectFactory.TexTriStripQuad, ic: 0, seconddivisor: 1); rObjects.Add(objectshader, "bookmarks", ridisplay); var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);//, forwardfacing:false); findshader = items.NewShaderPipeline(null, vert, null, null, geofind, null, null, null); // hook to modelworldbuffer, at modelpos and worldpos. UpdateEnables will fill in instance count rifind = GLRenderableItem.CreateVector4Vector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rt, GLShapeObjectFactory.CreateQuadTriStrip(bookmarksize, bookmarksize), // quad2 4 vertexts as the model positions bookmarkposbuf, 0, GLShapeObjectFactory.TexTriStripQuad, ic: 0, seconddivisor: 1); }
private void IntCreatePath(GLItemsList items, GLRenderProgramSortedList rObjects, GLStorageBlock bufferfindresults) { HistoryEntry lastone = lastpos != -1 && lastpos < currentfilteredlist.Count ? currentfilteredlist[lastpos] : null; // see if lastpos is there, and store it if (TravelPathEndDateEnable || TravelPathStartDateEnable) { currentfilteredlist = unfilteredlist.Where(x => (!TravelPathStartDateEnable || x.EventTimeUTC >= TravelPathStartDate) && (!TravelPathEndDateEnable || x.EventTimeUTC <= TravelPathEndDate)).ToList(); if (currentfilteredlist.Count > MaxStars) { currentfilteredlist = currentfilteredlist.Skip(currentfilteredlist.Count - MaxStars).ToList(); } } else { if (unfilteredlist.Count > MaxStars) { currentfilteredlist = unfilteredlist.Skip(currentfilteredlist.Count - MaxStars).ToList(); } else { currentfilteredlist = unfilteredlist; } } // do date filter on currentfilteredlist lastpos = lastone == null ? -1 : currentfilteredlist.IndexOf(lastone); // may be -1, may have been removed var positionsv4 = currentfilteredlist.Select(x => new Vector4((float)x.System.X, (float)x.System.Y, (float)x.System.Z, 0)).ToArray(); var colours = currentfilteredlist.Select(x => x.JumpColor).ToArray(); float seglen = tapesize * 10; // a tape is a set of points (item1) and indexes to select them (item2), so we need an element index in the renderer to use. var tape = GLTapeObjectFactory.CreateTape(positionsv4, colours, tapesize, seglen, 0F.Radians(), margin: sunsize * 1.2f); if (ritape == null) // first time.. { // first the tape var tapetex = new GLTexture2D(Properties.Resources.chevron, internalformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8); // tape image items.Add(tapetex); tapetex.SetSamplerMode(OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat, OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat); tapefrag = new GLPLFragmentShaderTextureTriStripColorReplace(1, Color.FromArgb(255, 206, 0, 0)); var vert = new GLPLVertexShaderWorldTextureTriStrip(); tapeshader = new GLShaderPipeline(vert, tapefrag); items.Add(tapeshader); GLRenderState rts = GLRenderState.Tri(tape.Item3, cullface: false); // set up a Tri strip, primitive restart value set from tape, no culling rts.DepthTest = depthtest; // no depth test so always appears // now the renderer, set up with the render control, tape as the points, and bind a RenderDataTexture so the texture gets binded each time ritape = GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rts, tape.Item1.ToArray(), new GLRenderDataTexture(tapetex)); tapepointbuf = items.LastBuffer(); // keep buffer for refill ritape.Visible = tape.Item1.Count > 0; // no items, set not visible, so it won't except over the BIND with nothing in the element buffer ritape.CreateElementIndex(items.NewBuffer(), tape.Item2.ToArray(), tape.Item3); // finally, we are using index to select vertexes, so create an index rObjects.Add(tapeshader, "travelpath-tape", ritape); // add render to object list // now the stars starposbuf = items.NewBuffer(); // where we hold the vertexes for the suns, used by renderer and by finder starposbuf.AllocateFill(positionsv4); //Vector4[] vectors = starposbuf.ReadVector4s(0, starposbuf.Length / 16); sunvertex = new GLPLVertexShaderModelCoordWorldAutoscale(new Color[] { Color.Yellow, Color.FromArgb(255, 230, 230, 1) }, autoscale: 30, autoscalemin: 1f, autoscalemax: 2f, useeyedistance: false); // below scale, 1f, above scale, scale up to x times (eyedist/scale) sunshader = new GLShaderPipeline(sunvertex, new GLPLStarSurfaceFragmentShader()); items.Add(sunshader); var shape = GLSphereObjectFactory.CreateSphereFromTriangles(2, sunsize); GLRenderState rt = GLRenderState.Tri(); // render is triangles, with no depth test so we always appear rt.DepthTest = depthtest; rt.DepthClamp = true; renderersun = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, rt, shape, starposbuf, 0, null, currentfilteredlist.Count, 1); rObjects.Add(sunshader, "travelpath-suns", renderersun); // find compute var geofind = new GLPLGeoShaderFindTriangles(bufferfindresults, 16); findshader = items.NewShaderPipeline(null, sunvertex, null, null, geofind, null, null, null); rifind = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, GLRenderState.Tri(), shape, starposbuf, ic: currentfilteredlist.Count, seconddivisor: 1); // Sun names, handled by textrenderer textrenderer = new GLBitmaps("bm-travelmap", rObjects, new Size(128, 40), depthtest: depthtest, cullface: false); items.Add(textrenderer); } else { tapepointbuf.AllocateFill(tape.Item1.ToArray()); // replace the points with a new one ritape.RenderState.PrimitiveRestart = GL4Statics.DrawElementsRestartValue(tape.Item3); // IMPORTANT missing bit Robert, must set the primitive restart value to the new tape size ritape.CreateElementIndex(ritape.ElementBuffer, tape.Item2.ToArray(), tape.Item3); // update the element buffer ritape.Visible = tape.Item1.Count > 0; starposbuf.AllocateFill(positionsv4); // and update the star position buffers so find and sun renderer works renderersun.InstanceCount = positionsv4.Length; // update the number of suns to draw. rifind.InstanceCount = positionsv4.Length; // update the find list } // name bitmaps HashSet <object> hashset = new HashSet <object>(currentfilteredlist); // so it can find it quickly textrenderer.CurrentGeneration++; // setup for next generation textrenderer.RemoveGeneration(textrenderer.CurrentGeneration - 1, hashset); // and remove all of the previous one which are not in hashset. Font fnt = new Font("Arial", 8.5F); using (StringFormat fmt = new StringFormat()) { fmt.Alignment = StringAlignment.Center; foreach (var isys in currentfilteredlist) { if (textrenderer.Exist(isys) == false) // if does not exist already, need a new label { textrenderer.Add(isys, isys.System.Name, fnt, Color.White, Color.Transparent, new Vector3((float)isys.System.X, (float)isys.System.Y - 5, (float)isys.System.Z), new Vector3(20, 0, 0), new Vector3(0, 0, 0), textformat: fmt, rotatetoviewer: true, rotateelevation: false, alphafadescalar: -200, alphafadepos: 300); } } } fnt.Dispose(); }
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); }
public void Start(GLOFC.WinForm.GLWinFormControl glwfc, GalacticMapping edsmmapping, GalacticMapping eliteregions) { this.glwfc = glwfc; this.edsmmapping = edsmmapping; this.elitemapping = eliteregions; hptimer.Start(); items.Add(new GLMatrixCalcUniformBlock(), "MCUB"); // create a matrix uniform block int lyscale = 1; int front = -20000 / lyscale, back = front + 90000 / lyscale, left = -45000 / lyscale, right = left + 90000 / lyscale, vsize = 2000 / lyscale; if (false) // debug bounding box { 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 GLShaderPipeline(new GLPLVertexShaderWorldCoord(), new GLPLFragmentShaderFixedColor(Color.Yellow)), "LINEYELLOW"); rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl, displaylines)); items.Add(new GLColorShaderWorld(), "COS-1L"); float h = 0; int dist = 1000 / lyscale; 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 OpenTK.Graphics.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 OpenTK.Graphics.Color4[] { cr }) ); rObjects.Add(new GLOperationClearDepthBuffer()); } int ctrlo = 2048 | 32 | 64; ctrlo = -1; if ((ctrlo & 1) != 0) // galaxy { volumetricboundingbox = new Vector4[] { 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(left, -vsize, back, 1), new Vector4(left, vsize, back, 1), new Vector4(right, vsize, back, 1), new Vector4(right, -vsize, back, 1), }; const int gnoisetexbinding = 3; //tex bindings are attached per shaders so are not global const int gdisttexbinding = 4; const int galtexbinding = 1; volumetricblock = new GLVolumetricUniformBlock(volumenticuniformblock); items.Add(volumetricblock, "VB"); int sc = 1; GLTexture3D noise3d = new GLTexture3D(1024 * sc, 64 * sc, 1024 * sc, OpenTK.Graphics.OpenGL4.SizedInternalFormat.R32f); // red channel only items.Add(noise3d, "Noise"); ComputeShaderNoise3D csn = new ComputeShaderNoise3D(noise3d.Width, noise3d.Height, noise3d.Depth, 128 * sc, 16 * sc, 128 * sc, gnoisetexbinding); // must be a multiple of localgroupsize in csn csn.StartAction += (A, m) => { noise3d.BindImage(gnoisetexbinding); }; csn.Run(); // compute noise csn.Dispose(); GLTexture1D gaussiantex = new GLTexture1D(1024, OpenTK.Graphics.OpenGL4.SizedInternalFormat.R32f); // red channel only items.Add(gaussiantex, "Gaussian"); // set centre=width, higher widths means more curve, higher std dev compensate. // fill the gaussiantex with data ComputeShaderGaussian gsn = new ComputeShaderGaussian(gaussiantex.Width, 2.0f, 2.0f, 1.4f, gdisttexbinding); gsn.StartAction += (A, m) => { gaussiantex.BindImage(gdisttexbinding); }; gsn.Run(); // compute noise gsn.Dispose(); GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); // load one upside down and horz flipped, because the volumetric co-ords are 0,0,0 bottom left, 1,1,1 top right GLTexture2D galtex = new GLTexture2D(Properties.Resources.Galaxy_L180, SizedInternalFormat.Rgba8); items.Add(galtex, "galtex"); galaxyshader = new GalaxyShader(volumenticuniformblock, galtexbinding, gnoisetexbinding, gdisttexbinding); items.Add(galaxyshader, "Galaxy-sh"); // bind the galaxy texture, the 3dnoise, and the gaussian 1-d texture for the shader galaxyshader.StartAction += (a, m) => { galtex.Bind(galtexbinding); noise3d.Bind(gnoisetexbinding); gaussiantex.Bind(gdisttexbinding); }; // shader requires these, so bind using shader GLRenderState rt = GLRenderState.Tri(); galaxyrenderable = GLRenderableItem.CreateNullVertex(OpenTK.Graphics.OpenGL4.PrimitiveType.Points, rt); // no vertexes, all data from bound volumetric uniform, no instances as yet rObjects.Add(galaxyshader, "galshader", galaxyrenderable); } if ((ctrlo & 2) != 0) { var corr = new GalMapRegions.ManualCorrections[] { // nerf the centeroid position slightly new GalMapRegions.ManualCorrections("The Galactic Aphelion", y: -2000), new GalMapRegions.ManualCorrections("The Abyss", y: +3000), new GalMapRegions.ManualCorrections("Eurus", y: -3000), new GalMapRegions.ManualCorrections("The Perseus Transit", x: -3000, y: -3000), new GalMapRegions.ManualCorrections("Zephyrus", x: 0, y: 2000), }; edsmgalmapregions = new GalMapRegions(); edsmgalmapregions.CreateObjects("edsmregions", items, rObjects, edsmmapping, 8000, corr: corr); } if ((ctrlo & 4) != 0) { elitemapregions = new GalMapRegions(); elitemapregions.CreateObjects("eliteregions", items, rObjects, eliteregions, 8000); EliteRegionsEnable = false; } if ((ctrlo & 8) != 0) { int gran = 8; Bitmap img = Properties.Resources.Galaxy_L180; Bitmap heat = img.Function(img.Width / gran, img.Height / gran, mode: GLOFC.Utils.BitMapHelpers.BitmapFunction.HeatMap); heat.Save(@"c:\code\heatmap.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); Random rnd = new Random(23); GLBuffer buf = items.NewBuffer(16 * 350000, false); // since RND is fixed, should get the same number every time. buf.StartWrite(0); // get a ptr to the whole schebang int xcw = (right - left) / heat.Width; int zch = (back - front) / heat.Height; int points = 0; for (int x = 0; x < heat.Width; x++) { for (int z = 0; z < heat.Height; z++) { int i = heat.GetPixel(x, z).R; if (i > 32) { int gx = left + x * xcw; int gz = front + z * zch; float dx = (float)Math.Abs(gx) / 45000; float dz = (float)Math.Abs(25889 - gz) / 45000; double d = Math.Sqrt(dx * dx + dz * dz); // 0 - 0.1412 d = 1 - d; // 1 = centre, 0 = unit circle d = d * 2 - 1; // -1 to +1 double dist = ObjectExtensionsNumbersBool.GaussianDist(d, 1, 1.4); int c = Math.Min(Math.Max(i * i * i / 120000, 1), 40); //int c = Math.Min(Math.Max(i * i * i / 24000000, 1), 40); dist *= 2000 / lyscale; //System.Diagnostics.Debug.WriteLine("{0} {1} : dist {2} c {3}", x, z, dist, c); //System.Diagnostics.Debug.Write(c); GLPointsFactory.RandomStars4(buf, c, gx, gx + xcw, gz, gz + zch, (int)dist, (int)-dist, rnd, w: 0.8f); points += c; System.Diagnostics.Debug.Assert(points < buf.Length / 16); } } //System.Diagnostics.Debug.WriteLine("."); } buf.StopReadWrite(); stardots = new GalaxyStarDots(); items.Add(stardots); GLRenderState rc = GLRenderState.Points(1); rc.DepthTest = false; // note, if this is true, there is a wierd different between left and right in view.. not sure why rObjects.Add(stardots, "stardots", GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Points, rc, buf, points)); System.Diagnostics.Debug.WriteLine("Stars " + points); } rObjects.Add(new GLOperationClearDepthBuffer()); // clear depth buffer and now use full depth testing on the rest if ((ctrlo & 16) != 0) { items.Add(new GLTexture2D(Properties.Resources.StarFlare2, SizedInternalFormat.Rgba8), "lensflare"); items.Add(new GLPointSpriteShader(items.Tex("lensflare"), 64, 40), "PS"); var p = GLPointsFactory.RandomStars4(1000, 0, 25899 / lyscale, 10000 / lyscale, 1000 / lyscale, -1000 / lyscale); GLRenderState rps = GLRenderState.PointSprites(); rObjects.Add(items.Shader("PS"), "starsprites", GLRenderableItem.CreateVector4Color4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Points, rps, p, new Color4[] { Color.White })); } if ((ctrlo & 32) != 0) { gridvertshader = new DynamicGridVertexShader(Color.Cyan); //items.Add(gridvertshader, "PLGRIDVertShader"); var frag = new GLPLFragmentShaderVSColor(); //items.Add(frag, "PLGRIDFragShader"); GLRenderState rl = GLRenderState.Lines(1); items.Add(new GLShaderPipeline(gridvertshader, frag), "DYNGRID"); gridrenderable = GLRenderableItem.CreateNullVertex(OpenTK.Graphics.OpenGL4.PrimitiveType.Lines, rl, drawcount: 2); rObjects.Add(items.Shader("DYNGRID"), "DYNGRIDRENDER", gridrenderable); } if ((ctrlo & 64) != 0) { gridbitmapvertshader = new DynamicGridCoordVertexShader(); var frag = new GLPLFragmentShaderTexture2DIndexed(0); GLRenderState rl = GLRenderState.Tri(cullface: false); GLTexture2DArray gridtexcoords = new GLTexture2DArray(); items.Add(gridtexcoords, "PLGridBitmapTextures"); GLShaderPipeline sp = new GLShaderPipeline(gridbitmapvertshader, frag); items.Add(sp, "DYNGRIDBitmap"); rObjects.Add(items.Shader("DYNGRIDBitmap"), "DYNGRIDBitmapRENDER", GLRenderableItem.CreateNullVertex(OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rl, drawcount: 4, instancecount: 9)); } GLStorageBlock findresults = items.NewStorageBlock(findblock); float sunsize = .5f; if ((ctrlo & 128) != 0) { Random rnd = new Random(52); List <HistoryEntry> pos = new List <HistoryEntry>(); DateTime start = new DateTime(2020, 1, 1); Color[] colors = new Color[] { Color.Red, Color.Green, Color.Blue, Color.White, Color.Black, Color.Purple, Color.Yellow }; for (int j = 0; j <= 200; j++) { Color jc = colors[j % colors.Length]; int i = j * 10; string name = "Kyli Flyuae AA-B h" + j.ToString(); if (i < 30000) { pos.Add(new HistoryEntry(start, name, i + rnd.Next(50), rnd.Next(50), i, jc)); } else if (i < 60000) { pos.Add(new HistoryEntry(start, name, 60000 - i + rnd.Next(50), rnd.Next(50), i, jc)); } else if (i < 90000) { pos.Add(new HistoryEntry(start, name, -(i - 60000) + rnd.Next(50), rnd.Next(50), 120000 - i, jc)); } else { pos.Add(new HistoryEntry(start, name, -30000 + (i - 90000) + rnd.Next(50), rnd.Next(50), -i + 120000, jc)); } start = start.AddDays(1); } // tested to 50k stars travelpath = new TravelPath(1000); travelpath.Create(items, rObjects, pos, sunsize, sunsize, findresults, true); travelpath.SetSystem(0); } if ((ctrlo & 256) != 0) { galmapobjects = new GalMapObjects(); galmapobjects.CreateObjects(items, rObjects, edsmmapping, findresults, true); } if ((ctrlo & 512) != 0) { // galaxystars = new GalaxyStars(items, rObjects, sunsize, findresults); } if ((ctrlo & 1024) != 0) { rightclickmenu = new GLContextMenu("RightClickMenu", new GLMenuItem("RCMInfo", "Information") { MouseClick = (s, e) => { var nl = NameLocationDescription(rightclickmenu.Tag); System.Diagnostics.Debug.WriteLine($"Info {nl.Item1} {nl.Item2}"); // logical name is important as menu uses it to close down GLMessageBox msg = new GLMessageBox("InfoBoxForm-1", displaycontrol, e.WindowLocation, nl.Item3, $"{nl.Item1} @ {nl.Item2.X:#.#},{nl.Item2.Y:#.#},{nl.Item2.Z:#.#}", GLMessageBox.MessageBoxButtons.OK, null, Color.FromArgb(220, 60, 60, 70), Color.DarkOrange); } }, new GLMenuItem("RCMZoomIn", "Goto Zoom In") { MouseClick = (s1, e1) => { var nl = NameLocationDescription(rightclickmenu.Tag); gl3dcontroller.SlewToPositionZoom(nl.Item2, 100, -1); } }, new GLMenuItem("RCMGoto", "Goto Position") { MouseClick = (s1, e1) => { var nl = NameLocationDescription(rightclickmenu.Tag); System.Diagnostics.Debug.WriteLine($"Goto {nl.Item1} {nl.Item2}"); gl3dcontroller.SlewToPosition(nl.Item2, -1); } }, new GLMenuItem("RCMLookAt", "Look At") { MouseClick = (s1, e1) => { var nl = NameLocationDescription(rightclickmenu.Tag); gl3dcontroller.PanTo(nl.Item2, -1); } } ); } if ((ctrlo & 2048) != 0) { bookmarks = new Bookmarks(); var syslist = new List <SystemClass> { new SystemClass("bk1", 1000, 0, 0), new SystemClass("bk1", 1000, 0, 2000), }; bookmarks.Create(items, rObjects, syslist, 10, findresults, false); } // Matrix calc holding transform info matrixcalc = new GLMatrixCalc(); matrixcalc.PerspectiveNearZDistance = 1f; matrixcalc.PerspectiveFarZDistance = 120000f / lyscale; matrixcalc.InPerspectiveMode = true; matrixcalc.ResizeViewPort(this, glwfc.Size); // must establish size before starting // menu system displaycontrol = new GLControlDisplay(items, glwfc, matrixcalc, true, 0.00001f, 0.00001f); // hook form to the window - its the master displaycontrol.Font = new Font("Arial", 10f); displaycontrol.Focusable = true; // we want to be able to focus and receive key presses. displaycontrol.SetFocus(); // 3d controller gl3dcontroller = new Controller3D(); gl3dcontroller.PosCamera.ZoomMax = 600; // gives 5ly gl3dcontroller.ZoomDistance = 3000F / lyscale; gl3dcontroller.PosCamera.ZoomMin = 0.1f; gl3dcontroller.PosCamera.ZoomScaling = 1.1f; gl3dcontroller.YHoldMovement = true; gl3dcontroller.PaintObjects = Controller3DDraw; 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); }; // hook gl3dcontroller to display control - its the slave. Do not register mouse UI, we will deal with that. gl3dcontroller.Start(matrixcalc, displaycontrol, new Vector3(0, 0, 0), new Vector3(140.75f, 0, 0), 0.5F, false, true); //gl3dcontroller.Start(matrixcalc, displaycontrol, new Vector3(0, 0, 0), new Vector3(90F, 0, 0), 0.5F, false, true); if (displaycontrol != null) { displaycontrol.Paint += (o, ts) => // subscribing after start means we paint over the scene, letting transparency work { // MCUB set up by Controller3DDraw which did the work first galaxymenu.UpdateCoords(gl3dcontroller.MatrixCalc, gl3dcontroller.PosCamera.ZoomFactor); // debug this galaxymenu.DebugStatusText(gl3dcontroller.PosCamera.StringPositionCamera); gl3dcontroller.PosCamera.SetPositionCamera(gl3dcontroller.PosCamera.StringPositionCamera); displaycontrol.Animate(glwfc.ElapsedTimems); displaycontrol.Render(glwfc.RenderState, ts); }; } displaycontrol.MouseClick += MouseClickOnMap; displaycontrol.MouseUp += MouseUpOnMap; displaycontrol.MouseDown += MouseDownOnMap; displaycontrol.MouseMove += MouseMoveOnMap; displaycontrol.MouseWheel += MouseWheelOnMap; galaxymenu = new MapMenu(this); // Autocomplete text box at top for searching GLTextBoxAutoComplete tbac = ((GLTextBoxAutoComplete)displaycontrol[MapMenu.EntryTextName]); tbac.PerformAutoCompleteInUIThread = (s, a, set) => { System.Diagnostics.Debug.Assert(Application.MessageLoop); // must be in UI thread var glist = edsmmapping.galacticMapObjects.Where(x => s.Length < 3 ? x.name.StartsWith(s, StringComparison.InvariantCultureIgnoreCase) : x.name.Contains(s, StringComparison.InvariantCultureIgnoreCase)).Select(x => x).ToList(); List <string> list = glist.Select(x => x.name).ToList(); list.AddRange(travelpath.CurrentList.Where(x => s.Length < 3 ? x.System.Name.StartsWith(s, StringComparison.InvariantCultureIgnoreCase) : x.System.Name.Contains(s, StringComparison.InvariantCultureIgnoreCase)).Select(x => x.System.Name)); foreach (var x in list) { set.Add(x); } }; tbac.SelectedEntry = (a) => // in UI thread { System.Diagnostics.Debug.Assert(Application.MessageLoop); // must be in UI thread System.Diagnostics.Debug.WriteLine("Selected " + tbac.Text); var gmo = edsmmapping.galacticMapObjects.Find(x => x.name.Equals(tbac.Text, StringComparison.InvariantCultureIgnoreCase)); if (gmo != null) { System.Diagnostics.Debug.WriteLine("Move to gmo " + gmo.points[0]); gl3dcontroller.SlewToPosition(new Vector3((float)gmo.points[0].X, (float)gmo.points[0].Y, (float)gmo.points[0].Z), -1); } else { var he = travelpath.CurrentList.Find(x => x.System.Name.Equals(tbac.Text, StringComparison.InvariantCultureIgnoreCase)); if (he != null) { System.Diagnostics.Debug.WriteLine("Move to sys " + he.System.Name); gl3dcontroller.SlewToPosition(new Vector3((float)he.System.X, (float)he.System.Y, (float)he.System.Z), -1); } else { tbac.InErrorCondition = true; } } }; if (galaxystars != null) { galaxystars.Start(); } if (false) // enable for debug buffer { debugbuffer = new GLStorageBlock(31, true); debugbuffer.AllocateBytes(32000, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); // set size of vec buffer } if (false) // enable for debug { items.Add(new GLColorShaderObjectTranslation(), "COSOT"); GLRenderState rc = GLRenderState.Tri(cullface: false); rc.DepthTest = false; Vector3[] markers = new Vector3[] { new Vector3(0, 0, 0), new Vector3(0, -5, 0), new Vector3(0, -5 - 3.125f / 2f, 0) }; for (int i = 0; i < markers.Length; i++) { rObjects.Add(items.Shader("COSOT"), "marker" + i, GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc, GLCubeObjectFactory.CreateSolidCubeFromTriangles(0.5f), new Color4[] { Color4.Red, Color4.Green, Color4.Blue, Color4.White, Color4.Cyan, Color4.Orange }, new GLRenderDataTranslationRotation(markers[i]) )); } } }
public void CreateObjects(string name, GLItemsList items, GLRenderProgramSortedList rObjects, GalacticMapping galmap, float sizeofname = 5000, ManualCorrections[] corr = null) { List <Vector4> vertexcolourregions = new List <Vector4>(); List <Vector4> vertexregionsoutlines = new List <Vector4>(); List <ushort> vertexregionoutlineindex = new List <ushort>(); Size bitmapsize = new Size(250, 22); textrenderer = new GLBitmaps(name + "-bitmaps", rObjects, bitmapsize, depthtest: false, yfixed: true); items.Add(textrenderer); StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap) { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; Font fnt = new Font("MS Sans Serif", 12F); int cindex = 0; foreach (GalacticMapObject gmo in galmap.galacticMapObjects) { if (gmo.galMapType.Group == GalMapType.GalMapGroup.Regions) { string gmoname = gmo.name; List <Vector2> polygonxz = new List <Vector2>(); // needs it in x/z and in vector2's foreach (var pd in gmo.points) { polygonxz.Add(new Vector2((float)pd.X, (float)pd.Z)); // can be concave and wound the wrong way.. vertexregionoutlineindex.Add((ushort)(vertexregionsoutlines.Count)); vertexregionsoutlines.Add(new Vector4((float)pd.X, 0, (float)pd.Z, 1)); } vertexregionoutlineindex.Add(0xffff); // primitive restart to break polygon List <List <Vector2> > polys = PolygonTriangulator.Triangulate(polygonxz, false); // cut into convex polygons first - because we want the biggest possible area for naming purposes Vector2 avgcentroid = new Vector2(0, 0); int pointsaveraged = 0; if (polys.Count > 0) // just in case.. { foreach (List <Vector2> points in polys) // now for every poly { List <List <Vector2> > polytri; if (points.Count == 3) // already a triangle.. { polytri = new List <List <Vector2> >() { new List <Vector2>() { points[0], points[1], points[2] } } } ; else { polytri = PolygonTriangulator.Triangulate(points, true); // cut into triangles not polygons } foreach (List <Vector2> pt in polytri) { vertexcolourregions.Add(pt[0].ToVector4XZ(w: cindex)); vertexcolourregions.Add(pt[2].ToVector4XZ(w: cindex)); vertexcolourregions.Add(pt[1].ToVector4XZ(w: cindex)); var cx = (pt[0].X + pt[1].X + pt[2].X) / 3; var cy = (pt[0].Y + pt[1].Y + pt[2].Y) / 3; avgcentroid = new Vector2(avgcentroid.X + cx, avgcentroid.Y + cy); pointsaveraged++; //foreach (var pd in pt) // debug //{ // vertexregionoutlineindex.Add((ushort)(vertexregionsoutlines.Count)); // vertexregionsoutlines.Add(new Vector4((float)pd.X, 0, (float)pd.Y, 1)); //} //vertexregionoutlineindex.Add(0xffff); // primitive restart to break polygon } } cindex = (cindex + 1) % array.Length; Vector2 centeroid = PolygonTriangulator.WeightedCentroids(polys); if (corr != null) // allows the centeroid to be nerfed slightly { var entry = Array.Find(corr, x => gmo.name.Contains(x.name, StringComparison.InvariantCultureIgnoreCase)); if (entry != null) { centeroid = new Vector2(centeroid.X + entry.x, centeroid.Y + entry.y); } } var final = PolygonTriangulator.FitInsideConvexPoly(polys, centeroid, new Vector2(sizeofname, sizeofname * (float)bitmapsize.Height / (float)bitmapsize.Width)); Vector3 bestpos = new Vector3(final.Item1.X, 0, final.Item1.Y); Vector3 bestsize = new Vector3(final.Item2.X, 1, final.Item2.Y); textrenderer.Add(null, gmo.name, fnt, Color.White, Color.Transparent, bestpos, bestsize, new Vector3(0, 0, 0), fmt, alphafadescalar: 5000, alphafadepos: 500); } } } fmt.Dispose(); fnt.Dispose(); // regions var vertregion = new GLPLVertexShaderWorldPalletColor(array.ToVector4(0.1f), true); var fragregion = new GLPLFragmentShaderVSColor(); regionshader = new GLShaderPipeline(vertregion, fragregion, null, null); items.Add(regionshader); GLRenderState rt = GLRenderState.Tri(); rt.DepthTest = false; var ridisplay = GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, rt, vertexcolourregions.ToArray()); rObjects.Add(regionshader, name + "-regions", ridisplay); // outlines var vertoutline = new GLPLVertexShaderWorldCoord(true); var fragoutline = new GLPLFragmentShaderFixedColor(Color.Cyan); outlineshader = new GLShaderPipeline(vertoutline, fragoutline, null, null); items.Add(outlineshader); GLRenderState ro = GLRenderState.Lines(); ro.DepthTest = false; ro.PrimitiveRestart = 0xffff; var rioutline = GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.LineStrip, ro, vertexregionsoutlines.ToArray()); rioutline.CreateElementIndexUShort(items.NewBuffer(), vertexregionoutlineindex.ToArray()); rObjects.Add(outlineshader, name + "-outlines", rioutline); renderstate = 7; }
public void Start(string name, int maxstars, float sunsize, float tapesize, GLStorageBlock bufferfindresults, bool depthtest, GLItemsList items, GLRenderProgramSortedList rObjects) { this.MaxStars = maxstars; this.tapesize = tapesize; this.sunsize = sunsize; // first the tape var tapetex = new GLTexture2D(BaseUtils.Icons.IconSet.GetBitmap("GalMap.chevron"), internalformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8); // tape image items.Add(tapetex); tapetex.SetSamplerMode(OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat, OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat); // configure the fragger, set the replacement color, and set the distance where the replacement color is used for all pixels tapefrag = new GLPLFragmentShaderTextureTriStripColorReplace(1, Color.FromArgb(255, 206, 0, 0), 1000); // create the vertex shader with the autoscale required var vert = new GLPLVertexShaderWorldTextureTriStripNorm(100, 1, 10000); vert.SetWidth(tapesize); // set the nominal tape width tapeshader = new GLShaderPipeline(vert, tapefrag); items.Add(tapeshader); GLRenderState rts = GLRenderState.Tri(OpenTK.Graphics.OpenGL4.DrawElementsType.UnsignedByte, cullface: false); // set up a Tri strip, Default primitive restart rts.DepthTest = depthtest; // no depth test so always appears // now the renderer, set up with the render control, tape as the points, and bind a RenderDataTexture so the texture gets binded each time var zerotape = new Vector4[] { Vector4.Zero }; // just use an dummy array to get this going ritape = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.TriangleStrip, rts, zerotape, zerotape, new GLRenderDataTexture(tapetex)); tapepointbuf = items.LastBuffer(); // keep buffer for refill ritape.ElementBuffer = items.NewBuffer(); // empty buffer for element index for now ritape.Visible = false; // until its filled, not visible (important, we don't want render to execute unless its been fully set up below) rObjects.Add(tapeshader, name + "-tape", ritape); // add render to object list // now the stars starposbuf = items.NewBuffer(); // where we hold the vertexes for the suns, used by renderer and by finder // the colour index of the stars is selected by the w parameter of the world position vertexes. // we autoscale to make them bigger at greater distances from eye sunvertex = new GLPLVertexShaderModelCoordWorldAutoscale(new Color[] { Color.Yellow, Color.FromArgb(255, 230, 230, 1) }, autoscale: 30, autoscalemin: 1, autoscalemax: 2, useeyedistance: false); sunshader = new GLShaderPipeline(sunvertex, new GLPLStarSurfaceFragmentShader()); items.Add(sunshader); var shape = GLSphereObjectFactory.CreateSphereFromTriangles(2, sunsize); GLRenderState rt = GLRenderState.Tri(); // render is triangles, with no depth test so we always appear rt.DepthTest = depthtest; rt.DepthClamp = true; renderersun = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, rt, shape, starposbuf, 0, null, 0, 1); renderersun.Visible = false; // until its filled, not visible rObjects.Add(sunshader, name + "-suns", renderersun); // find compute var geofind = new GLPLGeoShaderFindTriangles(bufferfindresults, 16); findshader = items.NewShaderPipeline(null, sunvertex, null, null, geofind, null, null, null); rifind = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, GLRenderState.Tri(), shape, starposbuf, ic: 0, seconddivisor: 1); // Sun names, handled by textrenderer textrenderer = new GLBitmaps(name + "-text", rObjects, BitMapSize, depthtest: depthtest, cullface: false); items.Add(textrenderer); }