示例#1
0
 public GLUniform(GLShader sdr, string name)
 {
     location = GL.GetUniformLocation(sdr.ShaderProgram, name);
     if (location < 0)
     {
         throw new Exception("Uniform location '" + name + "' could not be resolved");
     }
 }
示例#2
0
        public CoordinateSystem()
        {
            // Load shader
            sdr = new GLShader(new string[] { COORDINATE_SYSTEM_SHADER.VS }, new string[] { COORDINATE_SYSTEM_SHADER.FS });
            sdr_colorModeParam = sdr.GetUniformLocation("ColorMode");

            // Load texture
            tex = GLTexture2D.FromFile(Global.EXE_DIR + "arrow.png");
        }
示例#3
0
        public CoordinateSystem()
        {
            // Load shader
            sdr = new GLShader(new string[] {COORDINATE_SYSTEM_SHADER.VS}, new string[] {COORDINATE_SYSTEM_SHADER.FS});
            sdr_colorModeParam = sdr.GetUniformLocation("ColorMode");

            // Load texture
            tex = GLTexture2D.FromFile(Global.EXE_DIR + "arrow.png");
        }
示例#4
0
        public void Draw(GLShader sdr, Matrix4 viewprojmatrix)
        {
            //GL.Enable(EnableCap.CullFace);
            Matrix4 transform = Matrix4.CreateTranslation(-0.5f, -0.5f, 0.0f) * Common.Matrix4_CreateRotationDir(new Vector3(a, b, c), new Vector3(0.0f, 0.0f, 1.0f)) * Matrix4.CreateTranslation(new Vector3(a, b, c) * -d);

            sdr.Bind(transform * viewprojmatrix);
            Common.meshQuad.Bind(sdr, null);
            Common.meshQuad.Draw();
            //GL.Disable(EnableCap.CullFace);
        }
示例#5
0
        public GLTextFont(string filename, Vector2 charsize, GLMesh meshquad)
        {
            this.texture  = GLTexture2D.FromFile(filename);
            this.charsize = charsize;
            this.meshquad = meshquad;

            if (fontshader == null)
            {
                fontshader = new GLShader(new string[] { FONT_SHADER.VS }, new string[] { FONT_SHADER.FS });
                fontshader_coloruniform = fontshader.GetUniformLocation("Color");
            }
        }
示例#6
0
        public GLNumberFont(string filename, FontDefinition fontDefinition, GLMesh meshquad, bool isFixedWidth)
        {
            this.texture    = GLTexture2D.FromFile(filename);
            this.fontdef    = fontDefinition;
            this.meshquad   = meshquad;
            this.fixedwidth = /*isFixedWidth ? fontdef[0][10] / 10 :*/ 0;

            if (fontshader == null)
            {
                fontshader = new GLShader(new string[] { FONT_SHADER.VS }, new string[] { FONT_SHADER.FS });
                fontshader_coloruniform = fontshader.GetUniformLocation("Color");
            }
        }
            public void Draw(Rectangle bounds, int argidx, Size backbufferSize, GLShader sdr, int colorUniform)
            {
                float x, y;

                this.bounds = bounds;

                Matrix4 trans = Matrix4.Identity;

                trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f);

                sdr.Bind(trans);
                GL.Uniform4(colorUniform, BORDER_COLOR);
                meshBorders.Bind(sdr, null);
                meshBorders.Draw();

                GL.Uniform4(colorUniform, SLIDER_COLOR);
                meshSlider.Bind(sdr, null);
                y = 0.0f;                //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height;
                //int xi = 0;
                float sliderWidth = 20.0f;

                //x = (float)(xi + 1) / (float)(values.Length + 1);
                x  = (currentValue - minValue) / valueRange;
                x *= (2.0f * bounds.Width) / backbufferSize.Width;
                x  = (sliderWidth + x * (bounds.Width - sliderWidth)) / bounds.Width;
                sdr.Bind(Matrix4.CreateScale(sliderWidth / (2.0f * bounds.Width), 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f));
                meshSlider.Draw();

                GL.LineWidth(2.0f);
                sdr.Bind(trans);
                GL.Uniform4(colorUniform, TICK_COLOR);
                meshTick.Bind(sdr, null);

                for (int i = 0; i < values.Length; ++i)
                {
                    //x = (float)(i + 1) / (float)(values.Length + 1);
                    x = (values[i] - minValue) / valueRange;
                    sdr.Bind(trans * Matrix4.CreateTranslation((x * 2.0f * (bounds.Width - sliderWidth) + sliderWidth) / backbufferSize.Width, 0.0f, 0.0f));
                    meshTick.Draw();
                }

                GL.LineWidth(1.0f);

                Vector2 strsize = Common.fontText2.MeasureString(label);

                Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize);
                this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y);
            }
示例#8
0
        public static void CreateCommonShaders()
        {
            sdrTextured = new GLShader(new string[] { TEXTURED_SHADER.VS }, new string[] { TEXTURED_SHADER.FS });
            sdrTextured.Bind();
            sdrTextured_colorUniform = sdrTextured.GetUniformLocation("Color");
            GL.Uniform4(sdrTextured_colorUniform, OpenTK.Graphics.Color4.White);

            sdrSolidColor = new GLShader(new string[] { SOLID_COLOR_SHADER.VS }, new string[] { SOLID_COLOR_SHADER.FS });
            sdrSolidColor.Bind();
            sdrSolidColor_colorUniform = sdrSolidColor.GetUniformLocation("Color");
            GL.Uniform4(sdrSolidColor_colorUniform, OpenTK.Graphics.Color4.White);

            sdrDashedLine = new GLShader(new string[] { DASHED_LINE_SHADER.VS }, new string[] { DASHED_LINE_SHADER.FS });
            sdrDashedLine.Bind();
            sdrDashedLine_colorUniform  = sdrDashedLine.GetUniformLocation("Color");
            sdrDashedLine_lengthUniform = sdrDashedLine.GetUniformLocation("Length");
            GL.Uniform4(sdrDashedLine_colorUniform, OpenTK.Graphics.Color4.White);
        }
