Пример #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Name of bitmap collection</param>
        /// <param name="rlist">Render list to draw into</param>
        /// <param name="bitmapsize">Bit map size</param>
        /// <param name="mipmaplevels">Mip map levels</param>
        /// <param name="textureformat">Texture format of bitmaps</param>
        /// <param name="cullface">True to cull face</param>
        /// <param name="depthtest">True to depth test</param>
        /// <param name="maxpergroup">Maximum number of bitmaps per group</param>
        /// <param name="yfixed">Set true to fix Y co-ord externally</param>
        public GLBitmaps(string name, GLRenderProgramSortedList rlist, Size bitmapsize, int mipmaplevels = 3,
                         OpenTK.Graphics.OpenGL4.SizedInternalFormat textureformat = OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8,
                         bool cullface = true, bool depthtest = true, int maxpergroup = int.MaxValue, bool yfixed = false)
        {
            this.name    = name;
            this.context = GLStatics.GetContext();

            int maxdepthpertexture = GL4Statics.GetMaxTextureDepth();   // limits the number of textures per 2darray
            int max = Math.Min(maxdepthpertexture, maxpergroup);        //note RI uses a VertexArray to load the matrix in, so not limited by that (max size of uniform buffer)

            matrixbuffers = new GLSetOfMatrixBufferWithGenerations(items, max);

            matrixbuffers.AddedNewGroup += AddedNewGroup;       // hook up call back to say i've made a group

            renderlist      = rlist;
            this.bitmapsize = bitmapsize;

            shader = new GLShaderPipeline(new GLPLVertexShaderMatrixQuadTexture(yfixed), new GLPLFragmentShaderTexture2DIndexed(0, alphablend: true));
            items.Add(shader);

            renderstate                    = GLRenderState.Quads();
            renderstate.CullFace           = cullface;
            renderstate.DepthTest          = depthtest;
            renderstate.ClipDistanceEnable = 1;  // we are going to cull primitives which are deleted

            texmipmaplevels    = mipmaplevels;
            this.textureformat = textureformat;
        }
        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
        }
        public GalaxyStars(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: 50, autoscalemin: 1f, autoscalemax: 50f, useeyedistance: false);
            var sunfrag = new GLPLStarSurfaceFragmentShader();

            sunshader = items.NewShaderPipeline(null, sunvertex, sunfrag);

            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.Quads();

            textrc.DepthTest          = true;
            textrc.ClipDistanceEnable = 1;  // we are going to cull primitives which are deleted

            int texunitspergroup = 16;
            var textshader       = items.NewShaderPipeline(null, new GLPLVertexShaderMatrixQuadTexture(), 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, new Size(128, 32), textrc, SizedInternalFormat.Rgba8);

            items.Add(slset);

            var geofind = new GLPLGeoShaderFindTriangles(findbufferresults, 16);

            findshader = items.NewShaderPipeline(null, sunvertex, null, null, geofind, null, null, null);
        }
Пример #4
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
        }
        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();
        }
Пример #6
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
        }
