protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(110f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 50.0f);
            };

            //items.Add("lensflarewhite", new GLTexture2D(Properties.Resources.lensflare_white64));
            items.Add(new GLTexture2D(Properties.Resources.StarFlare2, SizedInternalFormat.Rgba8), "lensflare");

            items.Add(new GLColorShaderWorld(), "COS");

            #region coloured lines

            {
                GLRenderState rl = GLRenderState.Lines(1);
                rObjects.Add(items.Shader("COS"),    // horizontal
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green })
                             );


                rObjects.Add(items.Shader("COS"),    // vertical
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green })
                             );
            }

            var p = GLPointsFactory.RandomStars4(100, -100, 100, 100, -100, 100, -100);
            //p = new Vector4[10];
            //for( int i = 0; i < 10; i++)
            //{
            //    p[i] = new Vector4(i, 6.8f, 0,1);
            //}

            items.Add(new GLPointSprite(), "PS1");

            GLRenderState rp = GLRenderState.PointSprites();     // by program

            GLRenderDataTexture rt = new GLRenderDataTexture(items.Tex("lensflare"), 4);

            rObjects.Add(items.Shader("PS1"),
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Points, rp,
                                                              p, new Color4[] { Color.Red, Color.Yellow, Color.Green }, rt));

            #endregion

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block
        }
Exemple #2
0
        // Demonstrate buffer feedback AND geo shader add vertex/dump vertex

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(170f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 20.0f);
            };

            // 16 vertexes, passed thru geo shader above

            GLStorageBlock storagebuffer = new GLStorageBlock(5);           // new storage block on binding index 5 to provide vertexes

            Vector4[] vertexes = new Vector4[16];
            for (int v = 0; v < vertexes.Length; v++)
            {
                vertexes[v] = new Vector4(v % 4, 0, v / 4, 1);
            }
            storagebuffer.AllocateFill(vertexes);

            items.Add(new ShaderT3(), "Shader");            // geo shader
            GLRenderState ri = GLRenderState.Points();

            rObjects.Add(items.Shader("Shader"), "T1", new GLRenderableItem(PrimitiveType.Points, ri, vertexes.Length, null, null, 1));

            // list of rejected by geoshader above

            rejectedbuffer = new GLStorageBlock(1);                                                                     // new storage block on binding index 1 for vector out
            rejectedbuffer.AllocateBytes(sizeof(float) * 4 * 128, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); // set size of vec buffer
            countbuffer = new GLStorageBlock(2);                                                                        // new storage block on binding index 2 for count out
            countbuffer.AllocateBytes(sizeof(int), OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead);                // set size to a int.

            // redrawer of rejected items

            items.Add(new GLShaderPipeline(new GLPLVertexShaderWorldCoord(), new GLPLFragmentShaderFixedColor(new Color4(0.9f, 0.0f, 0.0f, 1.0f))), "ResultShader");
            GLRenderState rs = GLRenderState.Points(30);

            redraw = GLRenderableItem.CreateVector4(items, PrimitiveType.Points, rs, rejectedbuffer, 0);
            rObjects2.Add(items.Shader("ResultShader"), redraw);

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // def binding of 0

            Closed += ShaderTest_Closed;
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(110f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 100.0f);
            };


            items.Add(new GLColorShaderWorld(), "COSW");
            GLRenderState rl1 = GLRenderState.Lines(1);

            {
                rObjects.Add(items.Shader("COSW"), "L1",   // horizontal
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Gray })
                             );


                rObjects.Add(items.Shader("COSW"),    // vertical
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Gray })
                             );
            }

            items.Add(new GLTexture2D(Properties.Resources.galheightmap7, SizedInternalFormat.Rgba8), "gal");

            items.Add(new GLGalShader(), "TEX-NC");

            GLRenderState rg = GLRenderState.Quads(cullface: false);

            rObjects.Add(items.Shader("TEX-NC"),
                         GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rg,
                                                               GLShapeObjectFactory.CreateQuad(200.0f, 200.0f, new Vector3(0, 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                               new GLRenderDataTranslationRotationTexture(items.Tex("gal"), new Vector3(0, 0, 0))
                                                               ));

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block
        }
Exemple #4
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);
        }
 /// <summary> Construct, on an item list, a buffer with this size </summary>
 public GLMatrixBufferWithGenerations(GLItemsList items, int maximumsize)
 {
     MatrixBuffer = new GLBuffer();
     items.Add(MatrixBuffer);
     Max = maximumsize;
     MatrixBuffer.AllocateBytes(Max * GLLayoutStandards.Mat4size);
     MatrixBuffer.AddPosition(0);        // CreateMatrix4 needs to have a position
 }
Exemple #6
0
        /// <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;
        }
Exemple #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="items">Item list to store buffers into</param>
 /// <param name="vertsize">Size of vertex buffer</param>
 /// <param name="indirectsize">Size of indirect buffer</param>
 /// <param name="std430">Std430 layout</param>
 /// <param name="bufferusagehint">Buffer usage hint</param>
 public GLVertexBufferIndirect(GLItemsList items, int vertsize, int indirectsize, bool std430 = false, BufferUsageHint bufferusagehint = BufferUsageHint.StaticDraw)
 {
     this.items        = items;
     this.indirectsize = indirectsize;
     this.bufferusage  = bufferusagehint;
     this.context      = GLStatics.GetContext();
     Vertex            = new GLBuffer(vertsize, std430, bufferusagehint);
     items.Add(Vertex);
 }
        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;
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(110f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 100.0f);
            };

            items.Add("COS-1L", new GLColourShaderWithWorldCoord((a) => { GLStatics.LineWidth(1); }));

            #region coloured lines

            rObjects.Add(items.Shader("COS-1L"),    // horizontal
                         GLRenderableItem.CreateVector4Color4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Lines,
                                                              GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21),
                                                              new Color4[] { Color.Gray })
                         );


            rObjects.Add(items.Shader("COS-1L"),    // vertical
                         GLRenderableItem.CreateVector4Color4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Lines,
                                                              GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21),
                                                              new Color4[] { Color.Gray })
                         );


            #endregion

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block
        }
Exemple #10
0
        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);
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(135, 0, 0), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 100.0f);
            };

            items.Add(new GLColorShaderWorld(), "COSW");
            GLRenderState rl1 = GLRenderState.Lines(1);

            {
                rObjects.Add(items.Shader("COSW"), "L1",   // horizontal
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Gray })
                             );


                rObjects.Add(items.Shader("COSW"),    // vertical
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Gray })
                             );
            }

            int hsize = 10, vsize = 5, zsize = 10;

            boundingbox = new Vector4[]
            {
                new Vector4(-hsize, -vsize, zsize, 1),
                new Vector4(-hsize, vsize, zsize, 1),
                new Vector4(hsize, vsize, zsize, 1),
                new Vector4(hsize, -vsize, zsize, 1),

                new Vector4(-hsize, -vsize, -zsize, 1),
                new Vector4(-hsize, vsize, -zsize, 1),
                new Vector4(hsize, vsize, -zsize, 1),
                new Vector4(hsize, -vsize, -zsize, 1),
            };


            {
                GLRenderState rll = GLRenderState.Lines(4);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rll, boundingbox));

                Vector4[] extralines = new Vector4[]
                {
                    new Vector4(-hsize, -vsize, zsize, 1),
                    new Vector4(-hsize, -vsize, -zsize, 1),

                    new Vector4(-hsize, vsize, zsize, 1),
                    new Vector4(-hsize, vsize, -zsize, 1),

                    new Vector4(hsize, vsize, zsize, 1),
                    new Vector4(hsize, vsize, -zsize, 1),

                    new Vector4(hsize, -vsize, zsize, 1),
                    new Vector4(hsize, -vsize, -zsize, 1),

                    new Vector4(-hsize, -vsize, zsize, 1),
                    new Vector4(hsize, -vsize, zsize, 1),

                    new Vector4(-hsize, -vsize, -zsize, 1),
                    new Vector4(hsize, -vsize, -zsize, 1),
                };

                GLRenderState rl = GLRenderState.Lines(4);
                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl, extralines));
            }

            items.Add(new GLFixedShader(System.Drawing.Color.Purple), "LINEPURPLE");

            indicatorlinebuffer = new GLBuffer();                                                                          // new buffer
            indicatorlinebuffer.AllocateBytes(sizeof(float) * 4 * 2, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); // set size of vec buffer
            rObjects.Add(items.Shader("LINEPURPLE"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, indicatorlinebuffer, 2));

            items.Add(new GLFixedProjectionShader(System.Drawing.Color.Yellow), "DOTYELLOW");
            interceptpointbuffer = new GLBuffer();                                                                           // new buffer
            interceptpointbuffer.AllocateBytes(sizeof(float) * 4 * 12, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); // set size of vec buffer
            GLRenderState rp1 = GLRenderState.Points(10);

            interceptri = GLRenderableItem.CreateVector4(items, PrimitiveType.Points, rp1, interceptpointbuffer, 0);
            rObjects.Add(items.Shader("DOTYELLOW"), interceptri);

            items.Add(new GLFixedProjectionShader(System.Drawing.Color.FromArgb(60, Color.Blue)), "SURFACEBLUE");
            surfacebuffer = new GLBuffer();                                                                                // new buffer
            surfacebuffer.AllocateBytes(sizeof(float) * 4 * (6 + 2), OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); // set size of vec buffer
            GLRenderState rtf = GLRenderState.Tri();

            surfaceri = GLRenderableItem.CreateVector4(items, PrimitiveType.TriangleFan, rtf, surfacebuffer, 0);
            rObjects.Add(items.Shader("SURFACEBLUE"), surfaceri);

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block
        }
        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])
                                                                      ));
                }
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            gl3dcontroller.ZoomDistance = 40F;
            gl3dcontroller.MouseRotateAmountPerPixel = 0.05f;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(135, 0, 0), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 100.0f);
            };

            items.Add(new GLColorShaderWorld(), "COSW");
            GLRenderState rl1 = GLRenderState.Lines(1);

            {
                rObjects.Add(items.Shader("COSW"), "L1",   // horizontal
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Gray })
                             );


                rObjects.Add(items.Shader("COSW"),    // vertical
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Gray })
                             );
            }

            // Number markers using instancing and 2d arrays, each with its own transform
            {
                Bitmap[]  numbers   = new Bitmap[20];
                Matrix4[] numberpos = new Matrix4[20];

                Font fnt = new Font("Arial", 44);

                for (int i = 0; i < numbers.Length; i++)
                {
                    int v = -100 + i * 10;
                    numbers[i] = new Bitmap(100, 100);
                    GLOFC.Utils.BitMapHelpers.DrawTextCentreIntoBitmap(ref numbers[i], v.ToString(), fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Red, Color.AliceBlue);
                    numberpos[i]  = Matrix4.CreateScale(1);
                    numberpos[i] *= Matrix4.CreateRotationX(-80f.Radians());
                    numberpos[i] *= Matrix4.CreateTranslation(new Vector3(20, 0, v));
                }

                GLTexture2DArray array = new GLTexture2DArray(numbers, SizedInternalFormat.Rgba8, ownbmp: true);
                items.Add(array, "Nums");
                items.Add(new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0)), "IC-2");

                GLRenderState       rq = GLRenderState.Quads(cullface: false);
                GLRenderDataTexture rt = new GLRenderDataTexture(items.Tex("Nums"));

                rObjects.Add(items.Shader("IC-2"), "1-b",
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(1.0f), GLShapeObjectFactory.TexQuadCW, numberpos, rt,
                                                                          numberpos.Length));
            }

            {
                int       left = -40, right = 40, bottom = -20, top = +20, front = -40, back = 40;
                Vector4[] lines2 = new Vector4[]
                {
                    new Vector4(left, bottom, front, 1), new Vector4(left, top, front, 1),
                    new Vector4(left, top, front, 1), new Vector4(right, top, front, 1),
                    new Vector4(right, top, front, 1), new Vector4(right, bottom, front, 1),
                    new Vector4(right, bottom, front, 1), new Vector4(left, bottom, front, 1),

                    new Vector4(left, bottom, back, 1), new Vector4(left, top, back, 1),
                    new Vector4(left, top, back, 1), new Vector4(right, top, back, 1),
                    new Vector4(right, top, back, 1), new Vector4(right, bottom, back, 1),
                    new Vector4(right, bottom, back, 1), new Vector4(left, bottom, back, 1),

                    new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1),
                    new Vector4(left, top, front, 1), new Vector4(left, top, back, 1),
                    new Vector4(right, bottom, front, 1), new Vector4(right, bottom, back, 1),
                    new Vector4(right, top, front, 1), new Vector4(right, top, back, 1),
                };

                items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW");
                rObjects.Add(items.Shader("LINEYELLOW"),
                             GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, lines2));
            }


            items.Add(new ShaderV2(), "V2");

            Vector4[] points = new Vector4[]
            {
                new Vector4(-40, -20, -40, 1),
                new Vector4(+40, +20, +40, 1),
            };

            GLRenderState rltot = GLRenderState.Tri();

            rObjects.Add(items.Shader("V2"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rltot, points, ic: 1));

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block

            dataoutbuffer = items.NewStorageBlock(5);
            dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead);    // 32 vec4 back

            atomicbuffer = items.NewAtomicBlock(6);
            atomicbuffer.AllocateBytes(sizeof(float) * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy);
        }
        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();
        }