示例#9
0
        public void Load(Cinema.CinemaArgument[] arguments, Dictionary <string, HashSet <object> > valuerange)
        {
            this.arguments = arguments;

            // Create selection array and populate it with the default values
            selection = new Selection(arguments.Length, valuerange.Count, images);
            for (int i = 0; i < arguments.Length; ++i)
            {
                if (arguments[i].defaultValue != null)
                {
                    selection[i].Add(Array.IndexOf(arguments[i].values, arguments[i].defaultValue));
                }
            }

            // Load shader
            sdrColored            = new GLShader(new string[] { ARGUMENT_INDEX_SHADER.VS }, new string[] { ARGUMENT_INDEX_SHADER.FS });
            sdrColored_colorParam = sdrColored.GetUniformLocation("Color");
            sdrColored.Bind();

            meshSelection = new GLMesh(new Vector3[] { new Vector3(0.0f, -0.1f, 0.0f), new Vector3(0.0f, 1.15f, 0.0f) }, null, null, null, null, null, PrimitiveType.Lines);

            // Create track bars for each argument
            foreach (Cinema.CinemaArgument argument in arguments)
            {
                TrackBar newtrackbar = new TrackBar(argument.values.Length, meshSelection);
                newtrackbar.label = argument.label;
                trackbars.Add(newtrackbar);
            }

            // Create track bars for meta data value
            foreach (KeyValuePair <string, HashSet <object> > range in valuerange)
            {
                TrackBar newtrackbar = new TrackBar(range.Value.Count, meshSelection);
                newtrackbar.label = range.Key;
                trackbars.Add(newtrackbar);
            }

            argumentLabelBounds = new Rectangle[arguments.Length];
        }
示例#10
0
            public void Draw(Rectangle bounds, HashSet <int> selection, Size backbufferSize, GLShader sdr, int colorUniform)
            {
                float x, y;

                this.bounds = bounds;

                Matrix4 trans = Matrix4.Identity;

                trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f);

                sdr.Bind(trans);
                GL.Uniform4(colorUniform, BORDER_COLOR);
                meshBorders.Bind(sdr, null);
                meshBorders.Draw();

                GL.LineWidth(6.0f);
                if (selection != null)
                {
                    GL.Uniform4(colorUniform, SELECTION_COLOR);
                    meshSelection.Bind(sdr, null);
                    y = 0.0f;                    //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height;
                    foreach (int xi in selection)
                    {
                        x  = (float)(xi + 1) / (float)(numvalues + 1);
                        x *= 2.0f * bounds.Width / backbufferSize.Width;
                        sdr.Bind(trans * Matrix4.CreateTranslation(x, y, 0.0f));
                        meshSelection.Draw();
                    }
                }

                /*Point preSelectedTick;
                 * if(TickFromMousePosition(mousepos, backbufferSize, out preSelectedTick))
                 * {
                 *      GL.Uniform4(sdrColored_colorParam, PRESELECTION_COLOR);
                 *      if(preSelectedTick.X == -1)
                 *              for(preSelectedTick.X = 0; preSelectedTick.X < arguments[preSelectedTick.Y].values.Length; ++preSelectedTick.X)
                 *              {
                 *                      x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                 *                      sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                 *                      meshSelection.Draw();
                 *              }
                 *      else
                 *      {
                 *              x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                 *              sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                 *              meshSelection.Draw();
                 *      }
                 * }*/

                GL.LineWidth(2.0f);
                sdr.Bind(trans);
                GL.Uniform4(colorUniform, TICK_COLOR);
                meshTicks.Bind(sdr, null);
                meshTicks.Draw();

                GL.LineWidth(1.0f);

                Vector2 strsize = Common.fontText.MeasureString(label);

                Common.fontText.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize);
                this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y);
            }
示例#11
0
            public void Draw(Rectangle bounds, Selection selection, Size backbufferSize, GLShader sdr, int colorUniform)
            {
                float x, y;

                this.bounds = bounds;

                Matrix4 trans = Matrix4.Identity;
                trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f);

                sdr.Bind(trans);
                GL.Uniform4(colorUniform, BORDER_COLOR);
                meshBorders.Bind(sdr, null);
                meshBorders.Draw();

                if(selection != null)
                {
                    GL.Uniform4(colorUniform, SELECTION_COLOR);
                    meshSelection.Bind(sdr, null);
                    y = 0.0f;//(2.0f * bounds.Height - 4.0f) / backbufferSize.Height;
                    foreach(TransformedImage selectedimage in selection)
                    {
                        /*int xi = -1;
                        for(int i = 0; i < selectedimage.args.Length; ++i)
                            if(selectedimage.args[i] == Global.arguments[argidx])
                            {
                                xi = Array.IndexOf(selectedimage.args[i].values, selectedimage.values[i]);
                                break;
                            }
                        if(xi == -1)
                            continue;*/

                        if(selectedimage.globalargindices.Length <= argidx || selectedimage.globalargindices[argidx] == -1)
                            continue;
                        int xi = Array.IndexOf(Global.arguments[argidx].values, selectedimage.values[selectedimage.globalargindices[argidx]]);
                        if(xi == -1)
                            continue;

                        /*if(selectedimage.args.Length <= argidx)
                            continue;
                        int xi = Array.IndexOf(selectedimage.args[argidx].values, selectedimage.values[argidx]);*/

                        float halfwidth = argument.strValues.Length <= MAX_NUM_ARGS_SHOWING_VALUES ? Common.fontTextSmall.MeasureString(argument.strValues[xi]).X / 2.0f + 2.0f : 3.0f;

                        x = (float)(xi + 1) / (float)(argument.strValues.Length + 1);
                        x *= 2.0f * bounds.Width / backbufferSize.Width;
                        sdr.Bind(Matrix4.CreateScale(halfwidth / bounds.Width, 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f));
                        meshSelection.Draw();
                    }
                }

                /*Point preSelectedTick;
                if(TickFromMousePosition(mousepos, backbufferSize, out preSelectedTick))
                {
                    GL.Uniform4(sdrColored_colorParam, PRESELECTION_COLOR);
                    if(preSelectedTick.X == -1)
                        for(preSelectedTick.X = 0; preSelectedTick.X < arguments[preSelectedTick.Y].values.Length; ++preSelectedTick.X)
                        {
                            x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                            sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                            meshSelection.Draw();
                        }
                    else
                    {
                        x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                        sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                        meshSelection.Draw();
                    }
                }*/

                if(argument.strValues.Length > MAX_NUM_ARGS_SHOWING_VALUES)
                {
                    GL.LineWidth(2.0f);
                    sdr.Bind(trans);
                    GL.Uniform4(colorUniform, TICK_COLOR);
                    meshTick.Bind(sdr, null);

                    for(int i = 0; i < argument.strValues.Length; ++i)
                    {
                        //x = (float)(i + 1) / (float)(argument.strValues.Length + 1);
                        x = argument.values[i] / 10.0f;
                        sdr.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, 0.0f, 0.0f));
                        meshTick.Draw();
                    }
                }
                else
                {
                    y = bounds.Bottom - Common.fontTextSmall.MeasureString(" ").Y + 2.0f;
                    for(int i = 0; i < argument.values.Length; ++i)
                    {
                        x = (float)(i + 1) / (float)(argument.strValues.Length + 1);
                        Common.fontTextSmall.DrawString(bounds.Left + x * bounds.Width - Common.fontTextSmall.MeasureString(argument.strValues[i]).X / 2.0f, y, argument.strValues[i], backbufferSize);
                    }
                }

                GL.LineWidth(1.0f);

                Vector2 strsize = Common.fontText2.MeasureString(label);
                Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize);
                this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y);
            }