Пример #7
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);
            Closed += ShaderTest_Closed;

            var ext = GLStatics.Extensions();

            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");

            {
                Bitmap bmp       = new Bitmap(Properties.Resources.dotted2); // demo argb copy
                byte[] argbbytes = bmp.GetARGBBytes();
                Bitmap copy      = GLOFC.Utils.BitMapHelpers.CreateBitmapFromARGBBytes(bmp.Width, bmp.Height, argbbytes);
                var    tex       = new GLTexture2D(copy, SizedInternalFormat.Rgba8);
                items.Add(tex, "dotted2");
                Bitmap bmp2 = tex.GetBitmap(inverty: false);
                bmp2.Save(@"c:\code\dotted2.bmp");
            }

            #region coloured lines

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

                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.White, Color.Red, Color.DarkRed, Color.DarkRed })
                             );

                GLRenderState lines2 = GLRenderState.Lines(1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines2,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(100, -0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Orange, Color.Blue, 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 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))
                                                                  ));
            }

            #endregion

            #region Matrix Calc Uniform

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

            #endregion

            #region FB

            GLTexture2D ctex = new GLTexture2D();
            items.Add(ctex, "drawnbitmap");

            if (true)
            {
                int width = 1024, height = 768;

                // set up FB
                // NOTE: things end up inverted in Y in the texture, this is because textures are bottom up structures - seems the internet agrees

                GLFrameBuffer fb = new GLFrameBuffer();

                // attach a texture to draw to
                ctex.CreateOrUpdateTexture(width, height, OpenTK.Graphics.OpenGL4.SizedInternalFormat.Rgba8, 1);
                ctex.SetMinMagLinear();
                fb.AttachColor(ctex, 0, 0);

                GLRenderBuffer rb = new GLRenderBuffer();
                items.Add(rb);
                rb.Allocate(RenderbufferStorage.DepthComponent32f, ctex.Width, ctex.Height);
                fb.AttachDepth(rb);

                // bind Framebuffer to system for it to be the target to draw to, with a default back colour
                fb.BindColor(new OpenTK.Graphics.Color4(40, 40, 40, 255));

                GLMatrixCalc mc = new GLMatrixCalc();
                mc.PerspectiveNearZDistance = 1f;
                mc.PerspectiveFarZDistance  = 1000f;
                mc.ResizeViewPort(this, new Size(ctex.Width, ctex.Height));
                Vector3 lookat    = new Vector3(0, 0, 0);
                Vector2 camerapos = new Vector2(110f, 0);
                mc.CalculateModelMatrix(lookat, camerapos, 20F, 0);
                mc.CalculateProjectionMatrix();

                ((GLMatrixCalcUniformBlock)items.UB("MCUB")).SetFull(mc);

                var renderState = GLRenderState.Start();

                Vector4[] p = new Vector4[4];

                int size   = 64;
                int offset = 10;
                p[0] = new Vector4(offset, offset, 0, 1);               // topleft - correct winding for our system. For dotted, red/blue at top as dots
                p[1] = new Vector4(offset, offset + size, 0, 1);        // bottomleft
                p[2] = new Vector4(offset + size, offset, 0, 1);        // topright
                p[3] = new Vector4(offset + size, offset + size, 0, 1); // botright

                items.Add(new GLDirect(), "fbds1");

                GLRenderState       rts = GLRenderState.Tri();
                GLRenderDataTexture rdt = new GLRenderDataTexture(items.Tex("dotted2"));
                var ri = GLRenderableItem.CreateVector4(items, PrimitiveType.TriangleStrip, rts, p, rdt);
                ri.Execute(items.Shader("fbds1"), renderState, mc);

                GLRenderState lines = GLRenderState.Lines(1);

                var l1 = 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 });

                l1.Execute(items.Shader("COSW"), renderState, mc);

                var l2 = 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 });

                l2.Execute(items.Shader("COSW"), renderState, mc);

                var l3 = 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 });

                l3.Execute(items.Shader("COSW"), renderState, mc);
                var l4 = 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 });
                l4.Execute(items.Shader("COSW"), renderState, mc);

                GLRenderState rc = GLRenderState.Tri();
                rc.CullFace = false;
                var ri2 = 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)));
                ri2.Execute(items.Shader("COSOT"), renderState, mc);

                GLRenderState rq = GLRenderState.Quads();

                var ri3 = GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Triangles, rq,
                                                                GLShapeObjectFactory.CreateQuad(5f, 5f, new Vector3(-90F.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                new GLRenderDataTranslationRotationTexture(items.Tex("dotted2"), new Vector3(10, 0, 0)));

                ri3.Execute(items.Shader("TEXOT"), renderState, mc);

                GLFrameBuffer.UnBind();
                gl3dcontroller.MatrixCalc.SetViewPort();        // restore the view port

                byte[] texdatab = ctex.GetTextureImageAs <byte>(OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, 0, true);
                Bitmap bmp      = GLOFC.Utils.BitMapHelpers.CreateBitmapFromARGBBytes(ctex.Width, ctex.Height, texdatab);
                bmp.Save(@"c:\code\out.bmp");
            }

            #endregion


            if (true)
            {
                Vector4[] p = new Vector4[4];

                int size   = 128;
                int offset = 10;
                p[0] = new Vector4(offset, offset, 0, 1);               // topleft - correct winding for our system. For dotted, red/blue at top as dots
                p[1] = new Vector4(offset, offset + size, 0, 1);        // bottomleft
                p[2] = new Vector4(offset + size, offset, 0, 1);        // topright
                p[3] = new Vector4(offset + size, offset + size, 0, 1); // botright

                items.Add(new GLDirect(), "ds1");

                GLRenderState       rts = GLRenderState.Tri();
                GLRenderDataTexture rdt = new GLRenderDataTexture(items.Tex("dotted2"));

                rObjects.Add(items.Shader("ds1"), "ds1", GLRenderableItem.CreateVector4(items, PrimitiveType.TriangleStrip, rts, p, rdt));
            }

            if (true)
            {
                GLRenderState rq = GLRenderState.Quads();

                float width  = 20F;
                float height = 20F / ctex.Width * ctex.Height;

                // TexQuadInv corrects for the inverted FB texture
                rObjects.Add(items.Shader("TEXOT"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(width, height, new Vector3(-90F.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCCW,
                                                                   new GLRenderDataTranslationRotationTexture(ctex, new Vector3(-15, 0, 10))
                                                                   ));
            }

            if (true)
            {
                GLRenderState rq = GLRenderState.Quads();
                rObjects.Add(items.Shader("TEXOT"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(5f, 5f, new Vector3(-90F.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("dotted2"), new Vector3(10, 0, 0))
                                                                   ));
            }


            dataoutbuffer = items.NewStorageBlock(5);
            dataoutbuffer.AllocateBytes(sizeof(float) * 4 * 32, OpenTK.Graphics.OpenGL4.BufferUsageHint.DynamicRead);    // 32 vec4 back
        }
Пример #9
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 })
                             );
            }


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

                GLRenderState rt = GLRenderState.Tri();

                rObjects.Add(items.Shader("TEX"),
                             GLRenderableItem.CreateVector4Vector2(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Triangles, rt,
                                                                   GLCubeObjectFactory.CreateSolidCubeFromTriangles(2000f), GLCubeObjectFactory.CreateCubeTexTriangles(),
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("dotted2"), new Vector3(-2, 0, 0))
                                                                   ));
            }

            {
                items.Add(new GLFixedColorShaderWorld(Color.FromArgb(150, Color.Green)), "FCS1");
                items.Add(new GLFixedColorShaderWorld(Color.FromArgb(80, Color.Red)), "FCS2");

                GLRenderState rq = GLRenderState.Quads();

                rObjects.Add(items.Shader("FCS1"),
                             GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Quads, rq,
                                                            GLShapeObjectFactory.CreateQuad(1000, pos: new Vector3(4000, 500, 0))));
                rObjects.Add(items.Shader("FCS2"),
                             GLRenderableItem.CreateVector4(items, OpenTK.Graphics.OpenGL4.PrimitiveType.Quads, rq,
                                                            GLShapeObjectFactory.CreateQuad(1000, pos: new Vector3(4000, 1000, 0))));
            }

            MatrixCalcSpecial mc = new MatrixCalcSpecial();

            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";

            GLForm pform = new GLForm("Form1", "GL Control demonstration", new Rectangle(0, 0, 1000, 850));

            // pform.BackColor = Color.FromArgb(200, Color.Red);
            //pform.BackColorGradientDir = 90;
            //pform.BackColorGradientAlt = Color.FromArgb(200, Color.Yellow);

            displaycontrol.Add(pform);

            if (true)
            {
                GLPanel p1 = new GLPanel("P3", new Size(150, 150), DockingType.TopLeft, 0);
                p1.SetMarginBorderWidth(new MarginType(1), 1, Color.Black, new PaddingType(1));
                pform.Add(p1);
            }

            if (true)
            {
                GLTableLayoutPanel ptable = new GLTableLayoutPanel("tablelayout", new Rectangle(5, 200, 190, 190));
                ptable.Margin      = new MarginType(2);
                ptable.Padding     = new PaddingType(2);
                ptable.BorderWidth = 1;
                ptable.Rows        = new List <GLTableLayoutPanel.Style> {
                    new GLTableLayoutPanel.Style(GLTableLayoutPanel.Style.SizeTypeEnum.Weight, 50), new GLTableLayoutPanel.Style(GLTableLayoutPanel.Style.SizeTypeEnum.Weight, 50)
                };
                ptable.Columns = new List <GLTableLayoutPanel.Style> {
                    new GLTableLayoutPanel.Style(GLTableLayoutPanel.Style.SizeTypeEnum.Weight, 50), new GLTableLayoutPanel.Style(GLTableLayoutPanel.Style.SizeTypeEnum.Weight, 50)
                };
                pform.Add(ptable);
                GLImage pti1 = new GLImage("PTI1", new Rectangle(0, 0, 24, 24), Properties.Resources.dotted);
                pti1.Column = 0; pti1.Row = 0; pti1.Dock = DockingType.Fill;
                ptable.Add(pti1);
                GLImage pti2 = new GLImage("PTI2", new Rectangle(100, 0, 24, 24), Properties.Resources.dotted2);
                pti2.Column = 1; pti1.Row = 0;
                ptable.Add(pti2);
                GLImage pti3 = new GLImage("PTI3", new Rectangle(100, 0, 48, 48), Properties.Resources.ImportSphere);
                pti3.Column = 0; pti3.Row = 1; pti3.Dock = DockingType.LeftCenter; pti3.ImageStretch = true;
                ptable.Add(pti3);
                GLImage pti4 = new GLImage("PTI4", new Rectangle(100, 0, 64, 64), Properties.Resources.Logo8bpp);
                pti4.Column = 1; pti4.Row = 1; pti4.Dock = DockingType.Center;
                ptable.Add(pti4);
            }

            if (true)
            {
                GLFlowLayoutPanel pflow1 = new GLFlowLayoutPanel("flowlayout", new Rectangle(5, 400, 190, 190));
                pflow1.SetMarginBorderWidth(new MarginType(2), 1, Color.Black, new PaddingType(2));
                pflow1.FlowPadding = new PaddingType(10, 5, 0, 0);
                pform.Add(pflow1);
                GLImage pti1 = new GLImage("PTI1", new Rectangle(0, 0, 24, 24), Properties.Resources.dotted);
                pflow1.Add(pti1);
                GLImage pti2 = new GLImage("PTI2", new Rectangle(100, 0, 32, 32), Properties.Resources.dotted2);
                pflow1.Add(pti2);
                GLImage pti3 = new GLImage("PTI3", new Rectangle(100, 0, 48, 48), Properties.Resources.ImportSphere);
                pflow1.Add(pti3);
                GLImage pti4 = new GLImage("PTI4", new Rectangle(100, 0, 64, 64), Properties.Resources.Logo8bpp);
                pflow1.Add(pti4);
            }

            if (true)
            {
                GLScrollPanel sp1 = new GLScrollPanel("VSP1", new Rectangle(5, 600, 200, 200));
                sp1.BorderWidth = 1;
                sp1.BackColor   = Color.Yellow;
                // sp1.SetMarginBorderWidth(new Margin(2), 1, Color.Black, new GLOFC.GL4.Controls.Padding(2));
                pform.Add(sp1);
                GLImage sp1i1 = new GLImage("SP1I1", new Rectangle(0, 0, 190, 100), Properties.Resources.dotted);
                sp1.Add(sp1i1);
                GLImage sp1i2 = new GLImage("SP1I22", new Rectangle(10, 150, 100, 100), Properties.Resources.dotted);
                sp1.Add(sp1i2);
                GLImage sp1i3 = new GLImage("SP1I23", new Rectangle(100, 100, 200, 200), Properties.Resources.dotted2);
                sp1.Add(sp1i3);
                sp1.VertScrollPos = 0;
                sp1.HorzScrollPos = 0;

                GLScrollBar sb1 = new GLScrollBar("SB1", new Rectangle(220, 600, 20, 100), 0, 200);
                sb1.Scroll += (c, s1e) => sp1.VertScrollPos = s1e.NewValue;
                pform.Add(sb1);

                GLScrollBar sb2 = new GLScrollBar("SB2", new Rectangle(260, 600, 100, 20), 0, 200);
                sb2.HorizontalScroll = true;
                sb2.Scroll          += (c, s1e) => sp1.HorzScrollPos = s1e.NewValue;
                pform.Add(sb2);
            }

            int col2 = 200;

            if (true)
            {
                GLScrollPanelScrollBar spb1 = new GLScrollPanelScrollBar("CSPan", new Rectangle(col2, 5, 190, 190));
                spb1.ScrollBackColor = Color.Yellow;
                spb1.SetMarginBorderWidth(new MarginType(2), 1, Color.Black, new PaddingType(2));
                pform.Add(spb1);
                GLImage spb1i1 = new GLImage("SPB1I1", new Rectangle(10, 10, 100, 100), Properties.Resources.dotted);
                spb1.Add(spb1i1);
                GLButton but = new GLButton("SPB1BUT1", new Rectangle(40, 120, 40, 20), "But1");
                but.Click += (en, eb) => { System.Diagnostics.Debug.WriteLine("Click on SP Button"); };
                spb1.Add(but);
                GLImage spb1i2 = new GLImage("SPB1I2", new Rectangle(10, 150, 100, 100), Properties.Resources.dotted);
                spb1.Add(spb1i2);
                spb1.EnableHorzScrolling = false;
            }

            {
                GLButton but = new GLButton("ButExample", new Rectangle(40, 160, 40, 20), "But1");
                but.Click += (en, eb) => { System.Diagnostics.Debug.WriteLine("Click on SP Button"); };
                pform.Add(but);
            }
            int col3 = 400;

            if (true)
            {
                GLScrollPanelScrollBar spb1 = new GLScrollPanelScrollBar("CSPan2", new Rectangle(col3, 5, 190, 190));
                spb1.ScrollBackColor = Color.Blue;
                spb1.ScrollBarTheme.ThumbButtonColor = Color.Red;
                spb1.SetMarginBorderWidth(new MarginType(2), 1, Color.Black, new PaddingType(2));
                pform.Add(spb1);
                GLImage spb1i1 = new GLImage("SPB1I1", new Rectangle(10, 10, 100, 100), Properties.Resources.dotted);
                spb1.Add(spb1i1);
                GLImage spb1i2 = new GLImage("SPB1I2", new Rectangle(10, 120, 100, 100), Properties.Resources.dotted);
                spb1.Add(spb1i2);
                GLImage spb1i3 = new GLImage("SPB1I3", new Rectangle(150, 50, 100, 100), Properties.Resources.dotted2);
                spb1.Add(spb1i3);
            }

            if (true)
            {
                //GLGroupBox p3 = new GLGroupBox("GB1", "Group Box Very Long Title", new Rectangle(col2,200,190,190));
                GLGroupBox p3 = new GLGroupBox("GB1", "Group Box", new Rectangle(col2, 200, 190, 190));
                p3.TextAlign = ContentAlignment.MiddleRight;
                p3.AutoSize  = true;
                GLImage spb1i1 = new GLImage("SPB1I1", new Rectangle(10, 10, 100, 100), Properties.Resources.dotted);
                p3.Add(spb1i1);
                pform.Add(p3);
            }

            if (true)
            {
                GLTabControl tc = new GLTabControl("Tabc", new Rectangle(col2, 400, 200, 190));
                tc.TabNotSelectedColor = Color.Yellow;
                tc.TabSelectedColor    = Color.Red;
                tc.TabStyle            = new TabStyleRoundedEdge();
                //tc.TabStyle = new TabStyleSquare();
                //tc.TabStyle = new TabStyleAngled();
                tc.Font = new Font("Ms Sans Serif", 9);

                GLTabPage tabp1 = new GLTabPage("tabp1", "TAB 1", Color.Blue);
                tc.Add(tabp1);

                GLButton tabp1b1 = new GLButton("B1", new Rectangle(5, 5, 80, 40), "Button 1");
                tabp1.Add(tabp1b1);
                tabp1b1.Click      += (c, ev) => { System.Diagnostics.Debug.WriteLine("On click for " + c.Name + " " + ev.Button); };
                tabp1b1.ToolTipText = "Button 1";

                GLTabPage tabp2   = new GLTabPage("tabp2", "TAB Page 2", Color.Yellow);
                GLButton  tabp2b1 = new GLButton("B2-2", new Rectangle(5, 25, 80, 40), "Button 2-2");
                tabp2.Add(tabp2b1);
                tc.Add(tabp2);

                GLTabPage tabp3 = new GLTabPage("tabp3", "TAB Page 3", Color.Green);
                tc.Add(tabp3);
                GLTabPage tabp4 = new GLTabPage("tabp4", "TAB Page 4", Color.Magenta);
                tc.Add(tabp4);

                pform.Add(tc);
                //     tc.SelectedTab = 0;

                GLButton tabselnone = new GLButton("BTSN", new Rectangle(col2 + 200 + 5, 400, 40, 15), "None");
                tabselnone.Click += (c12, ev2) => { tc.SelectedTab = -1; };
                pform.Add(tabselnone);
            }


            if (true)
            {
                GLPanel pouter = new GLPanel("outerflow", new Rectangle(col3, 200, 1300, 30));      // make it very wide, so the child has all the width it wants to flow into
                pouter.SetMarginBorderWidth(new MarginType(5), 1, Color.Blue, new PaddingType(5));
                pouter.AutoSize = true;

                GLFlowLayoutPanel pflow2;
                pflow2             = new GLFlowLayoutPanel("Flowlayout2", new Rectangle(0, 0, 10, 10));
                pflow2.AutoSize    = true;
                pflow2.Margin      = new MarginType(2);
                pflow2.Padding     = new PaddingType(2);
                pflow2.BorderWidth = 1;
                pflow2.FlowPadding = new PaddingType(10, 5, 0, 5);

                GLImage pti1 = new GLImage("PTI1", new Rectangle(0, 0, 24, 24), Properties.Resources.dotted2);
                pflow2.Add(pti1);
                GLImage pti2 = new GLImage("PTI2", new Rectangle(0, 0, 32, 32), Properties.Resources.dotted2);
                pflow2.Add(pti2);
                GLImage pti3 = new GLImage("PTI3", new Rectangle(0, 0, 48, 48), Properties.Resources.ImportSphere);
                pflow2.Add(pti3);

                for (int i = 0; i < 5; i++)
                {
                    GLImage pti4 = new GLImage("PTI00" + i, new Rectangle(0, 0, 64, 64), Properties.Resources.Logo8bpp);
                    pflow2.Add(pti4);
                }

                pouter.Add(pflow2);
                pform.Add(pouter);
            }

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

            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
                {
                    //System.Diagnostics.Debug.WriteLine(ts + " Render");
                    displaycontrol.Render(glwfc.RenderState, ts);       // we use the same matrix calc as done in controller 3d draw
                };
            }
            else
            {
                gl3dcontroller.Start(glwfc, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F);     // HOOK the 3dcontroller to the form so it gets Form events
            }
            systemtimer.Interval = 25;
            systemtimer.Tick    += new EventHandler(SystemTick);
            systemtimer.Start();
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

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

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

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

            Bitmap[] numbitmaps    = new Bitmap[116];

            {
                Font fnt = new Font("Arial", 20);
                for (int i = 0; i < numbitmaps.Length; i++)
                {
                    int v = -45000 + 1000 * i;      // range from -45000 to +70000
                    numbitmaps[i] = new Bitmap(100, 100);
                    GLOFC.Utils.BitMapHelpers.DrawTextCentreIntoBitmap(ref numbitmaps[i], v.ToString(), fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Red, Color.AliceBlue);
                }

                GLTexture2DArray numtextures = new GLTexture2DArray(numbitmaps, SizedInternalFormat.Rgba8, ownbmp: true);
                items.Add(numtextures, "Nums");

                Matrix4[] numberposx = new Matrix4[(right - left) / 1000 + 1];
                for (int i = 0; i < numberposx.Length; i++)
                {
                    numberposx[i]  = Matrix4.CreateScale(1);
                    numberposx[i] *= Matrix4.CreateRotationX(-25f.Radians());
                    numberposx[i] *= Matrix4.CreateTranslation(new Vector3(left + 1000 * i, 0, front));
                }

                GLShaderPipeline numshaderx = new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0));
                items.Add(numshaderx, "IC-X");

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

                rObjects.Add(numshaderx, "xnum",
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberposx,
                                                                          rt, numberposx.Length));

                Matrix4[] numberposz = new Matrix4[(back - front) / 1000 + 1];
                for (int i = 0; i < numberposz.Length; i++)
                {
                    numberposz[i]  = Matrix4.CreateScale(1);
                    numberposz[i] *= Matrix4.CreateRotationX(-25f.Radians());
                    numberposz[i] *= Matrix4.CreateTranslation(new Vector3(right + 1000, 0, front + 1000 * i));
                }

                GLShaderPipeline numshaderz = new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(25));
                items.Add(numshaderz, "IC-Z");

                rObjects.Add(numshaderz, "ynum",
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberposz,
                                                                          rt, numberposz.Length));
            }

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

            float h = 50;

            if (h != -1)
            {
                GLRenderState rl = GLRenderState.Lines(1);

                int dist = 1000;
                //20?
                Color cr = Color.FromArgb(50, Color.Red);
                rObjects.Add(items.Shader("COSW"),    // 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("COSW"),
                             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 })
                             );
            }

            {
                items.Add(new GLTexture2D(numbitmaps[45], 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 (true) // 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);

                if (false)       // heat map checkout debug
                {
                    List <Vector4> points = new List <Vector4>();

                    int xcw = (right - left) / heat.Width;
                    int zch = (back - front) / heat.Height;

                    for (int x = 0; x < heat.Width; x++)
                    {
                        for (int z = 0; z < heat.Height; z++)
                        {
                            int   gx = left + x * xcw + xcw / 2;
                            int   gz = front + z * zch + zch / 2;
                            Color px = heat.GetPixel(x, z);
                            //System.Diagnostics.Debug.WriteLine(x + "," + z + " = " + gx + "," + gz + " : " + px.R);
                            points.Add(new Vector4(gx, 2000, gz, px.R));
                        }
                    }

                    items.Add(new GLHeatMapIntensity(), "ShP");
                    GLRenderState rp = GLRenderState.Points();
                    rp.DepthTest = false;
                    rObjects.Add(items.Shader("ShP"), GLRenderableItem.CreateVector4(items, PrimitiveType.Points, rp, points.ToArray()));
                }

                if (false)      // v1 via array
                {
                    List <Vector4> points = new List <Vector4>();
                    Random         rnd    = new Random(23);

                    int xcw = (right - left) / heat.Width;
                    int zch = (back - front) / heat.Height;

                    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 / 100000, 0), 20);

                                dist *= 2000;

                                var rs = GLPointsFactory.RandomStars4(c, gx, gx + xcw, gz, gz + zch, (int)dist, (int)-dist, rnd, w: i);

                                if (z == heat.Height / 2)
                                {
                                    System.Diagnostics.Debug.WriteLine(gx + "," + gz + "; " + dx + "," + dz + " = " + i + " " + c + " " + d + "=h " + dist);
                                }
                                //var rs = GLPointsFactory.RandomStars4(500, gx, gx + xcw, gz, gz + zch, (int)dist, (int)-dist, rnd, w:i);
                                points.AddRange(rs);
                            }
                        }
                    }

                    items.Add(new GalaxyStarDots(), "SD");
                    GLRenderState rp = GLRenderState.Points(1);
                    rp.DepthTest = false;

                    rObjects.Add(items.Shader("SD"), GLRenderableItem.CreateVector4(items, PrimitiveType.Points, rp, points.ToArray()));
                }

                if (true)  //v2 direct to buffer
                {
                    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), 40);

                                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.star_grey64, SizedInternalFormat.Rgba8), "lensflare");
                items.Add(new GLPointSpriteShader(items.Tex("lensflare")), "PS1");
                int dist = 20000;
                var p    = GLPointsFactory.RandomStars4(100, -dist, dist, 25899 - dist, 25899 + dist, 2000, -2000);

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

                rObjects.Add(items.Shader("PS1"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Points, rps, p, new Color4[] { Color.White }));
            }
        }