Exemple #15
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f;
            gl3dcontroller.MatrixCalc.PerspectiveFarZDistance  = 100000f;
            gl3dcontroller.ZoomDistance          = 5000F;
            gl3dcontroller.PosCamera.ZoomMin     = 0.1f;
            gl3dcontroller.PosCamera.ZoomScaling = 1.1f;
            gl3dcontroller.YHoldMovement         = true;
            gl3dcontroller.PaintObjects          = ControllerDraw;

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms * 1.0f * Math.Min(eyedist / 1000, 10));
            };

            gl3dcontroller.MatrixCalc.InPerspectiveMode = true;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F);

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block

            int front = -20000, back = front + 90000, left = -45000, right = left + 90000, vsize = 2000;

            boundingbox = 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),
            };

            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),
            };

            {
                items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW");
                GLRenderState rl = GLRenderState.Lines(1);
                rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl, displaylines));
            }


            {
                items.Add(new GLTexture2D(Properties.Resources.golden, SizedInternalFormat.Rgba8), "solmarker");
                items.Add(new GLTexturedShaderObjectTranslation(), "TEX");
                GLRenderState rq = GLRenderState.Quads(cullface: false);
                rObjects.Add(items.Shader("TEX"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(1000.0f, 1000.0f, new Vector3(0, 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("solmarker"), new Vector3(0, 1000, 0))
                                                                   ));
                rObjects.Add(items.Shader("TEX"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(1000.0f, 1000.0f, new Vector3(0, 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("solmarker"), new Vector3(0, -1000, 0))
                                                                   ));
                items.Add(new GLTexture2D(Properties.Resources.dotted, SizedInternalFormat.Rgba8), "sag");
                rObjects.Add(items.Shader("TEX"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(1000.0f, 1000.0f, new Vector3(0, 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("sag"), new Vector3(25.2f, 2000, 25899))
                                                                   ));
                rObjects.Add(items.Shader("TEX"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(1000.0f, 1000.0f, new Vector3(0, 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("sag"), new Vector3(25.2f, -2000, 25899))
                                                                   ));
                items.Add(new GLTexture2D(Properties.Resources.dotted2, SizedInternalFormat.Rgba8), "bp");
                rObjects.Add(items.Shader("TEX"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(1000.0f, 1000.0f, new Vector3(0, 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("bp"), new Vector3(-1111f, 0, 65269))
                                                                   ));
            }

            if (false) // galaxy
            {
                volumetricblock = new GLVolumetricUniformBlock();
                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); // must be a multiple of localgroupsize in csn
                csn.StartAction += (A, m) => { noise3d.BindImage(3); };
                csn.Run();                                                                                                                      // compute noise

                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, 4);
                gsn.StartAction += (A, m) => { gaussiantex.BindImage(4); };
                gsn.Run();      // compute noise

                GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits);

                //float[] gdata = gaussiantex.GetTextureImageAsFloats(OpenTK.Graphics.OpenGL4.PixelFormat.Red); // read back check
                //for( int i = 0; i < gdata.Length; i++  )
                //{
                //    double v = ((float)i / gdata.Length-0.5)*2*2;
                //    double r = ObjectExtensionsNumbersBool.GaussianDist(v, 2, 1.4);
                // //   System.Diagnostics.Debug.WriteLine(i + ":" + gdata[i] + ": " +  r);
                //}

                // 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, "gal");
                GalaxyShader gs = new GalaxyShader();
                items.Add(gs, "Galaxy");
                // bind the galaxy texture, the 3dnoise, and the gaussian 1-d texture for the shader
                gs.StartAction = (a, m) => { galtex.Bind(1); noise3d.Bind(3); gaussiantex.Bind(4); };      // shader requires these, so bind using shader

                GLRenderState rt = GLRenderState.Tri();
                galaxy = GLRenderableItem.CreateNullVertex(PrimitiveType.Points, rt);   // no vertexes, all data from bound volumetric uniform, no instances as yet
                rObjects.Add(items.Shader("Galaxy"), galaxy);
            }

            if (true) // star points
            {
                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 = new GLBuffer(16 * 500000); // 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;
                        int ii = i * i * i;
                        if (ii > 32 * 32 * 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(ii / 140000, 0), 20);

                            dist *= 2000;

                            GLPointsFactory.RandomStars4(buf, c, gx, gx + xcw, gz, gz + zch, (int)dist, (int)-dist, rnd, w: i);
                            points += c;
                            System.Diagnostics.Debug.Assert(points < buf.Length / 16);
                        }
                    }
                }

                buf.StopReadWrite();

                items.Add(new GalaxyStarDots(), "SD");
                GLRenderState rp = GLRenderState.Points(1);
                rp.DepthTest = false;
                rObjects.Add(items.Shader("SD"),
                             GLRenderableItem.CreateVector4(items, PrimitiveType.Points, rp, buf, points));
                System.Diagnostics.Debug.WriteLine("Stars " + points);
            }

            if (true)  // point sprite
            {
                items.Add(new GLTexture2D(Properties.Resources.StarFlare2, SizedInternalFormat.Rgba8), "lensflare");
                items.Add(new GLPointSpriteShader(items.Tex("lensflare"), 64, 40), "PS1");
                var p = GLPointsFactory.RandomStars4(1000, 0, 25899, 10000, 1000, -1000);

                GLRenderState rps = GLRenderState.PointSprites();
                rps.DepthTest = false;

                rObjects.Add(items.Shader("PS1"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Points, rps, p, new Color4[] { Color.White }));
            }

            {
                items.Add(new DynamicGridVertexShader(Color.Cyan), "PLGRIDVertShader");
                items.Add(new GLPLFragmentShaderVSColor(), "PLGRIDFragShader");

                GLRenderState rl = GLRenderState.Lines(1);
                rl.DepthTest = false;

                items.Add(new GLShaderPipeline(items.PLShader("PLGRIDVertShader"), items.PLShader("PLGRIDFragShader")), "DYNGRID");
                rObjects.Add(items.Shader("DYNGRID"), "DYNGRIDRENDER", GLRenderableItem.CreateNullVertex(PrimitiveType.Lines, rl, drawcount: 2));
            }


            {
                items.Add(new DynamicGridCoordVertexShader(), "PLGRIDBitmapVertShader");
                items.Add(new GLPLFragmentShaderTexture2DIndexed(0), "PLGRIDBitmapFragShader");     // binding

                GLRenderState rl = GLRenderState.Tri(cullface: false);
                rl.DepthTest = false;

                gridtexcoords = new GLTexture2DArray();
                items.Add(gridtexcoords, "PLGridBitmapTextures");

                GLShaderPipeline sp = new GLShaderPipeline(items.PLShader("PLGRIDBitmapVertShader"), items.PLShader("PLGRIDBitmapFragShader"));

                items.Add(sp, "DYNGRIDBitmap");

                rObjects.Add(items.Shader("DYNGRIDBitmap"), "DYNGRIDBitmapRENDER", GLRenderableItem.CreateNullVertex(PrimitiveType.TriangleStrip, rl, drawcount: 4, instancecount: 9));
            }
        }