示例#12
0
            public void Draw(Rectangle bounds, int argidx, Size backbufferSize, GLShader sdr, int colorUniform)
            {
                float x, y;

                this.bounds = bounds;

                Matrix4 trans = Matrix4.Identity;

                trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f);

                sdr.Bind(trans);
                GL.Uniform4(colorUniform, BORDER_COLOR);
                meshBorders.Bind(sdr, null);
                meshBorders.Draw();

                GL.Uniform4(colorUniform, CHECK_COLOR);
                meshCheck.Bind(sdr, null);
                y = 0.0f;                //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height;
                int xi = 0;

                foreach (bool isChecked in parameter.isChecked)
                {
                    if (isChecked)
                    {
                        float halfwidth = parameter.strValues.Length <= MAX_NUM_PARAMS_SHOWING_VALUES?Common.fontTextSmall.MeasureString(parameter.strValues[xi]).X / 2.0f + 2.0f : 3.0f;

                        x  = (float)(xi + 1) / (float)(parameter.strValues.Length + 1);
                        x *= 2.0f * bounds.Width / backbufferSize.Width;
                        sdr.Bind(Matrix4.CreateScale(halfwidth / bounds.Width, 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f));
                        meshCheck.Draw();
                    }
                    ++xi;
                }

                if (parameter.strValues.Length > MAX_NUM_PARAMS_SHOWING_VALUES)
                {
                    GL.LineWidth(2.0f);
                    sdr.Bind(trans);
                    GL.Uniform4(colorUniform, TICK_COLOR);
                    meshTick.Bind(sdr, null);

                    for (int i = 0; i < parameter.strValues.Length; ++i)
                    {
                        //x = (float)(i + 1) / (float)(parameter.strValues.Length + 1);
                        x = parameter.values[i] / 10.0f;
                        sdr.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, 0.0f, 0.0f));
                        meshTick.Draw();
                    }
                }
                else
                {
                    y = bounds.Bottom - Common.fontTextSmall.MeasureString(" ").Y + 2.0f;
                    for (int i = 0; i < parameter.values.Length; ++i)
                    {
                        x = (float)(i + 1) / (float)(parameter.strValues.Length + 1);
                        Common.fontTextSmall.DrawString(bounds.Left + x * bounds.Width - Common.fontTextSmall.MeasureString(parameter.strValues[i]).X / 2.0f, y, parameter.strValues[i], backbufferSize);
                    }
                }

                GL.LineWidth(1.0f);

                Vector2 strsize = Common.fontText2.MeasureString(label);

                Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize);
                this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y);
            }
示例#13
0
 public GLUniformVector3(GLShader sdr, string name) : base(sdr, name)
 {
 }
示例#14
0
        public ColorTableManager(GLWindow glcontrol)
        {
            this.glcontrol = glcontrol;
            this.Bounds = new Rectangle(Point.Empty, glcontrol.Size);
            SetCursor(CursorType.Default);

            ShowColormapPickerAction = ActionManager.CreateAction("Show colormap picker", "show picker", delegate(object[] parameters) {
                pickerVisible = true;
                return null;
            });
            HideColormapPickerAction = ActionManager.CreateAction("Hide colormap picker", "hide picker", delegate(object[] parameters) {
                pickerVisible = false;
                return null;
            });

            // Create shaders as singleton
            /*if(colortableshader == null)
                colortableshader = new GLShader(new string[] {COLOR_TABLE_SHADER.VS}, new string[] {COLOR_TABLE_SHADER.FS});*/
            if(lineshader == null)
                lineshader = new GLShader(new string[] {LINE_SHADER.VS}, new string[] {LINE_SHADER.FS});
            if(cmpreviewshader == null)
                cmpreviewshader = new GLShader(new string[] {COLORMAP_PREVIEW_SHADER.VS}, new string[] {COLORMAP_PREVIEW_SHADER.FS});

            // Create input section
            input = new InputSection(this, new GLTextFont2(new Font("Lucida Sans Unicode", 12.0f)));
            input.Bounds = new Rectangle(130, 60, glcontrol.Width - 260, 200);//new Rectangle(100, glcontrol.Height - 60, glcontrol.Width - 400, 40);
            input.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
            this.Controls.Add(input);

            // Create colormap picker
            picker = new ColorMapPicker(new GLTextFont2(new Font("Lucida Sans Unicode", 12.0f/*, FontStyle.Bold*/)));
            picker.bounds = new Rectangle(0, 0, glcontrol.Width, input.Bounds.Top);
            picker.ColormapDragStart += ColorMapPicker_ColormapDragStart;

            // Create/load colormaps
            AddColormap(ColorTableFromSolidColor(Color4.Red, Vector3.Zero, "Red"));
            AddColormap(ColorTableFromSolidColor(Color4.Orange, Vector3.Zero, "Orange"));
            AddColormap(ColorTableFromSolidColor(Color4.Yellow, Vector3.Zero, "Yellow"));
            AddColormap(ColorTableFromSolidColor(Color4.Green, Vector3.Zero, "Green"));
            AddColormap(ColorTableFromSolidColor(new Color4(0.215686f, 0.278431f, 0.082353f, 1.0f), Vector3.Zero, "Green2"));
            AddColormap(ColorTableFromSolidColor(Color4.Blue, Vector3.Zero, "Blue"));
            AddColormap(ColorTableFromSolidColor(new Color4(0.082353f, 0.133333f, 0.278431f, 1.0f), Vector3.Zero, "Blue2"));
            AddColormap(ColorTableFromSolidColor(Color4.White, Vector3.Zero, "White"));
            AddColormap(ColorTableFromSolidColor(Color4.Gray, Vector3.Zero, "Gray"));
            AddColormap(ColorTableFromSolidColor(Color4.Black, Vector3.Zero, "Black"));
            AddColormap(ColorTableFromSolidColor(new Color4(1.0f, 1.0f, 1.0f, 0.25f), Vector3.Zero, "25% White", "Transparent"));
            AddColormap(ColorTableFromSolidColor(new Color4(1.0f, 1.0f, 1.0f, 0.5f), Vector3.Zero, "50% White", "Transparent"));
            AddColormap(ColorTableFromSolidColor(new Color4(0.0f, 0.0f, 0.0f, 0.25f), Vector3.Zero, "25% Black", "Transparent"));
            AddColormap(ColorTableFromSolidColor(new Color4(0.0f, 0.0f, 0.0f, 0.5f), Vector3.Zero, "50% Black", "Transparent"));
            AddColormap(ColorTableFromSolidColor(new Color4(1.0f, 0.0f, 0.0f, 0.25f), Vector3.Zero, "25% Red", "Transparent"));
            AddColormap(ColorTableFromSolidColor(new Color4(1.0f, 0.0f, 0.0f, 0.5f), Vector3.Zero, "50% Red", "Transparent"));
            /*ColorMapCreator.Vector3 C0 = new ColorMapCreator.Vector3(58.650f, 76.245f, 192.270f);
            ColorMapCreator.Vector3 C1 = new ColorMapCreator.Vector3(180.030f, 4.080f, 38.250f);
            AddColormap(ColorTableFromRange(C0, C1, new Vector3(65.0f / 255.0f, 68.0f / 255.0f, 91.0f / 255.0f), "Moreland cool/warm", "Divergent"));*/
            AddColormaps(ColorTableFromXml(Global.EXE_DIR + "ColorMaps.xml"));
            //AddColormap(NamedColorTable.None);

            // Overwrite default //EDIT: DELETE
            //colormaps.Remove("_default"); //EDIT: DELETE
            //colormaps.Add("_default", colormaps["KineticEnergy"]); //EDIT: DELETE

            ActionManager.Do(HideColormapPickerAction);
            Reset();
            input.UpdateColormap();

            // Create buttons
            buttons = new GLButton[5];
            buttons[0] = new GLButton(Global.EXE_DIR + "splitterButton.png", new Rectangle(4, 100, 0, 0), AnchorStyles.Bottom | AnchorStyles.Left, "CreateSplitter", "Create colormap splitter");
            buttons[0].Click = SplitterButton_Click;
            buttons[1] = new GLButton(Global.EXE_DIR + "interjectorButton.png", new Rectangle(4, 100 - buttons[0].Bounds.Height, 0, 0), AnchorStyles.Bottom | AnchorStyles.Left, "CreateInterjector", "Create colormap interjector");
            buttons[1].Click = InterjectorButton_Click;
            buttons[2] = new GLButton(Global.EXE_DIR + "colorMapButton.png", new Rectangle(4, 100, 0, 0), AnchorStyles.Bottom | AnchorStyles.Right, "ShowColormapPicker", "Show colormap picker");
            buttons[2].Click = ColorMapButton_Click;
            buttons[3] = new GLButton(Global.EXE_DIR + "saveColorMapButton.png", new Rectangle(4, 100 - buttons[2].Bounds.Height, 0, 0), AnchorStyles.Bottom | AnchorStyles.Right, "SaveColormap", "Save colormap to disk");
            buttons[3].Click = SplitterButton_Click;
            buttons[3].Visible = false;
            buttons[4] = new GLButton(Global.EXE_DIR + "trashButton.png", new Rectangle(4, 100, 0, 0), AnchorStyles.Bottom | AnchorStyles.Left, "RemoveSplitter", "Remove colormap splitter");
            buttons[4].MouseUp = TrashButton_MouseUp;
            buttons[4].Visible = false;

            // Create cursors
            cursors = new GLCursor[2];
            cursors[0] = new GLCursor(Global.EXE_DIR + "splitterCursor.png", new Point(2, 54));
            cursors[1] = new GLCursor(Global.EXE_DIR + "interjectorCursor.png", new Point(8, 51));

            /*HISTORY_PATH = System.Reflection.Assembly.GetEntryAssembly().Location;
            HISTORY_PATH = HISTORY_PATH.Substring(0, Math.Max(HISTORY_PATH.LastIndexOf('/'), HISTORY_PATH.LastIndexOf('\\')) + 1);
            HISTORY_PATH += ".colormap";

            if(System.IO.File.Exists(HISTORY_PATH))
            {
                System.IO.StreamReader sr = new System.IO.StreamReader(HISTORY_PATH);
                while(sr.Peek() != -1)
                    history.Add(sr.ReadLine());
                sr.Close();
                history_idx = history.Count;
            }*/
        }