Пример #11
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));
            }
        }
        // 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
        }
Пример #13
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

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

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

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

                rObjects.Add(items.Shader("COS"), GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                                                       GLShapeObjectFactory.CreateBox(400, 200, 40, new Vector3(0, 0, 0), new Vector3(0, 0, 0)),
                                                                                       new Color4[] { Color.Red, Color.Red, Color.Green, Color.Green }));
            }

            {
                items.Add(new GLTexturedShaderObjectTranslation(), "TEX");

                using (var bmp = BitMapHelpers.DrawTextIntoAutoSizedBitmap("200,100", new Size(200, 100), new Font("Arial", 10.0f), System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Yellow, Color.Blue))
                {
                    items.Add(new GLTexture2D(bmp, SizedInternalFormat.Rgba8), "200,100");
                }

                using (var bmp = GLOFC.Utils.BitMapHelpers.DrawTextIntoAutoSizedBitmap("-200,-100", new Size(200, 100), new Font("Arial", 10.0f), System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Yellow, Color.Blue))
                {
                    items.Add(new GLTexture2D(bmp, SizedInternalFormat.Rgba8), "-200,-100");
                }

                GLRenderState rq = GLRenderState.Quads();

                rObjects.Add(items.Shader("TEX"), GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                                        GLShapeObjectFactory.CreateQuad(20.0f, 20.0f, new Vector3(-90f.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                                        new GLRenderDataTranslationRotationTexture(items.Tex("200,100"), new Vector3(200, 0, 100))));

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

            {
                items.Add(new GLStarPoints(), "STARS");

                Vector3[] stars = GLPointsFactory.RandomStars(10000, -200, 200, -100, 100, 20, -20);

                GLRenderState rp = GLRenderState.PointsByProgram();

                rObjects.Add(items.Shader("STARS"), "Stars", GLRenderableItem.CreateVector3Packed2(items, PrimitiveType.Points, rp,
                                                                                                   stars, new Vector3(50000, 50000, 50000), 16));
            }


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

            Closed += ShaderTest_Closed;
        }
Пример #14
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);

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

            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOT");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOTNoRot");
            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLColorShaderObjectTranslation(), "COSOT");
            items.Add(new GLFixedColorShaderObjectTranslation(Color.Goldenrod), "FCOSOT");
            items.Add(new GLTexturedShaderObjectCommonTranslation(), "TEXOCT");

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

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


            #region coloured lines

            GLRenderState def = new GLRenderState()
            {
                DepthTest = false
            };                                                                  // set up default state for fixed values - no depth test, rely on stencil

            if (true)
            {
                rObjects.Add(new GLOperationSetStencil());      // set default stencil

                GLRenderState rq = GLRenderState.Quads(def);

                IGLProgramShader s = items.Shader("TEXOT");

                rObjects.Add(s, "Quad",
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(5.0f, 5.0f, new Vector3(-90F.Radians(), 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   new GLRenderDataTranslationRotationTexture(items.Tex("dotted"), new Vector3(-2, 3, -6))
                                                                   ));

                rObjects.Add(new GLOperationStencilOnlyIfEqual());
            }

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

                rObjects.Add(items.Shader("COSOT"), "Tri",
                             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))
                                                                  ));
            }

            if (true)
            {
                GLRenderState lines = GLRenderState.Lines(def, 5);

                rObjects.Add(items.Shader("COSW"), "L1",
                             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.White, Color.Red, Color.DarkRed, Color.DarkRed })
                             );

                GLRenderState lines2 = GLRenderState.Lines(def, 1);

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

                rObjects.Add(items.Shader("COSW"), "L3",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines2,
                                                                  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"), "L4",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines2,
                                                                  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


            #endregion

            #region Matrix Calc Uniform

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

            #endregion
        }