Exemple #16
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            //GLStatics.EnableDebug(DebugProc);

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f;
            gl3dcontroller.MatrixCalc.PerspectiveFarZDistance  = 500000f;
            gl3dcontroller.ZoomDistance  = 5000F;
            gl3dcontroller.YHoldMovement = true;

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms * 10.0f);
            };

            gl3dcontroller.MatrixCalc.InPerspectiveMode = true;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, -35000), new Vector3(135f, 0, 0), 0.31622F);


            items.Add(new GLColorShaderWorld(), "COSW");
            GLRenderState rl1 = GLRenderState.Lines(1);

            float h = -1;

            if (h != -1)
            {
                Color cr = Color.FromArgb(60, Color.Gray);
                rObjects.Add(items.Shader("COS-1L"),    // horizontal
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-35000, h, -35000), new Vector3(-35000, h, 35000), new Vector3(1000, 0, 0), 70),
                                                                  new Color4[] { cr })
                             );

                rObjects.Add(items.Shader("COS-1L"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-35000, h, -35000), new Vector3(35000, h, -35000), new Vector3(0, 0, 1000), 70),
                                                                  new Color4[] { cr })
                             );
            }

            int hsize = 35000, vsize = 2000, zsize = 35000;

            {
                int       left = -hsize, right = hsize, bottom = -vsize, top = +vsize, front = -zsize, back = zsize;
                Vector4[] lines2 = new Vector4[]
                {
                    new Vector4(left, bottom, front, 1), new Vector4(left, top, front, 1),
                    new Vector4(left, top, front, 1), new Vector4(right, top, front, 1),
                    new Vector4(right, top, front, 1), new Vector4(right, bottom, front, 1),
                    new Vector4(right, bottom, front, 1), new Vector4(left, bottom, front, 1),

                    new Vector4(left, bottom, back, 1), new Vector4(left, top, back, 1),
                    new Vector4(left, top, back, 1), new Vector4(right, top, back, 1),
                    new Vector4(right, top, back, 1), new Vector4(right, bottom, back, 1),
                    new Vector4(right, bottom, back, 1), new Vector4(left, bottom, back, 1),

                    new Vector4(left, bottom, front, 1), new Vector4(left, bottom, back, 1),
                    new Vector4(left, top, front, 1), new Vector4(left, top, back, 1),
                    new Vector4(right, bottom, front, 1), new Vector4(right, bottom, back, 1),
                    new Vector4(right, top, front, 1), new Vector4(right, top, back, 1),
                };

                items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW");
                rObjects.Add(items.Shader("LINEYELLOW"),
                             GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, lines2));
            }

            // bounding box

            boundingbox = new Vector4[]
            {
                new Vector4(-hsize, -vsize, -zsize, 1),
                new Vector4(-hsize, vsize, -zsize, 1),
                new Vector4(hsize, vsize, -zsize, 1),
                new Vector4(hsize, -vsize, -zsize, 1),

                new Vector4(-hsize, -vsize, zsize, 1),
                new Vector4(-hsize, vsize, zsize, 1),
                new Vector4(hsize, vsize, zsize, 1),
                new Vector4(hsize, -vsize, zsize, 1),
            };

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block

            dataoutbuffer = items.NewStorageBlock(5);
            dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead);    // 32 vec4 back

            atomicbuffer = items.NewAtomicBlock(6);
            atomicbuffer.AllocateBytes(sizeof(float) * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy);

            dataoutbuffer = items.NewStorageBlock(5);
            dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 256, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead);    // 32 vec4 back

            volumetricblock = new GLVolumetricUniformBlock();
            items.Add(volumetricblock, "VB");

            {
                Bitmap[]  numbers    = new Bitmap[70];
                Matrix4[] numberpos  = new Matrix4[numbers.Length];
                Matrix4[] numberpos2 = new Matrix4[numbers.Length];

                Font fnt = new Font("Arial", 20);

                for (int i = 0; i < numbers.Length; i++)
                {
                    int v = -35000 + i * 1000;
                    numbers[i] = new Bitmap(100, 100);
                    GLOFC.Utils.BitMapHelpers.DrawTextCentreIntoBitmap(ref numbers[i], v.ToString(), fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Red, Color.AliceBlue);

                    numberpos[i]   = Matrix4.CreateScale(1);
                    numberpos[i]  *= Matrix4.CreateRotationX(-25f.Radians());
                    numberpos[i]  *= Matrix4.CreateTranslation(new Vector3(35500, 0, v));
                    numberpos2[i]  = Matrix4.CreateScale(1);
                    numberpos2[i] *= Matrix4.CreateRotationX(-25f.Radians());
                    numberpos2[i] *= Matrix4.CreateTranslation(new Vector3(v, 0, -35500));
                }

                GLTexture2DArray array = new GLTexture2DArray(numbers, SizedInternalFormat.Rgba8, ownbmp: true);
                items.Add(array, "Nums");
                items.Add(new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0)), "IC-2");

                GLRenderState       rq = GLRenderState.Quads(cullface: false);
                GLRenderDataTexture rt = new GLRenderDataTexture(items.Tex("Nums"));

                rObjects.Add(items.Shader("IC-2"), "1-b",
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberpos,
                                                                          rt, numberpos.Length));

                rObjects.Add(items.Shader("IC-2"), "1-b2",
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberpos2,
                                                                          rt, numberpos.Length));
            }

            GLTexture3D noise3d = new GLTexture3D(1024, 64, 1024, OpenTK.Graphics.OpenGL4.SizedInternalFormat.R32f); // red channel only

            //{     // shows program fill
            //    for (int ly = 0; ly < noise3d.Depth; ly++)
            //    {
            //        float[] fd = new float[noise3d.Width * noise3d.Height];
            //        float[] fdi = new float[noise3d.Width * noise3d.Height];
            //        for (int x = 0; x < noise3d.Width; x++)
            //        {
            //            for (int y = 0; y < noise3d.Height; y++)
            //            {
            //                int p = (y * noise3d.Width + x) * 1;

            //                float xv = (float)x / (float)noise3d.Width;
            //                float yv = (float)y / (float)noise3d.Height;

            //                var c = ((Math.Sin(2 * Math.PI * xv) / 2) + 0.5);
            //                c += ((Math.Cos(2 * Math.PI * yv) / 2) + 0.5);

            //                c /= 2;

            //                fd[p + 0] = (float)(c);
            //                fdi[p + 0] = 1.0f-(float)(c);
            //            }
            //        }

            //        noise3d.StoreZPlane(ly, 0, 0, noise3d.Width, noise3d.Height, fd, OpenTK.Graphics.OpenGL4.PixelFormat.Red);        // only a single float per pixel, stored in RED

            //    }
            //}

            ShaderNoiseDisplay ns = new ShaderNoiseDisplay();

            ns.StartAction += (a, m) => { noise3d.Bind(3); };
            items.Add(ns, "NS");
            GLRenderState rv = GLRenderState.Tri();

            noisebox = GLRenderableItem.CreateNullVertex(OpenTK.Graphics.OpenGL4.PrimitiveType.Points, rv);   // no vertexes, all data from bound volumetric uniform, no instances as yet

            rObjects.Add(items.Shader("NS"), noisebox);

            // make a compute shader noise and run it, to fill up noise3d buffer

            ComputeShaderNoise csn = new ComputeShaderNoise(noise3d.Width, noise3d.Height, noise3d.Depth, 32, 4, 32);       // must be a multiple of localgroupsize in csn

            csn.StartAction += (A, m) => { noise3d.BindImage(3); };
            items.Add(csn, "CE1");
            GLComputeShaderList p = new GLComputeShaderList();      // demonstrate a render list holding a compute shader.

            p.Add(csn);
            p.Run();        // run the shader to compute into the noise3d block the noise.
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(180f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 50.0f);
            };

            glwfc.MouseDown += mousedown;

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // def binding of 0

            if (true)
            {
                GLRenderState lines = GLRenderState.Lines(1);

                items.Add(new GLColorShaderWorld(), "COSW");

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(-100, 0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green })
                             );


                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 0, -100), new Vector3(100, 0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green }));
            }

            var vert   = new GLPLVertexShaderModelCoordWorldAutoscale();
            var frag   = new GLPLFragmentShaderFixedColor(Color.Yellow);
            var shader = new GLShaderPipeline(vert, frag);

            items.Add(shader, "TRI");

            var triangles = new Vector4[] { new Vector4(0, 0, 0, 1), new Vector4(10, 0, 0, 1), new Vector4(10, 0, 10, 1),
                                            new Vector4(-20, 0, 0, 1), new Vector4(-10, 0, 0, 1), new Vector4(-10, 0, 10, 1) };

            var worldpos = new Vector4[] { new Vector4(0, 0, 0, 0), new Vector4(0, 0, 12, 0) };

            GLRenderState rc = GLRenderState.Tri();

            rObjects.Add(items.Shader("TRI"), "scopen", GLRenderableItem.CreateVector4Vector4Buf2(items, PrimitiveType.Triangles, rc, triangles, worldpos, ic: 2, seconddivisor: 1));

            // demo shared find block, a problem in the past with the previous interface

            GLStorageBlock findblock = new GLStorageBlock(11);

            findshader1 = items.NewShaderPipeline("FS", new GLPLVertexShaderModelCoordWorldAutoscale(), null, null, new GLPLGeoShaderFindTriangles(findblock, 16), null, null, null);
            findrender1 = GLRenderableItem.CreateVector4Vector4Buf2(items, PrimitiveType.Triangles, GLRenderState.Tri(), triangles, worldpos, ic: 2, seconddivisor: 1);

            findshader2 = items.NewShaderPipeline("FS2", new GLPLVertexShaderModelCoordWorldAutoscale(), null, null, new GLPLGeoShaderFindTriangles(findblock, 16), null, null, null);
            findrender2 = GLRenderableItem.CreateVector4Vector4Buf2(items, PrimitiveType.Triangles, GLRenderState.Tri(), triangles, worldpos, ic: 2, seconddivisor: 1);

            Closed += ShaderTest_Closed;
        }
        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;

            if (true)
            {
                pform = new GLForm("Form1", "GL Form demonstration", new Rectangle(0, 0, 1000, 800));
                //pform.BackColor = Color.FromArgb(200, Color.Red);
                //pform.Opacity = 0.7f;
                // pform.BackColorGradientDir = 90;
                //  pform.BackColorGradientAlt = Color.FromArgb(200, Color.Yellow);
                //pform.ScaleWindow = new SizeF(0.75f, 0.75f);
                //pform.AlternatePos = new RectangleF(100, 100, 500, 400);
                //pform.AlternatePos = new RectangleF(100, 100, 1200, 1000);
                //  pform.ScaleWindow = new SizeF(0.0f, 0.0f);
                //   pform.Animators.Add(new AnimateScale(100, 1000, true, new SizeF(1, 1),removeafterend:true));
                //  pform.Animators.Add(new AnimateTranslate(glwfc.ElapsedTimems + 100, glwfc.ElapsedTimems + 1000, false, new Point(100, 100), removeafterend: true));
                //  pform.Animators.Add(new AnimateOpacity(glwfc.ElapsedTimems + 100, glwfc.ElapsedTimems + 2000, false, 1.0f,0.0f, removeafterend: true));

                int taborder = 0;

                if (true)
                {
                    GLLabel lab1 = new GLLabel("Lab1", new Rectangle(400, 0, 0, 0), "From Check");
                    pform.Add(lab1);

                    GLButton b1 = new GLButton("B1", new Rectangle(5, 10, 80, 30), "Configuration Dialog");
                    b1.Margin      = new MarginType(2);
                    b1.AutoSize    = true;
                    b1.TabOrder    = taborder++;
                    b1.Padding     = new PaddingType(5);
                    b1.Click      += (c, ev) => { ConfDialog(); };
                    b1.ToolTipText = "Button 1 tip\r\nLine 2 of it";
                    pform.Add(b1);

                    GLButton b2 = new GLButton("B2", new Rectangle(5, 50, 0, 0), "Msg1");
                    b2.Image       = Properties.Resources.ImportSphere;
                    b2.TabOrder    = taborder++;
                    b2.ImageAlign  = ContentAlignment.MiddleLeft;
                    b2.TextAlign   = ContentAlignment.MiddleRight;
                    b2.Click      += (c, ev) => { MsgDialog1(); };
                    b2.ToolTipText = "Button 2 tip\r\nLine 2 of it";
                    pform.Add(b2);

                    GLButton b3 = new GLButton("B3", new Rectangle(100, 10, 80, 30), "Font");
                    b3.Margin      = new MarginType(2);
                    b3.TabOrder    = taborder++;
                    b3.Padding     = new PaddingType(5);
                    b3.ToolTipText = "Button 3 tip\r\nLine 2 of it";
                    b3.Click      += (c, ev) => {
                        displaycontrol.Font = new Font("Times", 12);
                    };
                    pform.Add(b3);

                    GLButton b4 = new GLButton("B4", new Rectangle(100, 50, 80, 30), "Msg2");
                    b4.TabOrder    = taborder++;
                    b4.Padding     = new PaddingType(2);
                    b4.ToolTipText = "Button 4 tip\r\nLine 2 of it";
                    b4.Click      += (c, ev) => { MsgDialog2(); };
                    pform.Add(b4);

                    GLButton b5 = new GLButton("B5", new Rectangle(200, 10, 80, 30), "Conf2");
                    b5.TabOrder    = taborder++;
                    b5.Padding     = new PaddingType(2);
                    b5.ToolTipText = "Button 5 tip\r\nLine 2 of it";
                    b5.Click      += (c, ev) => { ConfDialog2(); };
                    pform.Add(b5);

                    GLButton b6 = new GLButton("B3", new Rectangle(200, 50, 80, 30), "Disabled");
                    b6.TabOrder    = taborder++;
                    b6.ToolTipText = "Button 6 tip\r\nLine 2 of it";
                    b6.Enabled     = false;
                    pform.Add(b6);
                }

                if (true)
                {
                    GLComboBox cb1 = new GLComboBox("CB", new Rectangle(0, 100, 0, 0), new List <string>()
                    {
                        "one", "two", "three"
                    });
                    cb1.Margin      = new MarginType(16, 8, 16, 8);
                    cb1.TabOrder    = taborder++;
                    cb1.ToolTipText = "Combo Box";
                    pform.Add(cb1);

                    GLComboBox cbstars = new GLComboBox("GalaxyStarsNumber", new Rectangle(100, 100, 100, 32));
                    cbstars.ToolTipText = "Control how many stars are shown when zoomes in";
                    cbstars.Items       = new List <string>()
                    {
                        "Ultra", "High", "Medium", "Low"
                    };
                    cbstars.TabOrder = taborder++;
                    var list = new List <int>()
                    {
                        1000000, 500000, 250000, 100000
                    };
                    int itemno = 1;
                    cbstars.SelectedIndex = itemno >= 0 ? itemno : 1;       // high default
                    pform.Add(cbstars);
                }

                if (true)
                {
                    GLCheckBox chk1 = new GLCheckBox("Checkbox1", new Rectangle(0, 150, 0, 0), "Normal");
                    chk1.Margin   = new MarginType(16, 0, 0, 0);
                    chk1.TabOrder = taborder++;
                    pform.Add(chk1);
                    GLCheckBox chk2 = new GLCheckBox("Checkbox2", new Rectangle(100, 150, 0, 0), "Radio");
                    chk2.Appearance = GLCheckBox.CheckBoxAppearance.Radio;
                    chk2.TabOrder   = taborder++;
                    chk2.Checked    = true;
                    pform.Add(chk2);
                    GLCheckBox chk3 = new GLCheckBox("Checkbox3", new Rectangle(200, 150, 0, 0), "Button");
                    chk3.Appearance = GLCheckBox.CheckBoxAppearance.Button;
                    chk3.TabOrder   = taborder++;
                    chk3.BackColor  = Color.FromArgb(200, 200, 200);
                    pform.Add(chk3);
                    GLCheckBox chk4 = new GLCheckBox("Checkbox4", new Rectangle(300, 150, 0, 0), "");
                    chk4.TabOrder = taborder++;
                    pform.Add(chk4);
                    GLCheckBox chk5 = new GLCheckBox("Checkbox5", new Rectangle(350, 150, 0, 0), "R1");
                    chk5.Appearance       = GLCheckBox.CheckBoxAppearance.Radio;
                    chk5.GroupRadioButton = true;
                    chk5.TabOrder         = taborder++;
                    pform.Add(chk5);
                    GLCheckBox chk6 = new GLCheckBox("Checkbox6", new Rectangle(400, 150, 0, 0), "R2");
                    chk6.Appearance       = GLCheckBox.CheckBoxAppearance.Radio;
                    chk6.GroupRadioButton = true;
                    chk6.TabOrder         = taborder++;
                    pform.Add(chk6);
                    GLCheckBox chk7 = new GLCheckBox("Checkbox7", new Rectangle(0, 175, 0, 0), "Disabled");
                    chk7.TabOrder = taborder++;
                    chk7.Enabled  = false;
                    pform.Add(chk7);
                    GLCheckBox chk8 = new GLCheckBox("Checkbox8", new Rectangle(100, 175, 0, 0), "Disabled");
                    chk8.Appearance = GLCheckBox.CheckBoxAppearance.Radio;
                    chk8.TabOrder   = taborder++;
                    chk8.Enabled    = false;
                    pform.Add(chk8);
                    GLCheckBox chk9 = new GLCheckBox("Checkbox9", new Rectangle(200, 175, 0, 0), "CDisabled");
                    chk9.TabOrder = taborder++;
                    chk9.Enabled  = false;
                    chk9.Checked  = true;
                    pform.Add(chk9);
                    GLCheckBox chk10 = new GLCheckBox("Checkbox10", new Rectangle(300, 175, 0, 0), "CDisabled");
                    chk10.Appearance = GLCheckBox.CheckBoxAppearance.Radio;
                    chk10.TabOrder   = taborder++;
                    chk10.Enabled    = false;
                    chk10.Checked    = true;
                    pform.Add(chk10);
                }

                if (true)
                {
                    GLDateTimePicker dtp = new GLDateTimePicker("DTP", new Rectangle(0, 210, 500, 30), DateTime.Now);
                    dtp.Culture = System.Globalization.CultureInfo.GetCultureInfo("de-AT");
                    dtp.Format  = GLDateTimePicker.DateTimePickerFormat.Long;
                    //dtp.CustomFormat = "'start' dddd 'hello there' MMMM' and here 'yyyy";
                    dtp.Font         = new Font("Ms Sans Serif", 11);
                    dtp.ShowCheckBox = true;
                    dtp.ShowCalendar = true;
                    dtp.ShowUpDown   = true;
                    dtp.AutoSize     = true;
                    //dtp.Culture = CultureInfo.GetCultureInfo("es");
                    dtp.TabOrder = taborder++;
                    pform.Add(dtp);
                }

                if (true)
                {
                    List <string> i1 = new List <string>()
                    {
                        "one two three four five six seven eight", "two", "three", "four", "five", "six", "seven is very long too to check", "eight", "nine", "ten", "eleven", "twelve"
                    };
                    GLListBox lb1 = new GLListBox("LB1", new Rectangle(0, 260, 260, 100), i1);
                    lb1.Font         = new Font("Microsoft Sans Serif", 12f);
                    lb1.TabOrder     = taborder++;
                    lb1.ShowFocusBox = true;
                    lb1.ScrollBarTheme.SliderColor      = Color.AliceBlue;
                    lb1.ScrollBarTheme.ThumbButtonColor = Color.Blue;
                    //lb1.FitToItemsHeight = false;
                    pform.Add(lb1);
                    lb1.SelectedIndexChanged += (s, si) => { System.Diagnostics.Debug.WriteLine("Selected index " + si); };
                }

                if (true)
                {
                    GLUpDownControl upc1 = new GLUpDownControl("UPC1", new Rectangle(0, 600, 26, 46));
                    upc1.TabOrder = taborder++;
                    pform.Add(upc1);
                    upc1.Clicked += (s, upe) => System.Diagnostics.Debug.WriteLine("Up down control {0} {1}", s.Name, upe);
                }

                if (true)
                {
                    GLCalendar cal = new GLCalendar("Cal", new Rectangle(500, 10, 300, 200));
                    cal.TabOrder = taborder++;
                    //cal.Culture = CultureInfo.GetCultureInfo("es");
                    cal.AutoSize = true;
                    cal.Font     = new Font("Arial", 10);
                    pform.Add(cal);
                }

                if (true)
                {
                    GLNumberBoxFloat glf = new GLNumberBoxFloat("FLOAT", new Rectangle(500, 250, 100, 25), 23.4f);
                    glf.BackColor        = Color.AliceBlue;
                    glf.TabOrder         = taborder++;
                    glf.Font             = new Font("Ms Sans Serif", 12);
                    glf.Minimum          = -1000;
                    glf.Maximum          = 1000;
                    glf.ValueChanged    += (a) => { System.Diagnostics.Debug.WriteLine("GLF value changed"); };
                    glf.ValidityChanged += (a, b) => { System.Diagnostics.Debug.WriteLine($"GLF validity changed {b}"); };
                    pform.Add(glf);

                    GLButton glfbut = new GLButton("FLOATBUT", new Rectangle(610, 250, 40, 15), "Value");
                    glfbut.Click += (e1, b1) => { glf.Value = 20.22f; };
                    pform.Add(glfbut);

                    GLTextBoxAutoComplete gla = new GLTextBoxAutoComplete("ACTB", new Rectangle(500, 300, 100, 25));
                    gla.TabOrder = taborder++;
                    gla.Font     = new Font("Ms Sans Serif", 12);
                    gla.PerformAutoCompleteInThread += (s, a, set) =>
                    {
                        var r = new List <string>()
                        {
                            "one", "two", "three"
                        };
                        foreach (var x in r)
                        {
                            if (x.StartsWith(s) || s.IsEmpty())
                            {
                                set.Add(x);
                            }
                        }
                    };
                    gla.SelectedEntry += (s) => { System.Diagnostics.Debug.WriteLine($"Autocomplete selected {s.Text}"); };
                    pform.Add(gla);
                }

                if (true)
                {
                    GLButton b1 = new GLButton("BD1", new Rectangle(5, 10, 80, 30), "Bottom 1");
                    b1.TabOrder = taborder++;
                    b1.Dock     = DockingType.Bottom;
                    displaycontrol.Add(b1);
                    GLButton b2 = new GLButton("BD2", new Rectangle(5, 10, 80, 30), "Bottom 2");
                    b2.TabOrder = taborder++;
                    b2.Dock     = DockingType.Bottom;
                    displaycontrol.Add(b2);
                }

                displaycontrol.Add(pform);
            }

            if (true)
            {
                GLForm pform2 = new GLForm("Form2", "Form 2 GL Control demonstration", new Rectangle(1100, 0, 400, 400));
                pform2.BackColor            = Color.FromArgb(200, Color.Red);
                pform2.Font                 = new Font("Ms sans serif", 10);
                pform2.BackColorGradientDir = 90;
                pform2.BackColorGradientAlt = Color.FromArgb(200, Color.Blue);
                displaycontrol.Add(pform2);

                GLButton b1 = new GLButton("*********** F2B1", new Rectangle(5, 10, 80, 30), "F2B1");
                pform2.Add(b1);
            }

            if (true)
            {
                GLToolTip tip = new GLToolTip("ToolTip");
                displaycontrol.Add(tip);
            }

            displaycontrol.GlobalMouseDown += (ctrl, ex) =>
            {
                if (ctrl == null || !pform.IsThisOrChildOf(ctrl))
                {
                    //  System.Diagnostics.Debug.WriteLine("Not on form");
                }
                else
                {
                    //  System.Diagnostics.Debug.WriteLine("Click on form");
                }
            };



            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();
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.ZoomDistance = 100F;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            glwfc.BackColor = Color.FromArgb(0, 0, 20);
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(120f, 0, 0f), 1F);
            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 20.0f);
            };

            // this bit is eye candy just to show its working

            items.Add(new GLColorShaderWorld(), "COSW");
            GLRenderState rl = GLRenderState.Lines(1);

            rObjects.Add(items.Shader("COSW"),
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                              GLShapeObjectFactory.CreateLines(new Vector3(-40, 0, -40), new Vector3(-40, 0, 40), new Vector3(10, 0, 0), 9),
                                                              new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green })
                         );


            rObjects.Add(items.Shader("COSW"),
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                              GLShapeObjectFactory.CreateLines(new Vector3(-40, 0, -40), new Vector3(40, 0, -40), new Vector3(0, 0, 10), 9),
                                                              new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green })
                         );


            items.Add(new GLTexture2D(Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8), "moon");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEX");

            GLRenderState rt = GLRenderState.Tri();

            rObjects.Add(items.Shader("TEX"), "sphere7",
                         GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Triangles, rt,
                                                               GLSphereObjectFactory.CreateTexturedSphereFromTriangles(4, 20.0f),
                                                               new GLRenderDataTranslationRotationTexture(items.Tex("moon"), new Vector3(0, 0, 0))
                                                               ));


            // Pass vertex data thru a vertex shader which stores into a block

            items.Add(new GLShaderPipeline(new GLVertexShaderCompute()), "N1");

            vecoutbuffer = new GLStorageBlock(1);                                                                                // new storage block on binding index 1 which the vertex shader uses
            vecoutbuffer.AllocateBytes(sizeof(float) * 2048 + sizeof(int), OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicCopy); // set size of vec buffer

            //Vector4[] data = new Vector4[] {
            //    new Vector4(1, 2, 3, 0),
            //    new Vector4(4, 5, 6, 0)
            //};

            Vector4[] data = GLSphereObjectFactory.CreateSphereFromTriangles(0, 1.0f);

            GLRenderState rp = GLRenderState.Points();

            rObjects.Add(items.Shader("N1"), GLRenderableItem.CreateVector4(items, PrimitiveType.Points, rp, data));

            for (double ang = -Math.PI / 2; ang <= Math.PI / 2 + 0.1; ang += 0.1)
            {
                Vector3 pos         = new Vector3((float)Math.Cos(ang), (float)Math.Sin(ang), 0);
                Vector3 up          = new Vector3(0, 1, 0);
                float   dotp        = Vector3.Dot(up, pos);
                float   lens        = (float)(up.Length * pos.Length);
                double  computedang = Math.Acos(dotp / lens);
                System.Diagnostics.Debug.WriteLine(ang.Degrees() + " " + pos + "-> dotp" + dotp + " " + computedang.Degrees());
            }

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // def binding of 0
        }
        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;
        }