示例#15
0
        public GLTextFont2(Font font)
        {
            if (fontshader == null)
            {
                fontshader = new GLShader(new string[] { FONT_SHADER.VS }, new string[] { FONT_SHADER.FS });
                fontshader_coloruniform = fontshader.GetUniformLocation("Color");
            }

            /*string charmap = "";
             * for(int i = 0; i < 255; ++i)
             *      if(!char.IsControl((char)i))
             *      charmap += (char)i;
             *
             * Bitmap bmp = new Bitmap(1, 1);
             * Graphics gfx = Graphics.FromImage(bmp);
             * Size charmapSize = gfx.MeasureString(charmap, font, 1024).ToSize();
             * bmp = new Bitmap(charmapSize.Width, charmapSize.Height);
             * gfx = Graphics.FromImage(bmp);
             * gfx.DrawString(charmap, font, Brushes.White, new RectangleF(0.0f, 0.0f, (float)charmapSize.Width, (float)charmapSize.Height));
             * gfx.Flush();
             * bmp.Save("charmap.png");*/

            int x = CHARMAP_PADDING, y = CHARMAP_PADDING, lineMaxHeight = 0;

            lineHeight = 0;
            Bitmap   bmp = new Bitmap(1, 1);
            Graphics gfx = Graphics.FromImage(bmp);

            for (int i = 0; i < 255; ++i)
            {
                if (!char.IsControl((char)i))
                {
                    Size charmapSize = gfx.MeasureString(new string((char)i, 1), font).ToSize();
                    charmapSize.Width  += CHARMAP_CHAR_SIZE_INFLATE;
                    charmapSize.Height += CHARMAP_CHAR_SIZE_INFLATE;
                    charBounds[i]       = new Rectangle(x, y, charmapSize.Width, charmapSize.Height);
                    x            += charmapSize.Width + CHARMAP_CHAR_DIST_INFLATE;
                    lineMaxHeight = Math.Max(lineMaxHeight, charmapSize.Height);

                    if (x > 1024)
                    {
                        y               += lineMaxHeight + CHARMAP_CHAR_DIST_INFLATE;
                        x                = CHARMAP_PADDING + charmapSize.Width + CHARMAP_CHAR_DIST_INFLATE;
                        lineHeight       = Math.Max(lineHeight, lineMaxHeight);
                        lineMaxHeight    = charmapSize.Height;
                        charBounds[i].X  = CHARMAP_PADDING;
                        charBounds[i].Y += lineMaxHeight;
                    }
                }
                else
                {
                    charBounds[i] = Rectangle.Empty;
                }
            }
            lineHeight = Math.Max(lineHeight, lineMaxHeight);

            blankWidth = (int)Math.Ceiling(gfx.MeasureString(" ", font).Width);

                        #if !DEBUG_GLFONT
                                #if SAVE_AND_LOAD_CHARMAPS
            string bmp_filename = "charmap_" + font.FontFamily.Name.Replace(" ", "") + "_" + font.Size + ".png";
            if (System.IO.File.Exists(bmp_filename))
            {
                bmp = (Bitmap)Bitmap.FromFile(bmp_filename);
            }
            else
                                #endif
            {
                        #endif
            bmp = new Bitmap(1024, y + lineMaxHeight);
            gfx = Graphics.FromImage(bmp);
                                #if DEBUG_GLFONT
            gfx.Clear(Color.Black);
                                #endif
            gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;                     // Do not use ClearType
            for (int i = 0; i < 255; ++i)
            {
                if (!char.IsControl((char)i))
                {
                    gfx.DrawString(new string((char)i, 1), font, Brushes.White, new RectangleF((float)charBounds[i].X - 1, (float)charBounds[i].Y - 2, (float)charBounds[i].Width, (float)charBounds[i].Height));
                }
            }
            gfx.Flush();
                        #if DEBUG_GLFONT
                                        #if SAVE_AND_LOAD_CHARMAPS
            bmp.Save("charmap_" + font.FontFamily.Name.Replace(" ", "") + "_" + font.Size + "_debug.png");
                                        #endif
                        #else
                                        #if SAVE_AND_LOAD_CHARMAPS
            bmp.Save("charmap_" + font.FontFamily.Name.Replace(" ", "") + "_" + font.Size + ".png");
                                        #endif
        }
                        #endif

            texture = new GLTexture2D("font", new GdiBitmap(bmp));
        }