Пример #15
0
        // 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 = 20F;
            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);
            };

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

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

                rObjects.Add(items.Shader("COS"),
                             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("COS"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, null,
                                                                  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 GLTexturedShaderObjectTranslation(), "TEX");
                items.Add(new GLTexture2D(Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8), "moon");

                GLRenderState rt = GLRenderState.Tri();

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

            {
                var sunvertex = new GLPLVertexShaderModelCoordWorldAutoscale(new Color[] { Color.Yellow, Color.FromArgb(255, 230, 230, 1) });

                items.Add(new GLShaderPipeline(sunvertex, new GLPLStarSurfaceFragmentShader()), "STAR");

                GLRenderState rt = GLRenderState.Tri();

                rObjects.Add(items.Shader("STAR"), "sun",
                             GLRenderableItem.CreateVector4(items, PrimitiveType.Triangles,
                                                            rt,
                                                            GLSphereObjectFactory.CreateSphereFromTriangles(3, 10.0f),
                                                            new GLRenderDataTranslationRotation(new Vector3(20, 0, 0)),
                                                            ic: 1));

                items.Add(new GLShaderStarCorona(), "CORONA");

                GLRenderState rq = GLRenderState.Quads();

                rObjects.Add(items.Shader("CORONA"), GLRenderableItem.CreateVector4(items, PrimitiveType.Quads,
                                                                                    rq,
                                                                                    GLShapeObjectFactory.CreateQuad(1f),
                                                                                    new GLRenderDataTranslationRotation(new Vector3(20, 0, 0), new Vector3(0, 0, 0), 20f, calclookat: true)));
            }

            if (true)
            {
                Vector4[] pos = new Vector4[3];
                pos[0] = new Vector4(-20, 0, 10, 0);
                pos[1] = new Vector4(0, 0, 10, 1);
                pos[2] = new Vector4(20, 0, 10, 2);

                var shape = GLSphereObjectFactory.CreateSphereFromTriangles(3, 10.0f);

                GLRenderState    rt = GLRenderState.Tri();
                GLRenderableItem ri = GLRenderableItem.CreateVector4Vector4(items, PrimitiveType.Triangles, rt, shape, pos, null, pos.Length, 1);

                var vertshader = new GLPLVertexShaderModelCoordWorldAutoscale(new Color[] { Color.Red, Color.Green, Color.Blue });
                var shader     = new GLShaderPipeline(vertshader, new GLPLStarSurfaceFragmentShader());
                items.Add(shader, "STAR-M2");
                rObjects.Add(shader, ri);
            }

            GLOFC.GLStatics.Check();

            GL.Enable(EnableCap.DepthClamp);
        }