Exemple #21
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;


            matrixcalc = new GLMatrixCalc();
            matrixcalc.PerspectiveNearZDistance = 1f;
            matrixcalc.PerspectiveFarZDistance  = worldsize * 2;
            matrixcalc.InPerspectiveMode        = true;
            matrixcalc.ResizeViewPort(this, glwfc.Size);

            displaycontrol           = new GLControlDisplay(items, glwfc, matrixcalc); // 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.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
                displaycontrol.Render(glwfc.RenderState, ts);
            };


            double  startspeed = 60 * 60 * 6; // in sec
            GLImage minus      = new GLImage("plus", new Rectangle(0, 0, 32, 32), Properties.Resources.GoBackward);

            minus.MouseClick += (e1, m1) => { currentjd -= 365; };
            displaycontrol.Add(minus);
            GLImage back = new GLImage("back", 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("back", new Rectangle(80, 0, 32, 32), Properties.Resources.Pause);

            pause.MouseClick += (e1, m1) => { jdscaling = 0; };
            displaycontrol.Add(pause);
            GLImage fwd = new GLImage("fwd", 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("plus", new Rectangle(160, 0, 32, 32), Properties.Resources.GoForward);

            plus.MouseClick += (e1, m1) => { currentjd += 365; };
            displaycontrol.Add(plus);
            status = new GLLabel("state", new Rectangle(200, 0, 400, 20), "Label", Color.DarkOrange);
            displaycontrol.Add(status);
            datalabel           = new GLLabel("datalabel", new Rectangle(0, 40, 400, 100), "", Color.DarkOrange);
            datalabel.TextAlign = ContentAlignment.TopLeft;
            displaycontrol.Add(datalabel);


            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.ZoomDistance = 3000F;
            gl3dcontroller.Start(matrixcalc, displaycontrol, new Vector3(0, 0, 0), new Vector3(135f, 0, 0f), 0.025F);
            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms * 100.0f);
            };

            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLTexturedShaderObjectCommonTranslation(), "TEXOCT");

            items.Add(new GLTexture2D(Properties.Resources.golden, SizedInternalFormat.Rgba8), "golden");
            items.Add(new GLTexture2D(Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8), "moon");

            #region coloured lines

            int gridsize = (int)(worldsize * mscaling);
            int markers  = gridsize / 20;

            {
                GLRenderState lines = GLRenderState.Lines(1);

                Color gridcolour = Color.FromArgb(255, 60, 60, 60);
                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-gridsize, -0, -gridsize), new Vector3(-gridsize, -0, gridsize), new Vector3(markers, 0, 0), gridsize / markers * 2 + 1),
                                                                  new Color4[] { gridcolour })
                             );


                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-gridsize, -0, -gridsize), new Vector3(gridsize, -0, -gridsize), new Vector3(0, 0, markers), gridsize / markers * 2 + 1),
                                                                  new Color4[] { gridcolour }));
            }

            rObjects.Add(new GLOperationClearDepthBuffer());

            {
                GLRenderState rt = GLRenderState.Tri();

                float sunscaled = sunradiusm * mscaling * sunscaleup;
                rObjects.Add(items.Shader("TEXOCT"), "sun",
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Triangles, rt,
                                                                   GLSphereObjectFactory.CreateTexturedSphereFromTriangles(3, sunscaled),
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("golden"), new Vector3(0, 0, 0))
                                                                   ));
            }


            #endregion

            {   // debug check
                DateTime t  = new DateTime(2000, 1, 1, 12, 0, 0);
                double   jd = t.ToJulianDate();
                DateTime t2 = jd.JulianToDateTime();
                System.Diagnostics.Debug.WriteLine($"Date time {t} JD {jd} back to {t2}");
            }


            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // create a matrix uniform block

            currentjd     = KeplerOrbitElements.J2000;
            jdscaling     = 0;
            bodies        = new KeplerOrbitElements[4];
            bodypositions = new GLRenderDataTranslationRotationTexture[4];

            // earth
            bodies[0] = new KeplerOrbitElements(true, semimajoraxiskm: 0.38709893 * AU,  // https://nssdc.gsfc.nasa.gov/planetary/factsheet/mercuryfact.html
                                                eccentricity: 0.20563069,
                                                inclination: 7.00487,
                                                longitudeofascendingnode: 48.33167,
                                                longitudeofperihelion: 77.45645,
                                                meanlongitude: 252.25084,
                                                currentjd);
            bodies[1] = new KeplerOrbitElements(true, semimajoraxiskm: 0.72333199 * AU,  // https://nssdc.gsfc.nasa.gov/planetary/factsheet/venusfact.html
                                                eccentricity: 0.00677323,
                                                inclination: 3.39471,
                                                longitudeofascendingnode: 76.68069,
                                                longitudeofperihelion: 131.53298,
                                                meanlongitude: 181.97973,
                                                currentjd);
            bodies[2] = new KeplerOrbitElements(true, semimajoraxiskm: 1.49596E+08,  // https://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
                                                eccentricity: 0.0167086,
                                                inclination: 0.00005,
                                                longitudeofascendingnode: -11.26064,
                                                longitudeofperihelion: 102.94719,
                                                meanlongitude: 100.46435,
                                                currentjd);
            bodies[3] = new KeplerOrbitElements(true, semimajoraxiskm: 1.52366231 * AU,  // https://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html
                                                eccentricity: 0.09341233,
                                                inclination: 1.85061,
                                                longitudeofascendingnode: 49.57854,
                                                longitudeofperihelion: 336.04084,
                                                meanlongitude: 355.45332,
                                                currentjd);

            float planetsize = earthradiusm * mscaling * planetscaleup;

            for (int i = 0; i < bodies.Length; i++)
            {
                bodies[i].CentralMass = Msol;

                System.Diagnostics.Debug.WriteLine($"{i} {bodies[i].OrbitalPeriodS/60/60/24} {bodies[i].CalculateMass(bodies[i].OrbitalPeriodS)}");

                bodypositions[i] = new GLRenderDataTranslationRotationTexture(items.Tex("moon"), new Vector3(0, 0, 0));

                GLRenderState rt = GLRenderState.Tri();
                rObjects.Add(items.Shader("TEXOCT"), "Body" + i,
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Triangles, rt,
                                                                   GLSphereObjectFactory.CreateTexturedSphereFromTriangles(3, planetsize), bodypositions[i]));

                Vector4[] orbit = bodies[i].Orbit(currentjd, 1, mscaling);

                GLRenderState lines = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.LineStrip, lines, orbit, new Color4[] { Color.FromArgb(255, 128, 0, 0) }));
            }

            systemtimer.Interval = 25;
            systemtimer.Tick    += new EventHandler(SystemTick);
            systemtimer.Start();
        }