示例#16
0
 public GLUniform(GLShader sdr, string name)
 {
     location = GL.GetUniformLocation(sdr.ShaderProgram, name);
     if(location < 0)
         throw new Exception("Uniform location '" + name + "' could not be resolved");
 }
示例#17
0
            public void Draw(Rectangle bounds, HashSet<int> selection, Size backbufferSize, GLShader sdr, int colorUniform)
            {
                float x, y;

                this.bounds = bounds;

                Matrix4 trans = Matrix4.Identity;
                trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f);

                sdr.Bind(trans);
                GL.Uniform4(colorUniform, BORDER_COLOR);
                meshBorders.Bind(sdr, null);
                meshBorders.Draw();

                GL.LineWidth(6.0f);
                if(selection != null)
                {
                    GL.Uniform4(colorUniform, SELECTION_COLOR);
                    meshSelection.Bind(sdr, null);
                    y = 0.0f;//(2.0f * bounds.Height - 4.0f) / backbufferSize.Height;
                    foreach(int xi in selection)
                    {
                        x = (float)(xi + 1) / (float)(numvalues + 1);
                        x *= 2.0f * bounds.Width / backbufferSize.Width;
                        sdr.Bind(trans * Matrix4.CreateTranslation(x, y, 0.0f));
                        meshSelection.Draw();
                    }
                }

                /*Point preSelectedTick;
                if(TickFromMousePosition(mousepos, backbufferSize, out preSelectedTick))
                {
                    GL.Uniform4(sdrColored_colorParam, PRESELECTION_COLOR);
                    if(preSelectedTick.X == -1)
                        for(preSelectedTick.X = 0; preSelectedTick.X < arguments[preSelectedTick.Y].values.Length; ++preSelectedTick.X)
                        {
                            x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                            sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                            meshSelection.Draw();
                        }
                    else
                    {
                        x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                        sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                        meshSelection.Draw();
                    }
                }*/

                GL.LineWidth(2.0f);
                sdr.Bind(trans);
                GL.Uniform4(colorUniform, TICK_COLOR);
                meshTicks.Bind(sdr, null);
                meshTicks.Draw();

                GL.LineWidth(1.0f);

                Vector2 strsize = Common.fontText.MeasureString(label);
                Common.fontText.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize);
                this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y);
            }
示例#18
0
		public void Init(GLWindow glcontrol, GLTextureStream.ReadImageMetaDataDelegate ReadImageMetaData)
		{
			this.glcontrol = glcontrol;
			glcontrol.GotFocus += (object sender, EventArgs e) => { glcontrol_focused = true; };
			glcontrol.LostFocus += (object sender, EventArgs e) => { glcontrol_focused = false; };
			glcontrol_focused = true;

			// Define actions
			SetViewControlAction = ActionManager.CreateAction("Set View Control", this, "SetViewControl");
			EnableDepthRenderingAction = ActionManager.CreateAction("Enable Depth Rendering", "enable depth", this, "EnableDepthRendering");
			DisableDepthRenderingAction = ActionManager.CreateAction("Disable Depth Rendering", "disable depth", this, "DisableDepthRendering");
			MoveAction = ActionManager.CreateAction("Move images", this, "Move");
			/*ActionManager.CreateAction("Select all", "all", this, "SelectAll");
			ActionManager.CreateAction("Select and focus all", "focus all", delegate(object[] parameters) {
				this.SelectAll();
				this.FocusSelection();
			});*/

			// Load shaders
			sdrAabb = new GLShader(new string[] {AABB_SHADER.VS}, new string[] {AABB_SHADER.FS});

			// Create mesh for non-depth rendering
#if USE_GS_QUAD
			mesh2D = new GLMesh(new Vector3[] {new Vector3(0.0f, 0.0f, 0.0f)}, null, null, null, null, null, PrimitiveType.Points); // Use this when rendering geometry shader quads
#else
			mesh2D = Common.meshQuad2;
#endif

			texstream = new GLTextureStream(256*1024*1024, ReadImageMetaData); // Optimize for 1GB of VRAM
			//texstream = new GLTextureStream(64*1024*1024, ReadImageMetaData); // Optimize for 256MB of VRAM
			//texstream = new GLTextureStream(8*1024*1024, ReadImageMetaData); // Optimize for 32MB of VRAM
			//texstream = new GLTextureStream(1024*1024, ReadImageMetaData); // Optimize for 4MB of VRAM
			//texstream = new GLTextureStream(128*1024, ReadImageMetaData); // Optimize for 512KB of VRAM

			#if USE_ARG_IDX
			argIndex.Bounds = new Rectangle(250, 10, Width - 250, 16);
			//argIndex.Bounds = new Rectangle(150, 10, Width - 150, 16);
			argIndex.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
			argIndex.Init();
			argIndex.SelectionChanged += SelectionChanged;//() => { SelectionChanged(); };
			//argIndex.ArgumentLabelMouseDown += ArgumentIndex_ArgumentLabelMouseDown;
			this.Controls.Add(argIndex);
			#endif

			#if USE_PARAM_IDX
			//paramIndex.Bounds = new Rectangle(200, 0, Width - 200, 16);
			//paramIndex.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
			paramIndex.Bounds = new Rectangle(16, 0, 300, 16);
			paramIndex.Anchor = AnchorStyles.Top | AnchorStyles.Right;
			paramIndex.Init();
			paramIndex.ParameterChanged += (Cinema.CinemaStore.Parameter parameter, int paramidx) => {
				foreach(TransformedImage image in images)
					image.OnParameterChanged(parameter, paramidx);
			};
			this.Controls.Add(paramIndex);
			#endif

			#if USE_CUSTOM_CONTROLS
			ccContainer.Bounds = new Rectangle(250, 10, Width - 300, 16);
			ccContainer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
			ccContainer.Init();
			/*ccContainer.CustomControlValueChanged += (int controlIdx, float value) => {
				//EDIT
			};*/
			this.Controls.Add(ccContainer);
			#endif

			colorTableMgr = new ColorTableManager(glcontrol);
			colorTableMgr.Visible = false;
			this.Controls.Add(colorTableMgr);

			coordsys = new CoordinateSystem();
			grid = new LineGrid();

			ContextMenu = new ImageContextMenu();

			fragmentcounter = GL.GenQuery();

//ccContainer.CreateSlider("testSlider", new float[] { 0.0f, 0.5f, 1.0f });
		}