Пример #16
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

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

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

            gl3dcontroller.PosCamera.ZoomScaling = 1.1f;

            gl3dcontroller.MatrixCalc.InPerspectiveMode = true;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), 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;

            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 GLFixedColorShaderWorld(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.dotted, SizedInternalFormat.Rgba8), "solmarker");
                items.Add(new GLTexturedShaderObjectTranslation(), "TEX");
                GLRenderState rq = GLRenderState.Quads(cullface: false);
                solmarker = new GLRenderDataTranslationRotationTexture(items.Tex("solmarker"), new Vector3(0, 0, 0));
                rObjects.Add(items.Shader("TEX"),
                             GLRenderableItem.CreateVector4Vector2(items, PrimitiveType.Quads, rq,
                                                                   GLShapeObjectFactory.CreateQuad(1.0f, 1.0f, new Vector3(0, 0, 0)), GLShapeObjectFactory.TexQuadCW,
                                                                   solmarker
                                                                   ));
            }



            {
                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 1

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


                texcoords = new GLTexture2DArray();
                items.Add(texcoords, "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));
            }
        }
Пример #17
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 = 500F;

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

            //gl3dcontroller.MatrixCalc.InPerspectiveMode = false;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(135f, 0, 0), 0.01F);

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

            float h = 0;
            {
                rObjects.Add(items.Shader("COSW"),    // 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[] { Color.Gray })
                             );

                rObjects.Add(items.Shader("COSW"),
                             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[] { Color.Gray })
                             );
            }

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

            {
                Bitmap[]  numbers   = new Bitmap[70];
                Matrix4[] numberpos = 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));
                }

                GLTexture2DArray array = new GLTexture2DArray(numbers, SizedInternalFormat.Rgba8, ownbmp: true);
                items.Add(array, "Nums");
                items.Add(new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0)), "IC-2");
                items.Shader("IC-2").StartAction  += (s, m) => { items.Tex("Nums").Bind(1); GL.Disable(EnableCap.CullFace); };
                items.Shader("IC-2").FinishAction += (s) => { GL.Enable(EnableCap.CullFace); };

                // investigate why its wrapping when we asked for it TexQUAD 1 which should interpolate over surface..

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

            // 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 ShaderV2(), "V2");
            GLRenderState rv = GLRenderState.Tri();

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

            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");

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block
        }
