Exemple #1
0
        private void glCanvas1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 'b')
            {
                BlendingSourceFactor      source;
                BlendingDestinationFactor dest;
                this.blendFactorHelper.GetNext(out source, out dest);
                this.glText.BlendSwitch.SourceFactor = source;
                this.glText.BlendSwitch.DestFactor   = dest;
                this.UpdateLabel();
            }
            else if (e.KeyChar == 'o')
            {
                if (this.openTextureDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string ttfFilename = this.openTextureDlg.FileName;
                    this.glText.Dispose();
                    FontResource fontResouce = FontResource.Load(ttfFilename, ' ', (char)126);
                    var          glText      = new GLText(AnchorStyles.Left | AnchorStyles.Top,
                                                          new Padding(3, 3, 3, 3), new Size(850, 50), -100, 100, fontResouce);
                    glText.Initialize();
                    glText.SwitchList.Add(new ClearColorSwitch());// show black back color to indicate glText's area.
                    glText.SetText("The quick brown fox jumps over the lazy dog!");
                    this.glText = glText;

                    uiRoot.Controls.Add(glText);

                    this.formPropertyGrid.DisplayObject(glText);
                }
            }
        }
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            mainfont.space = (float)numericUpDown1.Value;

            GLText t = tobs[0];

            tobs.RemoveAt(0);
            tobs.Add(mainfont.renderText(t.text, t.pos, t.scale));

            glControl1.Invalidate();
        }
        private void Form02OrderIndependentTransparency_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                camera.Position = new vec3(0, 0, 1);
                camera.Target   = new vec3(0, 0, 0);
                camera.UpVector = new vec3(0, 1, 0);
                var rotator = new SatelliteRotator(camera);
                this.camera  = camera;
                this.rotator = rotator;
            }
            {
                var UIRoot = new GLControl(this.glCanvas1.Size, -100, 100);
                UIRoot.Initialize();
                this.uiRoot = UIRoot;

                var glAxis = new GLAxis(AnchorStyles.Right | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100);
                glAxis.Initialize();
                this.glAxis = glAxis;

                UIRoot.Controls.Add(glAxis);

                var glText = new GLText(AnchorStyles.Left | AnchorStyles.Top,
                                        new Padding(3, 3, 3, 3), new Size(500, 50), -100, 100);
                glText.Initialize();
                glText.SwitchList.Add(new ClearColorSwitch());// show black back color to indicate glText's area.
                glText.SetText("The quick brown fox jumps over the lazy dog!");
                this.glText = glText;

                uiRoot.Controls.Add(glText);

                this.UpdateLabel();
            }
            {
                var frmPropertyGrid = new FormProperyGrid();
                frmPropertyGrid.DisplayObject(this.glText);
                frmPropertyGrid.Show();
                this.formPropertyGrid = frmPropertyGrid;
            }
        }
    public GLText renderText(string text, Vector2 pos, float scale)
    {
        /*
         * THIS FUNCTION WILL IMPLEMENT TEXT RENDERING
         *
         */
        float space  = this.space;
        float width  = this.width;
        float height = this.height;

        //Check if font exists
        if (this == null)
        {
            return(null);
        }

        //Create text objects
        GLText gtex = new GLText();

        //Save text
        gtex.text  = text;
        gtex.pos   = pos;
        gtex.scale = scale;
        //Load Image & Program
        gtex.GLImage = tex;
        gtex.program = program;
        //Allocate arrays
        gtex.pints  = new int[text.Length * 6];
        gtex.puvs   = new float[text.Length * 6 * 2];
        gtex.pverts = new float[text.Length * 6 * 3];

        //Construct float arrays
        float startx  = 0.0f;
        float startid = 0;

        for (int i = 0; i < text.Length; i++)
        {
            char  c    = text[i];
            Glyph glph = this.char_dict[c];
            //Store a quad for every char

            //Handle positions
            // 0
            gtex.pverts[6 * 3 * i + 0] = i * space + 0.0f;
            gtex.pverts[6 * 3 * i + 1] = height;
            gtex.pverts[6 * 3 * i + 2] = 0.2f;
            // 1
            gtex.pverts[6 * 3 * i + 3] = i * space + 0.0f;
            gtex.pverts[6 * 3 * i + 4] = 0.0f;
            gtex.pverts[6 * 3 * i + 5] = 0.2f;
            // 2
            gtex.pverts[6 * 3 * i + 6] = i * space + width;
            gtex.pverts[6 * 3 * i + 7] = height;
            gtex.pverts[6 * 3 * i + 8] = 0.2f;
            // 3
            gtex.pverts[6 * 3 * i + 9]  = i * space + width;
            gtex.pverts[6 * 3 * i + 10] = height;
            gtex.pverts[6 * 3 * i + 11] = 0.2f;
            // 4
            gtex.pverts[6 * 3 * i + 12] = i * space + 0.0f;
            gtex.pverts[6 * 3 * i + 13] = 0.0f;
            gtex.pverts[6 * 3 * i + 14] = 0.2f;
            // 5
            gtex.pverts[6 * 3 * i + 15] = i * space + width;
            gtex.pverts[6 * 3 * i + 16] = 0.0f;
            gtex.pverts[6 * 3 * i + 17] = 0.2f;


            //Handle Indices
            gtex.pints[6 * i + 0] = 4 * i + 0;
            gtex.pints[6 * i + 1] = 4 * i + 1;
            gtex.pints[6 * i + 2] = 4 * i + 2;
            gtex.pints[6 * i + 3] = 4 * i + 3;
            gtex.pints[6 * i + 4] = 4 * i + 4;
            gtex.pints[6 * i + 5] = 4 * i + 5;

            //Handle Uvs
            //0
            gtex.puvs[6 * 2 * i + 0] = glph.pos[0].X;
            gtex.puvs[6 * 2 * i + 1] = glph.pos[0].Y;
            //1
            gtex.puvs[6 * 2 * i + 2] = glph.pos[0].X;
            gtex.puvs[6 * 2 * i + 3] = glph.pos[1].Y;
            //2
            gtex.puvs[6 * 2 * i + 4] = glph.pos[1].X;
            gtex.puvs[6 * 2 * i + 5] = glph.pos[0].Y;
            //3
            gtex.puvs[6 * 2 * i + 6] = glph.pos[1].X;
            gtex.puvs[6 * 2 * i + 7] = glph.pos[0].Y;
            //4
            gtex.puvs[6 * 2 * i + 8] = glph.pos[0].X;
            gtex.puvs[6 * 2 * i + 9] = glph.pos[1].Y;
            //5
            gtex.puvs[6 * 2 * i + 10] = glph.pos[1].X;
            gtex.puvs[6 * 2 * i + 11] = glph.pos[1].Y;
        }

        //Create OpenGL buffers

        //Generate Geometry VBOs
        GL.GenBuffers(1, out gtex.vbo);
        GL.GenBuffers(1, out gtex.ebo);
        GL.GenBuffers(1, out gtex.uvbo);

        //Vertex Buffer
        int vsize = sizeof(float) * gtex.pverts.Length;

        //Upload vertex buffer
        GL.BindBuffer(BufferTarget.ArrayBuffer, gtex.vbo);
        //Allocate to NULL
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vsize), (IntPtr)null, BufferUsageHint.StaticDraw);
        //Add verts data
        GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)vsize, gtex.pverts);

        //UV Buffer
        int uvsize = sizeof(float) * gtex.puvs.Length;

        //Upload uv buffer
        GL.BindBuffer(BufferTarget.ArrayBuffer, gtex.uvbo);
        //Allocate to NULL
        GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(uvsize), (IntPtr)null, BufferUsageHint.StaticDraw);
        //Add verts data
        GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)uvsize, gtex.puvs);

        //Upload index buffer
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, gtex.ebo);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(sizeof(int) * gtex.pints.Length), gtex.pints, BufferUsageHint.StaticDraw);

        //Store text object
        return(gtex);
    }