示例#19
0
        public void Bind(GLShader shader, GLTexture texture = null, GLTexture texture2 = null, GLTexture texture3 = null, GLTexture texture4 = null)
        {
            if (posbuffer == -1)            // Mesh without vertex positions can't be rendered
            {
                return;
            }

            /*for(var i = 0; i < 16; i++)
             *      GL.DisableVertexAttribArray(i);
             *
             * GL.EnableVertexAttribArray(sdr.vertexPositionAttribute);*/
            GL.BindBuffer(BufferTarget.ArrayBuffer, posbuffer);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
            /*GL.VertexAttribPointer(sdr.vertexPositionAttribute, 3, VertexAttribType.Float, false, 0, 0);*/
            if (nmlbuffer != -1 /*&& sdr.vertexNormalAttribute != -1*/)
            {
                /*GL.EnableVertexAttribArray(sdr.vertexNormalAttribute);*/
                GL.BindBuffer(BufferTarget.ArrayBuffer, nmlbuffer);
                /*GL.VertexAttribPointer(sdr.vertexNormalAttribute, 3, gl.FLOAT, false, 0, 0);*/
            }

            /*if(tgtbuffer != -1 && sdr.vertexTangentAttribute != -1)
             * {
             *      GL.EnableVertexAttribArray(sdr.vertexTangentAttribute);
             *      GL.BindBuffer(BufferTarget.ArrayBuffer, tgtbuffer);
             *      GL.VertexAttribPointer(sdr.vertexTangentAttribute, 3, gl.FLOAT, false, 0, 0);
             * }
             * if(bnmbuffer != -1 && sdr.vertexBinormalAttribute != -1)
             * {
             *      GL.EnableVertexAttribArray(sdr.vertexBinormalAttribute);
             *      GL.BindBuffer(BufferTarget.ArrayBuffer, bnmbuffer);
             *      GL.VertexAttribPointer(sdr.vertexBinormalAttribute, 3, gl.FLOAT, false, 0, 0);
             * }*/
            if (texcoordbuffer != -1 && shader.defattrs.texcoord != -1)
            {
                GL.EnableVertexAttribArray(shader.defattrs.texcoord);
                GL.BindBuffer(BufferTarget.ArrayBuffer, texcoordbuffer);
                GL.VertexAttribPointer(shader.defattrs.texcoord, 2, VertexAttribPointerType.Float, false, 0, 0);
            }
            if (texture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture0);
                texture.Bind();
                if (shader != null)
                {
                    shader.SetTexture(0);
                }
            }
            if (texture2 != null)
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                texture2.Bind();
                if (shader != null)
                {
                    shader.SetTexture(1);
                }
            }
            if (texture3 != null)
            {
                GL.ActiveTexture(TextureUnit.Texture2);
                texture3.Bind();
                if (shader != null)
                {
                    shader.SetTexture(2);
                }
            }
            if (texture4 != null)
            {
                GL.ActiveTexture(TextureUnit.Texture3);
                texture4.Bind();
                if (shader != null)
                {
                    shader.SetTexture(3);
                }
            }
            if (idxbuffer != -1)
            {
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, idxbuffer);
            }
        }
            public void Draw(Rectangle bounds, int argidx, Size backbufferSize, GLShader sdr, int colorUniform)
            {
                float x, y;

                this.bounds = bounds;

                Matrix4 trans = Matrix4.Identity;
                trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f);

                sdr.Bind(trans);
                GL.Uniform4(colorUniform, BORDER_COLOR);
                meshBorders.Bind(sdr, null);
                meshBorders.Draw();

                GL.Uniform4(colorUniform, SLIDER_COLOR);
                meshSlider.Bind(sdr, null);
                y = 0.0f;//(2.0f * bounds.Height - 4.0f) / backbufferSize.Height;
                //int xi = 0;
                float sliderWidth = 20.0f;

                //x = (float)(xi + 1) / (float)(values.Length + 1);
                x = (currentValue - minValue) / valueRange;
                x *= (2.0f * bounds.Width) / backbufferSize.Width;
                x = (sliderWidth + x * (bounds.Width - sliderWidth)) / bounds.Width;
                sdr.Bind(Matrix4.CreateScale(sliderWidth / (2.0f * bounds.Width), 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f));
                meshSlider.Draw();

                GL.LineWidth(2.0f);
                sdr.Bind(trans);
                GL.Uniform4(colorUniform, TICK_COLOR);
                meshTick.Bind(sdr, null);

                for(int i = 0; i < values.Length; ++i)
                {
                    //x = (float)(i + 1) / (float)(values.Length + 1);
                    x = (values[i] - minValue) / valueRange;
                    sdr.Bind(trans * Matrix4.CreateTranslation((x * 2.0f * (bounds.Width - sliderWidth) + sliderWidth) / backbufferSize.Width, 0.0f, 0.0f));
                    meshTick.Draw();
                }

                GL.LineWidth(1.0f);

                Vector2 strsize = Common.fontText2.MeasureString(label);
                Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize);
                this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y);
            }