Exemple #22
0
        public void CreateObjects(GLItemsList items, GLRenderProgramSortedList rObjects, GalacticMapping galmap, GLStorageBlock findbufferresults, bool depthtest)
        {
            this.galmap = galmap;

            // first gets the images and make a 2d array texture for them

            Bitmap[] images = galmap.RenderableMapTypes.Select(x => x.Image as Bitmap).ToArray();
            // 256 is defined normal size
            var        objtex   = new GLTexture2DArray(images, bmpmipmaplevels: 1, wantedmipmaplevels: 3, texturesize: new Size(256, 256), internalformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, alignment: ContentAlignment.BottomCenter);
            IGLTexture texarray = items.Add(objtex, "GalObjTex");

            // now build the shaders

            const int texbindingpoint = 1;
            var       vert            = new GLPLVertexScaleLookat(rotatetoviewer: dorotate, rotateelevation: doelevation, // a look at vertex shader
                                                                  autoscale: 500, autoscalemin: 1f, autoscalemax: 20f);   // below 500, 1f, above 500, scale up to 20x
            var tcs = new GLPLTesselationControl(40f);

            tes = new GLPLTesselationEvaluateSinewave(1f, 2f);                  // this uses the world position from the vertex scaler to position the image, w controls image + animation (b16)
            var frag = new GLPLFragmentShaderTexture2DDiscard(texbindingpoint); // binding - takes image pos from tes. imagepos < 0 means discard

            objectshader = new GLShaderPipeline(vert, tcs, tes, null, frag);
            items.Add(objectshader);

            objectshader.StartAction += (s, m) =>
            {
                texarray.Bind(texbindingpoint);   // bind tex array to, matching above
            };

            // now the RenderControl for the objects

            GLRenderState rt = GLRenderState.Patches(4);

            rt.DepthTest = depthtest;

            // create a quad and all entries of the renderable map objects, zero at this point, with a zero instance count. UpdateEnables will fill it in later
            // but we need to give it the maximum buffer length at this point

            const float objsize = 10.0f;        // size of object on screen

            ridisplay = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, rt,
                                                              GLShapeObjectFactory.CreateQuadTriStrip(objsize, objsize), // quad2 4 vertexts
                                                              new Vector4[galmap.RenderableMapObjects.Length],           // world positions
                                                              ic: 0, seconddivisor: 1);

            modelworldbuffer = items.LastBuffer();
            int modelpos = modelworldbuffer.Positions[0];

            worldpos = modelworldbuffer.Positions[1];

            rObjects.Add(objectshader, "galmapobj", ridisplay);

            // add a find shader to look them up

            var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);

            findshader = items.NewShaderPipeline(null, vert, tcs, tes, geofind, null, null, null);


            // hook to modelworldbuffer, at modelpos and worldpos.  UpdateEnables will fill in instance count
            rifind = GLRenderableItem.CreateVector4Vector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Patches, GLRenderState.Patches(4), modelworldbuffer, modelpos, ridisplay.DrawCount,
                                                           modelworldbuffer, worldpos, null, ic: 0, seconddivisor: 1);

            GLStatics.Check();

            // Text renderer for the labels

            textrenderer = new GLBitmaps("bm-galmapobjects", rObjects, new Size(128, 40), depthtest: depthtest, cullface: false, textureformat: OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8);
            items.Add(textrenderer);

            // now make the text up for all the objects above

            using (Font fnt = new Font("Arial", 8.5F))
            {
                using (StringFormat fmt = new StringFormat())
                {
                    fmt.Alignment = StringAlignment.Center;

                    var renderablegalmapobjects = galmap.RenderableMapObjects; // list of enabled entries

                    List <Vector3> posset = new List <Vector3>();

                    float offscale = objsize * (0.5f + (float)textrenderer.BitmapSize.Height / (float)textrenderer.BitmapSize.Width / 2);       // this is the nominal centre of the text bitmap, offset in Y to the object

                    for (int i = 0; i < renderablegalmapobjects.Length; i++)
                    {
                        var   o      = renderablegalmapobjects[i];
                        float offset = -offscale;

                        for (int j = 0; j < i; j++)     // look up previous ones and see if we labeled it before
                        {
                            var d1   = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                            var d2   = posset[j];   // where it was placed.
                            var diff = d1 - d2;

                            if (diff.Length < offscale) // close
                            {
                                if (offset > 0)         // if offset is positive, flip below and increase again
                                {
                                    offset = -offset - offscale;
                                }
                                else
                                {
                                    offset *= -1;       // flip over top
                                }
                                // System.Diagnostics.Debug.WriteLine($"close {renderablegalmapobjects[i].name} {d1} to {renderablegalmapobjects[j].name} {d2} {diff} select {offset}");
                            }
                        }

                        Vector3 pos = new Vector3(o.points[0].X, o.points[0].Y + offset, o.points[0].Z);
                        posset.Add(pos);
                        //System.Diagnostics.Debug.WriteLine($"{renderablegalmapobjects[i].name} at {pos} {offset}");

                        textrenderer.Add(o.id, o.name, fnt,
                                         Color.White, Color.FromArgb(0, 255, 0, 255),
                                         pos,
                                         new Vector3(objsize, 0, 0), new Vector3(0, 0, 0), textformat: fmt, rotatetoviewer: dorotate, rotateelevation: doelevation,
                                         alphafadescalar: -100, alphafadepos: 500); // fade in, alpha = 0 at >500, 1 at 400
                    }
                }
            }

            UpdateEnables();      // fill in worldpos's and update instance count, taking into
        }