Пример #18
0
        private void CreateBodies(StarScan.ScanNode node, int subnode)
        {
            rBodyObjects.Clear();

            bodyinfo = new List <BodyInfo>();

            bool sysenabled = false;

            if (subnode > 0 && node.NodeType == StarScan.ScanNodeType.barycentre && node.Children != null)
            {
                node       = node.Children.Values[subnode - 1];
                sysenabled = true;
            }

            displaycontrol.ApplyToControlOfName("sys*", (c) => { c.Visible = sysenabled; });

            BodyInfo.CreateInfoTree(node, null, -1, 0, bodyinfo);

            foreach (var o in bodyinfo)
            {
                System.Diagnostics.Debug.Write($"Body {o.scannode.OwnName} {o.scannode.scandata?.StarType} {o.scannode.scandata?.PlanetClass} Lvl {o.scannode.Level} ");

                if (o.kepler != null)
                {
                    System.Diagnostics.Debug.Write($"SMA {o.kepler.SemiMajorAxis / oneAU_m} AU {o.kepler.SemiMajorAxis / 1000} km " +
                                                   $" Ecc {o.kepler.Eccentricity} Orbital Period {o.kepler.OrbitalPeriodS / 24 / 60 / 60 / 365} Y Radius {o.scannode.scandata.nRadius} m CM {o.kepler.CentralMass} axt {o.scannode.scandata.nAxialTilt}");
                }

                System.Diagnostics.Debug.WriteLine("");

                if (o.kepler != null)
                {
                    Vector4[]     orbit = o.kepler.Orbit(currentjd, 0.1, mscaling);
                    GLRenderState lines = GLRenderState.Lines(1);
                    lines.DepthTest = false;

                    o.orbitpos.ColorIndex = node.scandata?.nRadius != null ? 0 : 1;

                    var riol = GLRenderableItem.CreateVector4(items, PrimitiveType.LineStrip, lines, orbit, o.orbitpos);
                    rBodyObjects.Add(orbitlineshader, riol);

                    GLRenderState quad = GLRenderState.Quads(cullface: false);
                    quad.DepthTest = false;
                    var s       = 100000e3f * mscaling;
                    var quadpos = new Vector4[] { new Vector4(-s, 0, -s, 1), new Vector4(-s, 0, +s, 1), new Vector4(+s, 0, +s, 1), new Vector4(+s, 0, -s, 1) };
                    var plane   = GLRenderableItem.CreateVector4(items, PrimitiveType.Quads, quad, quadpos, o.bodypos);
                    rBodyObjects.Add(bodyplaneshader, plane);
                }
            }

            int bodies = bodyinfo.Count;

            // hold planet and barycentre positions/sizes/imageno
            bodymatrixbuffer.AllocateBytes(GLBuffer.Mat4size * bodies);

            GLRenderState rt = GLRenderState.Tri();

            rt.DepthTest = false;
            var ribody = GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Triangles, rt, spherebuffer, spheretexcobuffer, bodymatrixbuffer,
                                                                      spherebuffer.Length / sizeof(float) / 4,
                                                                      ic: bodies, matrixdivisor: 1);

            rBodyObjects.Add(bodyshader, ribody);

            rifind = GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Triangles, GLRenderState.Tri(), spherebuffer, spheretexcobuffer, bodymatrixbuffer,
                                                                  spherebuffer.Length / sizeof(float) / 4,
                                                                  ic: bodies, matrixdivisor: 1);
        }
        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
        }
        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;

            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(126.75f, 0, 0), 0.31622F);

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

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

            float h = -1;

            if (h != -1)
            {
                int   dist = 1000;
                Color cr   = Color.FromArgb(20, Color.Red);
                rObjects.Add(items.Shader("COS-1L"),    // horizontal
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl1,
                                                                  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, rl1,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(left, h, front), new Vector3(right, h, front), new Vector3(0, 0, dist), (right - left) / dist + 1),
                                                                  new Color4[] { cr })
                             );
            }

            {
                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 GLFixedColorShaderWorld(System.Drawing.Color.Yellow), "LINEYELLOW");
                rObjects.Add(items.Shader("LINEYELLOW"),
                             GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl1, displaylines));
            }


            Bitmap[] numbitmaps = new Bitmap[116];

            {
                Font fnt = new Font("Arial", 20);
                for (int i = 0; i < numbitmaps.Length; i++)
                {
                    int v = -45000 + 1000 * i;      // range from -45000 to +70000
                    numbitmaps[i] = new Bitmap(100, 100);
                    GLOFC.Utils.BitMapHelpers.DrawTextCentreIntoBitmap(ref numbitmaps[i], v.ToString(), fnt, System.Drawing.Text.TextRenderingHint.ClearTypeGridFit, Color.Red, Color.AliceBlue);
                }

                GLTexture2DArray numtextures = new GLTexture2DArray(numbitmaps, SizedInternalFormat.Rgba8, ownbmp: true);
                items.Add(numtextures, "Nums");

                Matrix4[] numberposx = new Matrix4[(right - left) / 1000 + 1];
                for (int i = 0; i < numberposx.Length; i++)
                {
                    numberposx[i]  = Matrix4.CreateScale(1);
                    numberposx[i] *= Matrix4.CreateRotationX(-25f.Radians());
                    numberposx[i] *= Matrix4.CreateTranslation(new Vector3(left + 1000 * i, 0, front));
                }

                GLShaderPipeline numshaderx = new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(0));
                items.Add(numshaderx, "IC-X");

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

                rObjects.Add(numshaderx, "xnum",
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberposx,
                                                                          rt, numberposx.Length));

                Matrix4[] numberposz = new Matrix4[(back - front) / 1000 + 1];
                for (int i = 0; i < numberposz.Length; i++)
                {
                    numberposz[i]  = Matrix4.CreateScale(1);
                    numberposz[i] *= Matrix4.CreateRotationX(-25f.Radians());
                    numberposz[i] *= Matrix4.CreateTranslation(new Vector3(right + 1000, 0, front + 1000 * i));
                }

                GLShaderPipeline numshaderz = new GLShaderPipeline(new GLPLVertexShaderModelMatrixTexture(), new GLPLFragmentShaderTexture2DIndexed(25));
                items.Add(numshaderz, "IC-Z");

                rObjects.Add(numshaderz, "ynum",
                             GLRenderableItem.CreateVector4Vector2Matrix4(items, PrimitiveType.Quads, rq,
                                                                          GLShapeObjectFactory.CreateQuad(500.0f), GLShapeObjectFactory.TexQuadCW, numberposz,
                                                                          rt, numberposz.Length));
            }

            {
                items.Add(new GLTexture2D(numbitmaps[45], 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))
                                                                   ));
            }

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

            if (true)
            {
                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

                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.GetTextureImageAs <float>(OpenTK.Graphics.OpenGL4.PixelFormat.Red); // read back check

                // 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");
                gs.StartAction += (a, m) => { galtex.Bind(1); noise3d.Bind(3); gaussiantex.Bind(4); };

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

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