示例#21
0
            public void Draw(Rectangle bounds, Selection selection, Size backbufferSize, GLShader sdr, int colorUniform)
            {
                float x, y;

                this.bounds = bounds;

                Matrix4 trans = Matrix4.Identity;

                trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f);

                sdr.Bind(trans);
                GL.Uniform4(colorUniform, BORDER_COLOR);
                meshBorders.Bind(sdr, null);
                meshBorders.Draw();

                if (selection != null)
                {
                    GL.Uniform4(colorUniform, SELECTION_COLOR);
                    meshSelection.Bind(sdr, null);
                    y = 0.0f;                    //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height;
                    foreach (TransformedImage selectedimage in selection)
                    {
                        /*int xi = -1;
                         * for(int i = 0; i < selectedimage.args.Length; ++i)
                         *      if(selectedimage.args[i] == Global.arguments[argidx])
                         *      {
                         *              xi = Array.IndexOf(selectedimage.args[i].values, selectedimage.values[i]);
                         *              break;
                         *      }
                         * if(xi == -1)
                         *      continue;*/

                        if (selectedimage.globalargindices.Length <= argidx || selectedimage.globalargindices[argidx] == -1)
                        {
                            continue;
                        }
                        int xi = Array.IndexOf(Global.arguments[argidx].values, selectedimage.values[selectedimage.globalargindices[argidx]]);
                        if (xi == -1)
                        {
                            continue;
                        }

                        /*if(selectedimage.args.Length <= argidx)
                         *      continue;
                         * int xi = Array.IndexOf(selectedimage.args[argidx].values, selectedimage.values[argidx]);*/

                        float halfwidth = argument.strValues.Length <= MAX_NUM_ARGS_SHOWING_VALUES?Common.fontTextSmall.MeasureString(argument.strValues[xi]).X / 2.0f + 2.0f : 3.0f;

                        x  = (float)(xi + 1) / (float)(argument.strValues.Length + 1);
                        x *= 2.0f * bounds.Width / backbufferSize.Width;
                        sdr.Bind(Matrix4.CreateScale(halfwidth / bounds.Width, 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f));
                        meshSelection.Draw();
                    }
                }

                /*Point preSelectedTick;
                 * if(TickFromMousePosition(mousepos, backbufferSize, out preSelectedTick))
                 * {
                 *      GL.Uniform4(sdrColored_colorParam, PRESELECTION_COLOR);
                 *      if(preSelectedTick.X == -1)
                 *              for(preSelectedTick.X = 0; preSelectedTick.X < arguments[preSelectedTick.Y].values.Length; ++preSelectedTick.X)
                 *              {
                 *                      x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                 *                      sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                 *                      meshSelection.Draw();
                 *              }
                 *      else
                 *      {
                 *              x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1);
                 *              sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f));
                 *              meshSelection.Draw();
                 *      }
                 * }*/

                if (argument.strValues.Length > MAX_NUM_ARGS_SHOWING_VALUES)
                {
                    GL.LineWidth(2.0f);
                    sdr.Bind(trans);
                    GL.Uniform4(colorUniform, TICK_COLOR);
                    meshTick.Bind(sdr, null);

                    for (int i = 0; i < argument.strValues.Length; ++i)
                    {
                        //x = (float)(i + 1) / (float)(argument.strValues.Length + 1);
                        x = argument.values[i] / 10.0f;
                        sdr.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, 0.0f, 0.0f));
                        meshTick.Draw();
                    }
                }
                else
                {
                    y = bounds.Bottom - Common.fontTextSmall.MeasureString(" ").Y + 2.0f;
                    for (int i = 0; i < argument.values.Length; ++i)
                    {
                        x = (float)(i + 1) / (float)(argument.strValues.Length + 1);
                        Common.fontTextSmall.DrawString(bounds.Left + x * bounds.Width - Common.fontTextSmall.MeasureString(argument.strValues[i]).X / 2.0f, y, argument.strValues[i], backbufferSize);
                    }
                }

                GL.LineWidth(1.0f);

                Vector2 strsize = Common.fontText2.MeasureString(label);

                Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize);
                this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y);
            }
示例#22
0
		public GLTextFont(string filename, Vector2 charsize, GLMesh meshquad)
		{
			this.texture = GLTexture2D.FromFile(filename);
			this.charsize = charsize;
			this.meshquad = meshquad;

			if(fontshader == null)
			{
				fontshader = new GLShader(new string[] { FONT_SHADER.VS }, new string[] { FONT_SHADER.FS });
				fontshader_coloruniform = fontshader.GetUniformLocation("Color");
			}
		}
示例#23
0
		public void Free()
		{
			if(texstream != null)
			{
				texstream.Free();
				texstream = null;
			}
			sdrAabb = null;
			if(mesh2D != null)
				mesh2D.Free();
			mesh2D = null;
			if(colorTableMgr != null)
			{
				//colorTableMgr.Free();
				colorTableMgr = null;
			}
		}
示例#24
0
		public GLTextFont2(Font font)
		{
			if(fontshader == null)
			{
				fontshader = new GLShader(new string[] { FONT_SHADER.VS }, new string[] { FONT_SHADER.FS });
				fontshader_coloruniform = fontshader.GetUniformLocation("Color");
			}

			/*string charmap = "";
			for(int i = 0; i < 255; ++i)
				if(!char.IsControl((char)i))
				charmap += (char)i;

			Bitmap bmp = new Bitmap(1, 1);
			Graphics gfx = Graphics.FromImage(bmp);
			Size charmapSize = gfx.MeasureString(charmap, font, 1024).ToSize();
			bmp = new Bitmap(charmapSize.Width, charmapSize.Height);
			gfx = Graphics.FromImage(bmp);
			gfx.DrawString(charmap, font, Brushes.White, new RectangleF(0.0f, 0.0f, (float)charmapSize.Width, (float)charmapSize.Height));
			gfx.Flush();
			bmp.Save("charmap.png");*/

			int x = CHARMAP_PADDING, y = CHARMAP_PADDING, lineMaxHeight = 0;
			lineHeight = 0;
			Bitmap bmp = new Bitmap(1, 1);
			Graphics gfx = Graphics.FromImage(bmp);
			for(int i = 0; i < 255; ++i)
				if(!char.IsControl((char)i))
				{
					Size charmapSize = gfx.MeasureString(new string((char)i, 1), font).ToSize();
					charmapSize.Width += CHARMAP_CHAR_SIZE_INFLATE;
					charmapSize.Height += CHARMAP_CHAR_SIZE_INFLATE;
					charBounds[i] = new Rectangle(x, y, charmapSize.Width, charmapSize.Height);
					x += charmapSize.Width + CHARMAP_CHAR_DIST_INFLATE;
					lineMaxHeight = Math.Max(lineMaxHeight, charmapSize.Height);

					if(x > 1024)
					{
						y += lineMaxHeight + CHARMAP_CHAR_DIST_INFLATE;
						x = CHARMAP_PADDING + charmapSize.Width + CHARMAP_CHAR_DIST_INFLATE;
						lineHeight = Math.Max(lineHeight, lineMaxHeight);
						lineMaxHeight = charmapSize.Height;
						charBounds[i].X = CHARMAP_PADDING;
						charBounds[i].Y += lineMaxHeight;
					}
				}
				else
					charBounds[i] = Rectangle.Empty;
			lineHeight = Math.Max(lineHeight, lineMaxHeight);

			blankWidth = (int)Math.Ceiling(gfx.MeasureString(" ", font).Width);

			#if !DEBUG_GLFONT
				#if SAVE_AND_LOAD_CHARMAPS
				string bmp_filename = "charmap_" + font.FontFamily.Name.Replace(" ", "") + "_" + font.Size + ".png";
				if(System.IO.File.Exists(bmp_filename))
					bmp = (Bitmap)Bitmap.FromFile(bmp_filename);
				else
				#endif
			{
			#endif
				bmp = new Bitmap(1024, y + lineMaxHeight);
				gfx = Graphics.FromImage(bmp);
				#if DEBUG_GLFONT
				gfx.Clear(Color.Black);
				#endif
				gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // Do not use ClearType
				for(int i = 0; i < 255; ++i)
					if(!char.IsControl((char)i))
						gfx.DrawString(new string((char)i, 1), font, Brushes.White, new RectangleF((float)charBounds[i].X - 1, (float)charBounds[i].Y - 2, (float)charBounds[i].Width, (float)charBounds[i].Height));
				gfx.Flush();
			#if DEBUG_GLFONT
					#if SAVE_AND_LOAD_CHARMAPS
					bmp.Save("charmap_" + font.FontFamily.Name.Replace(" ", "") + "_" + font.Size + "_debug.png");
					#endif
			#else
					#if SAVE_AND_LOAD_CHARMAPS
					bmp.Save("charmap_" + font.FontFamily.Name.Replace(" ", "") + "_" + font.Size + ".png");
					#endif
				}
			#endif

			texture = new GLTexture2D("font", new GdiBitmap(bmp));
		}