Exemple #23
0
        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);
        }
Exemple #24
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f;
            gl3dcontroller.MatrixCalc.PerspectiveFarZDistance  = 1000f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(110f, 0, 0f), 1F);
            glwfc.MouseClick += GLMouseClick;

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 40.0f);
            };

            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLColorShaderObjectTranslation(), "COSOT");

            #region coloured lines

            if (true)
            {
                GLRenderState lines = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(-100, -0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed })
                             );


                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(100, -0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed }));
            }

            #endregion

            #region Coloured triangles
            if (true)
            {
                GLRenderState rc = GLRenderState.Tri();
                rc.CullFace = false;

                rObjects.Add(items.Shader("COSOT"), "scopen",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                                  new Color4[] { Color4.Red, Color4.Green, Color4.Blue, Color4.White, Color4.Cyan, Color4.Orange },
                                                                  new GLRenderDataTranslationRotation(new Vector3(10, 0, 20))
                                                                  ));
            }

            #endregion

            var sunvertex = new GLPLVertexShaderModelCoordWorldAutoscale(new Color[] { Color.FromArgb(255, 220, 220, 10), Color.FromArgb(255, 0, 0, 0) });
            items.Add(sunvertex);
            var sunshader = new GLShaderPipeline(sunvertex, new GLPLStarSurfaceFragmentShader());
            items.Add(sunshader);
            var shapebuf = new GLBuffer();
            items.Add(shapebuf);
            var shape = GLSphereObjectFactory.CreateSphereFromTriangles(1, 0.5f);
            shapebuf.AllocateFill(shape);

            GLStorageBlock block = new GLStorageBlock(20);
            findshader = items.NewShaderPipeline(null, sunvertex, null, null, new GLPLGeoShaderFindTriangles(block, 16), null, null, null);

            int texunitspergroup = 16;      // opengl minimum texture units per frag shader

            //var textshader = new GLShaderPipeline(new GLPLVertexShaderQuadTextureWithMatrixTranslation(), new GLPLFragmentShaderTexture2DIndexedMulti(0,0,true, texunitspergroup));
            var textshader = new TextShader(texunitspergroup);
            items.Add(textshader);
            Font fnt = new Font("MS sans serif", 16f);

            if (true)
            {
                int maxstars = 1000;    // this is an aspriation, depends on fragmentation of the system

                dataindirectbuffer = new GLVertexBufferIndirect(items, maxstars * (GLBuffer.Vec4size + GLBuffer.Mat4size), GLBuffer.WriteIndirectArrayStride * 100, true);
                var textarray = new GLTexture2DArray(128, 32, maxstars, SizedInternalFormat.Rgba8);

                int SectorSize = 10;

                {
                    Vector3   pos   = new Vector3(-20, 0, -15);
                    Vector4[] array = new Vector4[10];
                    Random    rnd   = new Random(23);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                    }
                    dataindirectbuffer.Fill(array, 0, array.Length, 0, shape.Length, 0, array.Length, -1);

                    Matrix4[] matrix = new Matrix4[array.Length];
                    for (int i = 0; i < array.Length; i++)
                    {
                        int imgpos = textarray.DepthIndex;
                        textarray.DrawText("A" + i, fnt, Color.White, Color.Blue, -1);
                        var mat = GLPLVertexShaderMatrixQuadTexture.CreateMatrix(new Vector3(array[i].X, array[i].Y + 0.6f, array[i].Z),
                                                                                 new Vector3(1, 0, 0.2f),
                                                                                 new Vector3(-90F.Radians(), 0, 0),
                                                                                 imagepos: imgpos);
                        matrix[i] = mat;
                    }

                    dataindirectbuffer.Vertex.AlignMat4();          // instancing counts in mat4 sizes (mat4 0 @0, mat4 1 @ 64 etc) so align to it
                    dataindirectbuffer.Fill(matrix, 0, matrix.Length, 1, 4, 0, array.Length, -1);
                }

                if (true)
                {
                    Vector3   pos   = new Vector3(-20, 0, 0);
                    Vector4[] array = new Vector4[5];
                    Random    rnd   = new Random(23);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                    }
                    dataindirectbuffer.Fill(array, 0, array.Length, 0, shape.Length, 0, array.Length, -1);
                }

                if (true)
                {
                    Vector3   pos   = new Vector3(-20, 0, 15);
                    Vector4[] array = new Vector4[10];
                    Random    rnd   = new Random(23);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                    }
                    dataindirectbuffer.Fill(array, 0, array.Length, 0, shape.Length, 0, array.Length, -1);

                    Matrix4[] matrix = new Matrix4[array.Length];
                    for (int i = 0; i < array.Length; i++)
                    {
                        int imgpos = textarray.DepthIndex;
                        textarray.DrawText("C" + i, fnt, Color.White, Color.Red, -1);
                        var mat = GLPLVertexShaderMatrixQuadTexture.CreateMatrix(new Vector3(array[i].X, array[i].Y + 0.6f, array[i].Z),
                                                                                 new Vector3(1, 0, 0.2f),
                                                                                 new Vector3(-90F.Radians(), 0, 0),
                                                                                 imagepos: imgpos);
                        matrix[i] = mat;
                    }

                    dataindirectbuffer.Vertex.AlignMat4();          // instancing countis in mat4 sizes (mat4 0 @0, mat4 1 @ 64 etc) so align to it
                    dataindirectbuffer.Fill(matrix, 0, matrix.Length, 1, 4, 0, array.Length, -1);
                }


                int[]   indirectints0 = dataindirectbuffer.Indirects[0].ReadInts(0, 12);
                int[]   indirectints1 = dataindirectbuffer.Indirects[1].ReadInts(0, 4);
                float[] worldpos      = dataindirectbuffer.Vertex.ReadFloats(0, 3 * 2 * 4);

                if (true)
                {
                    GLRenderState rt = GLRenderState.Tri();     // render is triangles, with no depth test so we always appear
                    rt.DepthTest  = true;
                    rt.DepthClamp = true;

                    var renderer = GLRenderableItem.CreateVector4Vector4(items, PrimitiveType.Triangles, rt,
                                                                         shapebuf, 0, 0,               // binding 0 is shapebuf, offset 0, no draw count
                                                                         dataindirectbuffer.Vertex, 0, // binding 1 is vertex's world positions, offset 0
                                                                         null, 0, 1);                  // no ic, second divisor 1
                    renderer.IndirectBuffer       = dataindirectbuffer.Indirects[0];
                    renderer.BaseIndexOffset      = 0;                                                 // offset in bytes where commands are stored
                    renderer.DrawCount            = 3;
                    renderer.MultiDrawCountStride = GLBuffer.WriteIndirectArrayStride;

                    rObjects.Add(sunshader, "sunshader", renderer);
                }

                if (true)
                {
                    var rc = GLRenderState.Quads();
                    rc.CullFace           = true;
                    rc.DepthTest          = true;
                    rc.ClipDistanceEnable = 1;  // we are going to cull primitives which are deleted

                    var renderer = GLRenderableItem.CreateMatrix4(items, PrimitiveType.Quads, rc,
                                                                  dataindirectbuffer.Vertex, 0, 0, //attach buffer with matrices, no draw count
                                                                  new GLRenderDataTexture(textarray, 0),
                                                                  0, 1);                           //no ic, and matrix divide so 1 matrix per vertex set
                    renderer.IndirectBuffer       = dataindirectbuffer.Indirects[1];
                    renderer.BaseIndexOffset      = 0;                                             // offset in bytes where commands are stored
                    renderer.DrawCount            = 2;
                    renderer.MultiDrawCountStride = GLBuffer.WriteIndirectArrayStride;

                    rObjects.Add(textshader, "textshader", renderer);
                }
            }

            if (true)
            {
                GLRenderState starrc = GLRenderState.Tri();     // render is triangles, with no depth test so we always appear
                starrc.DepthTest  = true;
                starrc.DepthClamp = true;

                var textrc = GLRenderState.Quads();
                textrc.DepthTest          = true;
                textrc.ClipDistanceEnable = 1;  // we are going to cull primitives which are deleted

                sl = new GLObjectsWithLabels();
                var ris = sl.Create(texunitspergroup, 50, 50, shapebuf, shape.Length, starrc, PrimitiveType.Triangles, new Size(128, 32), textrc, SizedInternalFormat.Rgba8, 3);
                rObjects.Add(sunshader, "SLsunshade", ris.Item1);
                rObjects.Add(textshader, "SLtextshade", ris.Item2);
                items.Add(sl);

                int SectorSize = 10;
                {
                    Vector3   pos   = new Vector3(0, 0, -15);
                    Vector4[] array = new Vector4[10];
                    string[]  text  = new string[array.Length];
                    Random    rnd   = new Random(31);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                        text[i]  = "A.r" + i;
                    }

                    var mats = GLPLVertexShaderMatrixQuadTexture.CreateMatrices(array, new Vector3(0, 0.6f, 0), new Vector3(2f, 0, 0.4f), new Vector3(-90F.Radians(), 0, 0), true, false);
                    var bmps = GLOFC.Utils.BitMapHelpers.DrawTextIntoFixedSizeBitmaps(sl.LabelSize, text, fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.White, Color.DarkBlue, 0.5f);

                    List <GLObjectsWithLabels.BlockRef> bref = new List <GLObjectsWithLabels.BlockRef>();
                    sl.Add(array, mats, bmps, bref);
                    GLOFC.Utils.BitMapHelpers.Dispose(bmps);
                }
                {
                    Vector3   pos   = new Vector3(0, 0, 0);
                    Vector4[] array = new Vector4[20];
                    string[]  text  = new string[array.Length];
                    Random    rnd   = new Random(31);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                        text[i]  = "B." + i;
                    }

                    List <GLObjectsWithLabels.BlockRef> bref = new List <GLObjectsWithLabels.BlockRef>();
                    sl.Add(array, text, fnt, Color.White, Color.DarkBlue, new Vector3(2f, 0, 0.4f), new Vector3(-90F.Radians(), 0, 0), true, false, null, 0.5f, new Vector3(0, 0.6f, 0), bref);
                }
                {
                    Vector3   pos   = new Vector3(0, 0, 15);
                    Vector4[] array = new Vector4[10];
                    string[]  text  = new string[array.Length];
                    Random    rnd   = new Random(31);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                        text[i]  = "C." + i;
                    }

                    List <GLObjectsWithLabels.BlockRef> bref = new List <GLObjectsWithLabels.BlockRef>();
                    sl.Add(array, text, fnt, Color.White, Color.DarkBlue, new Vector3(2f, 0, 0.4f), new Vector3(-90F.Radians(), 0, 0), true, false, null, 0.5f, new Vector3(0, 0.6f, 0), bref);
                }

                System.Diagnostics.Debug.WriteLine($"Sets {sl.Blocks} Removed {sl.BlocksRemoved}");
            }

            // Sets of..

            if (true)
            {
                GLRenderState starrc = GLRenderState.Tri();     // render is triangles, with no depth test so we always appear
                starrc.DepthTest  = true;
                starrc.DepthClamp = true;

                var textrc = GLRenderState.Quads();
                textrc.DepthTest          = true;
                textrc.ClipDistanceEnable = 1;  // we are going to cull primitives which are deleted

                slset = new GLSetOfObjectsWithLabels("SLSet", rObjects, true ? 4 : texunitspergroup,
                                                     50, 10,
                                                     sunshader, shapebuf, shape.Length, starrc, PrimitiveType.Triangles,
                                                     textshader, new Size(128, 32), textrc, SizedInternalFormat.Rgba8,
                                                     3);
                items.Add(slset);

                int SectorSize = 10;
                {
                    Vector3   pos   = new Vector3(20, 0, -15);
                    Vector4[] array = new Vector4[10];
                    string[]  text  = new string[array.Length];
                    Random    rnd   = new Random(31);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                        text[i]  = "S.A.r" + i;
                    }

                    var mats = GLPLVertexShaderMatrixQuadTexture.CreateMatrices(array, new Vector3(0, 0.6f, 0), new Vector3(2f, 0, 0.4f), new Vector3(-90F.Radians(), 0, 0), true, false);
                    var bmps = GLOFC.Utils.BitMapHelpers.DrawTextIntoFixedSizeBitmaps(slset.LabelSize, text, fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.White, Color.DarkBlue, 0.5f);

                    slset.Add("GA", text, array, mats, bmps);
                    GLOFC.Utils.BitMapHelpers.Dispose(bmps);
                }
                {
                    Vector3   pos   = new Vector3(20, 0, 0);
                    Vector4[] array = new Vector4[10];
                    string[]  text  = new string[array.Length];
                    Random    rnd   = new Random(31);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                        text[i]  = "S.B." + i;
                    }

                    var mats = GLPLVertexShaderMatrixQuadTexture.CreateMatrices(array, new Vector3(0, 0.6f, 0), new Vector3(2f, 0, 0.4f), new Vector3(-90F.Radians(), 0, 0), true, false);
                    var bmps = GLOFC.Utils.BitMapHelpers.DrawTextIntoFixedSizeBitmaps(slset.LabelSize, text, fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.White, Color.DarkBlue, 0.5f);

                    slset.Add("GB", text, array, mats, bmps);
                    GLOFC.Utils.BitMapHelpers.Dispose(bmps);
                }
                {
                    Vector3   pos   = new Vector3(20, 0, 15);
                    Vector4[] array = new Vector4[10];
                    string[]  text  = new string[array.Length];
                    Random    rnd   = new Random(31);
                    for (int i = 0; i < array.Length; i++)
                    {
                        array[i] = new Vector4(pos.X + rnd.Next(SectorSize), pos.Y + rnd.Next(SectorSize), pos.Z + rnd.Next(SectorSize), 0);
                        text[i]  = "S.C." + i;
                    }

                    var mats = GLPLVertexShaderMatrixQuadTexture.CreateMatrices(array, new Vector3(0, 0.6f, 0), new Vector3(2f, 0, 0.4f), new Vector3(-90F.Radians(), 0, 0), true, false);
                    var bmps = GLOFC.Utils.BitMapHelpers.DrawTextIntoFixedSizeBitmaps(slset.LabelSize, text, fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.White, Color.DarkBlue, 0.5f);

                    slset.Add("GC", text, array, mats, bmps);
                    GLOFC.Utils.BitMapHelpers.Dispose(bmps);
                }
            }

            #region Matrix Calc Uniform

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // def binding of 0

            #endregion
        }
        // Demonstrate buffer feedback AND geo shader add vertex/dump vertex

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.ZoomDistance = 100F;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 0.1f;
            glwfc.BackColor = Color.FromArgb(0, 0, 60);
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(120f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 20.0f);
            };

            IGLTexture array2d = items.Add(new GLTexture2DArray(new Bitmap[] { Properties.Resources.mipmap, Properties.Resources.mipmap2,
                                                                               Properties.Resources.mipmap3, Properties.Resources.mipmap4 }, SizedInternalFormat.Rgba8, 9), "2DArray2");

            if (true)
            {
                items.Add(new GLMultipleTexturedBlended(false, 2), "ShaderPos");
                items.Shader("ShaderPos").StartAction += (s, m) =>
                {
                    array2d.Bind(1);
                };

                Vector4[] instancepositions = new Vector4[4];
                instancepositions[0] = new Vector4(-25, 0, -40, 0);      // last is image index..
                instancepositions[1] = new Vector4(-25, 0, 0, 0);
                instancepositions[2] = new Vector4(-25, 0, 40, 2);
                instancepositions[3] = new Vector4(-25, 0, 80, 2);

                GLRenderState rt = GLRenderState.Tri(cullface: false);
                rObjects.Add(items.Shader("ShaderPos"),
                             GLRenderableItem.CreateVector4Vector2Vector4(items, PrimitiveType.Triangles, rt,
                                                                          GLSphereObjectFactory.CreateTexturedSphereFromTriangles(3, 20.0f),
                                                                          instancepositions, ic: 4, separbuf: true
                                                                          ));
            }

            // Shader MAT

            if (true)
            {
                IGLProgramShader smat = items.Add(new GLMultipleTexturedBlended(true, 2), "ShaderMat");
                smat.StartAction += (s, m) =>
                {
                    array2d.Bind(1);
                };

                Matrix4[] pos2 = new Matrix4[3];
                pos2[0]     = Matrix4.CreateRotationY(-80f.Radians());
                pos2[0]    *= Matrix4.CreateTranslation(new Vector3(25, 0, -40));
                pos2[0].M44 = 0;        // this is the image number

                pos2[1]     = Matrix4.CreateRotationY(-70f.Radians());
                pos2[1]    *= Matrix4.CreateTranslation(new Vector3(25, 0, 0));
                pos2[1].M44 = 2;        // this is the image number

                pos2[2]     = Matrix4.CreateRotationZ(-60f.Radians());
                pos2[2]    *= Matrix4.CreateTranslation(new Vector3(25, 0, 40));
                pos2[2].M44 = 0;        // this is the image number

                GLRenderState rq = GLRenderState.Quads(cullface: false);
                rObjects.Add(items.Shader("ShaderMat"),
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(20.0f, 20.0f, new Vector3(-90f.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                          pos2, ic: 3, separbuf: false
                                                                          ));
            }

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // def binding of 0
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            glwfc.EnsureCurrentContext();       // paranoid check

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f;
            gl3dcontroller.MatrixCalc.PerspectiveFarZDistance  = 1000f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(110f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 100.0f);
            };

            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLColorShaderObjectTranslation(), "COSOT");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOT");

            items.Add(new GLTexture2D(Properties.Resources.dotted, SizedInternalFormat.Rgba8), "dotted");
            items.Add(new GLTexture2D(Properties.Resources.dotted2, SizedInternalFormat.Rgba8), "dotted2");
            items.Add(new GLTexture2D(Properties.Resources.Logo8bpp, SizedInternalFormat.Rgba8), "logo8bpp");
            items.Add(new GLTexture2D(Properties.Resources.smile5300_256x256x8, SizedInternalFormat.Rgba8), "smile");

            #region coloured lines

            if (true)
            {
                GLRenderState lines = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(-100, -0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed })
                             );


                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(100, -0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed }));
            }

            #endregion

            #region Coloured triangles
            if (true)
            {
                GLRenderState rc = GLRenderState.Tri();
                rc.CullFace = false;

                rObjects.Add(items.Shader("COSOT"), "scopen",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                                  new Color4[] { Color4.Red, Color4.Green, Color4.Blue, Color4.White, Color4.Cyan, Color4.Orange },
                                                                  new GLRenderDataTranslationRotation(new Vector3(10, 3, 20))
                                                                  ));

                rObjects.Add(items.Shader("COSOT"), "scopen2",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                                  new Color4[] { Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red },
                                                                  new GLRenderDataTranslationRotation(new Vector3(-10, -3, -20))
                                                                  ));
            }

            #endregion
            #region textures
            if (true)
            {
                GLRenderState rq = GLRenderState.Quads();

                rObjects.Add(items.Shader("TEXOT"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(1.0f, 1.0f, new Vector3(-90f.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("dotted2"), new Vector3(0, 0, 0))
                                                                   ));
            }

            #endregion


            #region Matrix Calc Uniform

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // def binding of 0

            #endregion


            //new Thread(() => new Window2().ShowDialog()).Start();       // in another thread, it works

            frm = new Window2();
            frm.Show();
        }