示例#25
0
        public void Load(Cinema.CinemaArgument[] arguments, Dictionary<string, HashSet<object>> valuerange)
        {
            this.arguments = arguments;

            // Create selection array and populate it with the default values
            selection = new Selection(arguments.Length, valuerange.Count, images);
            for(int i = 0; i < arguments.Length; ++i)
            {
                if(arguments[i].defaultValue != null)
                    selection[i].Add(Array.IndexOf(arguments[i].values, arguments[i].defaultValue));
            }

            // Load shader
            sdrColored = new GLShader(new string[] {ARGUMENT_INDEX_SHADER.VS}, new string[] {ARGUMENT_INDEX_SHADER.FS});
            sdrColored_colorParam = sdrColored.GetUniformLocation("Color");
            sdrColored.Bind();

            meshSelection = new GLMesh(new Vector3[] {new Vector3(0.0f, -0.1f, 0.0f), new Vector3(0.0f, 1.15f, 0.0f)}, null, null, null, null, null, PrimitiveType.Lines);

            // Create track bars for each argument
            foreach(Cinema.CinemaArgument argument in arguments)
            {
                TrackBar newtrackbar = new TrackBar(argument.values.Length, meshSelection);
                newtrackbar.label = argument.label;
                trackbars.Add(newtrackbar);
            }

            // Create track bars for meta data value
            foreach(KeyValuePair<string, HashSet<object>> range in valuerange)
            {
                TrackBar newtrackbar = new TrackBar(range.Value.Count, meshSelection);
                newtrackbar.label = range.Key;
                trackbars.Add(newtrackbar);
            }

            argumentLabelBounds = new Rectangle[arguments.Length];
        }
示例#26
0
		public GLNumberFont(string filename, FontDefinition fontDefinition, GLMesh meshquad, bool isFixedWidth)
		{
			this.texture = GLTexture2D.FromFile(filename);
			this.fontdef = fontDefinition;
			this.meshquad = meshquad;
			this.fixedwidth = /*isFixedWidth ? fontdef[0][10] / 10 :*/ 0;

			if(fontshader == null)
			{
				fontshader = new GLShader(new string[] { FONT_SHADER.VS }, new string[] { FONT_SHADER.FS });
				fontshader_coloruniform = fontshader.GetUniformLocation("Color");
			}
		}
示例#27
0
 public GLUniformVector3(GLShader sdr, string name)
     : base(sdr, name)
 {
 }
示例#28
0
        public void Bind(GLShader shader, GLTexture texture = null, GLTexture texture2 = null, GLTexture texture3 = null, GLTexture texture4 = null)
        {
            if(posbuffer == -1) // Mesh without vertex positions can't be rendered
                return;

            /*for(var i = 0; i < 16; i++)
                GL.DisableVertexAttribArray(i);

            GL.EnableVertexAttribArray(sdr.vertexPositionAttribute);*/
            GL.BindBuffer(BufferTarget.ArrayBuffer, posbuffer);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
            /*GL.VertexAttribPointer(sdr.vertexPositionAttribute, 3, VertexAttribType.Float, false, 0, 0);*/
            if(nmlbuffer != -1 /*&& sdr.vertexNormalAttribute != -1*/)
            {
                /*GL.EnableVertexAttribArray(sdr.vertexNormalAttribute);*/
                GL.BindBuffer(BufferTarget.ArrayBuffer, nmlbuffer);
                /*GL.VertexAttribPointer(sdr.vertexNormalAttribute, 3, gl.FLOAT, false, 0, 0);*/
            }
            /*if(tgtbuffer != -1 && sdr.vertexTangentAttribute != -1)
            {
                GL.EnableVertexAttribArray(sdr.vertexTangentAttribute);
                GL.BindBuffer(BufferTarget.ArrayBuffer, tgtbuffer);
                GL.VertexAttribPointer(sdr.vertexTangentAttribute, 3, gl.FLOAT, false, 0, 0);
            }
            if(bnmbuffer != -1 && sdr.vertexBinormalAttribute != -1)
            {
                GL.EnableVertexAttribArray(sdr.vertexBinormalAttribute);
                GL.BindBuffer(BufferTarget.ArrayBuffer, bnmbuffer);
                GL.VertexAttribPointer(sdr.vertexBinormalAttribute, 3, gl.FLOAT, false, 0, 0);
            }*/
            if(texcoordbuffer != -1 && shader.defattrs.texcoord != -1)
            {
                GL.EnableVertexAttribArray(shader.defattrs.texcoord);
                GL.BindBuffer(BufferTarget.ArrayBuffer, texcoordbuffer);
                GL.VertexAttribPointer(shader.defattrs.texcoord, 2, VertexAttribPointerType.Float, false, 0, 0);
            }
            if(texture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture0);
                texture.Bind();
                if(shader != null)
                    shader.SetTexture(0);
            }
            if(texture2 != null)
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                texture2.Bind();
                if(shader != null)
                    shader.SetTexture(1);
            }
            if(texture3 != null)
            {
                GL.ActiveTexture(TextureUnit.Texture2);
                texture3.Bind();
                if(shader != null)
                    shader.SetTexture(2);
            }
            if(texture4 != null)
            {
                GL.ActiveTexture(TextureUnit.Texture3);
                texture4.Bind();
                if(shader != null)
                    shader.SetTexture(3);
            }
            if(idxbuffer != -1)
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, idxbuffer);
        }