Exemple #27
0
        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();
        }
Exemple #28
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            // operate matrixcalc in +Z away mode (default), in perspective mode (default)

            matrixcalc = new GLMatrixCalc();                                                   // must make after GL window is made
            matrixcalc.ResizeViewPort(this, glwfc.Size);                                       // inform matrix calc of window size
            matrixcalc.CalculateModelMatrix(new Vector3(0, 0, 0), new Vector2(135, 0), 50, 0); // set up the lookat position, the camera direction, the distance and rotation
            matrixcalc.CalculateProjectionMatrix();                                            // and set the project matrix

            glwfc.Paint += Draw;                                                               // register for draw

            // disposable items are stored in GLItemsList, so they can be cleanly disposed of at the end

            // make three stock shaders with names

            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLColorShaderObjectTranslation(), "COSOT");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOT");

            // make a texture from resources called dotted2

            items.Add(new GLTexture2D(Properties.Resources.dotted2, SizedInternalFormat.Rgba8), "dotted2");

            // render state for lines
            GLRenderState lines = GLRenderState.Lines(1);

            // make a set of vertices from the shape factory
            var rs1 = GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(-100, -0, 100), new Vector3(10, 0, 0), 21);

            // make a array of colours for the vertexes (note do not need a full set, the render creator will repeat them automatically)
            var rc1 = new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed };

            // make a render item, indicating type (Lines), vertexes (rs1) and colours (rc1)
            var ri1 = GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines, rs1, rc1);

            // add to render list - paint with this shader, and this render
            rObjects.Add(items.Shader("COSW"), ri1);

            // do more..

            rObjects.Add(items.Shader("COSW"),
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                              GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(100, -0, -100), new Vector3(0, 0, 10), 21),
                                                              new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed }));

            // render state for triangles

            GLRenderState rc = GLRenderState.Tri();

            rc.CullFace = false;

            rObjects.Add(items.Shader("COSOT"), "scopen",
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                              GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                              new Color4[] { Color4.Red, Color4.Green, Color4.Blue, Color4.White, Color4.Cyan, Color4.Orange },
                                                              new GLRenderDataTranslationRotation(new Vector3(-10, 0, -10))
                                                              ));

            rObjects.Add(items.Shader("COSOT"), "scopen2",
                         GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                              GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                              new Color4[] { Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red },
                                                              new GLRenderDataTranslationRotation(new Vector3(10, 0, 10))
                                                              ));

            // render state for quads

            GLRenderState rq = GLRenderState.Quads();

            rObjects.Add(items.Shader("TEXOT"),
                         GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                               GLShapeObjectFactory.CreateQuad(5.0f, 5.0f, new Vector3(0f.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                               new GLRenderDataTranslationRotationTexture(items.Tex("dotted2"), new Vector3(0, 0, 0))
                                                               ));

            // make a Uniformblock to hold matrix info

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // def binding of 0
        }
        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();
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f;
            gl3dcontroller.MatrixCalc.PerspectiveFarZDistance  = 21000f;
            gl3dcontroller.MouseTranslateAmountAtZoom1PerPixel = 0.5f;
            gl3dcontroller.ZoomDistance = 50F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(135f, 0, 0f), 1F);

            bool useopenglcoords = true;        // true for +Z towards viewer. OFC is using mostly +Z away from viewer

            if (useopenglcoords)
            {
                gl3dcontroller.MatrixCalc.ModelAxisPositiveZAwayFromViewer = false;
                gl3dcontroller.SetPositionCamera(new Vector3(0, 0, 0), new Vector3(0, 0, 100), 0f);
                gl3dcontroller.RecalcMatrices();
            }

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 100.0f);
            };

            // create stock shaders

            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLColorShaderObjectTranslation(), "COSOT");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOT");

            // create stock textures

            items.Add(new GLTexture2D(Properties.Resources.dotted, SizedInternalFormat.Rgba8), "dotted");
            items.Add(new GLTexture2D(Properties.Resources.dotted2, SizedInternalFormat.Rgba8), "dotted2");
            items.Add(new GLTexture2D(Properties.Resources.Logo8bpp, SizedInternalFormat.Rgba8), "logo8bpp");
            items.Add(new GLTexture2D(Properties.Resources.smile5300_256x256x8, SizedInternalFormat.Rgba8), "smile");

            #region coloured lines

            if (true)
            {
                GLRenderState lines = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(-100, -0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed })
                             );


                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(100, -0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Red, Color.Red, Color.DarkRed, Color.DarkRed }));
            }

            if (true)
            {
                GLRenderState lines = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 10, -100), new Vector3(-100, 10, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Yellow, Color.Orange, Color.Yellow, Color.Orange })
                             );

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 10, -100), new Vector3(100, 10, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Yellow, Color.Orange, Color.Yellow, Color.Orange })
                             );
            }

            #endregion

            #region Coloured cubes
            if (true)
            {
                GLRenderState rc = GLRenderState.Tri();
                rc.CullFace = false;

                var cube1pos = GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f, new Vector3(10, 2.5f, 10));
                var cube1dtr = new GLRenderDataTranslationRotation(new Vector3(0, 0, 0));

                // these are on positive Z and x

                rObjects.Add(items.Shader("COSOT"), "scopen",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  cube1pos,
                                                                  new Color4[] { Color4.Green, Color4.Green, Color4.Blue, Color4.Blue, Color4.Cyan, Color4.Cyan },
                                                                  cube1dtr

                                                                  ));

                var cube2pos = GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f, new Vector3(10, 2.5f, 50));
                rObjects.Add(items.Shader("COSOT"), "scopen1",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  cube2pos,
                                                                  new Color4[] { Color4.Green, Color4.Green, Color4.Blue, Color4.Blue, Color4.Cyan, Color4.Cyan },
                                                                  cube1dtr

                                                                  ));

                // this one above cube2 for use in testing ortho mode

                var cube3pos = GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f, new Vector3(10, 10.25f, 50));
                rObjects.Add(items.Shader("COSOT"), "scopen2",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  cube3pos,
                                                                  new Color4[] { Color4.Yellow },
                                                                  cube1dtr

                                                                  ));

                // negative z and x

                rObjects.Add(items.Shader("COSOT"), "scopen3",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                                  new Color4[] { Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red },
                                                                  new GLRenderDataTranslationRotation(new Vector3(-10, -2.5f, -10))
                                                                  ));

                rObjects.Add(items.Shader("COSOT"), "scopen4",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                                  new Color4[] { Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Red },
                                                                  new GLRenderDataTranslationRotation(new Vector3(-10, -2.5f, -20))
                                                                  ));
            }

            #endregion

            #region textures
            if (true)
            {
                // texture facing upwards, culled if viewer below it

                GLRenderState rq = GLRenderState.Quads();

                rObjects.Add(items.Shader("TEXOT"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(5.0f, 5.0f, new Vector3(-0f.Radians(), 0, 0), ccw: gl3dcontroller.MatrixCalc.ModelAxisPositiveZAwayFromViewer), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("dotted2"), new Vector3(0, 0, 0))
                                                                   ));
            }

            #endregion


            #region Matrix Calc Uniform

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // def binding of 0

            #endregion
        }