Ejemplo n.º 1
0
        private void OpenGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
        {
            //  Get the OpenGL instance.
            var gl = args.OpenGL;

            //  Add a bit to theta (how much we're rotating the scene) and create the modelview
            //  and normal matrices.
            theta += 0.01f;
            scene.CreateModelviewAndNormalMatrix(theta);

            //  Clear the color and depth buffer.
            gl.ClearColor(0f, 0f, 0f, 1f);
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            //  Render the scene in either immediate or retained mode.
            switch (comboRenderMode.SelectedIndex)
            {
                case 0:
                    {
                        scene.RenderRetainedMode(gl, checkBoxUseToonShader.IsChecked.Value); break;
                    }
                case 1:
                    {
                        axies.Render(gl, RenderMode.Design);
                        scene.RenderImmediateMode(gl);
                        break;
                    }
            }
        }
Ejemplo n.º 2
0
        private void OpenGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
        {
            OpenGL gl = args.OpenGL;

            //  Initialise the scene.
            scene.Initialise(gl);
        }
Ejemplo n.º 3
0
        private void OpenGLControl_Resized(object sender, OpenGLEventArgs args)
        {
            //  Get the OpenGL instance.
            var gl = args.OpenGL;

            //  Create the projection matrix for the screen size.
            scene.CreateProjectionMatrix(gl, (float)ActualWidth, (float)ActualHeight);
        }
Ejemplo n.º 4
0
        private void OpenGL_Resize(object sender, OpenGLEventArgs args)
        {
            const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;

            projectionMatrix = glm.perspective(rads, (float)(openGLControl.ActualWidth / openGLControl.ActualHeight), 0.1f, 100.0f);
        }
Ejemplo n.º 5
0
 private void OpenGLControl_OnOpenGLInitialized(object sender, OpenGLEventArgs args)
 {
     args.OpenGL.Enable(OpenGL.GL_DEPTH_TEST);
 }
Ejemplo n.º 6
0
        private void OpenGL_Initialize(object sender, OpenGLEventArgs args)
        {
            openGLControl.OpenGLVersion = SharpGL.Version.OpenGLVersion.OpenGL3_3;
            OpenGL gl = openGLControl.OpenGL;

            vao = new VertexBufferArray();
            vao.Create(gl);
            vao.Bind(gl);

            vbo = new VertexBuffer();
            vbo.Create(gl);
            vbo.Bind(gl);

            gl.EnableVertexAttribArray(0);
            gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, 8 * 4, new System.IntPtr(0));
            gl.EnableVertexAttribArray(1);
            gl.VertexAttribPointer(1, 2, OpenGL.GL_FLOAT, false, 8 * 4, new System.IntPtr(12));
            gl.EnableVertexAttribArray(2);
            gl.VertexAttribPointer(2, 3, OpenGL.GL_FLOAT, false, 8 * 4, new System.IntPtr(20));

            gl.BindVertexArray(0);

            string vertexShaderSource =
                @"
                    #version 410

                    layout (location = 0) in vec3 in_position;
                    layout (location = 1) in vec2 in_uv;
                    layout (location = 2) in vec3 in_normal;

                    uniform mat4 mvp;
                    uniform mat4 m;

                    out vec3 normal;
                    out vec2 uv;

                    void main()
                    {
                        gl_Position = mvp * vec4(in_position, 1.0);
                        normal = (m * vec4(in_normal, 0.0)).xyz;
                        uv = in_uv;
                    }
                ";
            string fragmentShaderSource =
                @"
                    #version 410

                    layout (location = 0) out vec4 out_color;

                    in vec3 normal;
                    in vec2 uv;

                    void main()
                    {
                        out_color = vec4(1, 0, 0, 1);
                        if (length(normal) > 0.0)
                        {
                            out_color = vec4(abs(normal), 1);
                        }
                    }
                ";

            shader = new ShaderProgram();
            try
            {
                shader.Create(gl, vertexShaderSource, fragmentShaderSource, null);
            }
            catch (ShaderCompilationException e)
            {
                string error   = e.CompilerOutput;
                string message = e.Message;
            }

            const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;

            projectionMatrix = glm.perspective(rads, (float)(openGLControl.ActualWidth / openGLControl.ActualHeight), 0.1f, 100.0f);

            modelMatrix = mat4.identity();

            cameraPos  = new vec3(0.0f, 0.0f, 5.0f);
            viewMatrix = glm.lookAt(cameraPos, new vec3(0f), new vec3(0f, 1f, 0f));

            lastMousePos = new Point(-1, -1);

            gl.PointSize(5f);
            gl.ClearColor(0.2f, 0.3f, 0.8f, 1);
        }
Ejemplo n.º 7
0
 private void OpenGLControl_Resized(object sender, OpenGLEventArgs args)
 {
     _GL = args.OpenGL;
     InitialiseRenderer();
 }
Ejemplo n.º 8
0
        private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
        {
            OpenGL gl = openGLControl.OpenGL;

            gl.LookAt(-2, 0, 0, 0, 0, 0, 0, 1, 0);

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.PushMatrix();

            gl.LoadIdentity();

            gl.Translate(scale, position, 0);

            gl.Rotate(Angle, 0.0f, 0.0f, 2.0f);
            gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);

            gl.Color(0.5, 0.5, 0.6);
            Set(gl, 0, 0, 0, 0.3);

            Set(gl, 0, -0.1, -0.2, 0.1);
            Set(gl, 0, 0.1, 0, 0.1);

            Set(gl, 0, -0.1, 0.4, 0.1);
            Set(gl, 0, 0.1, 0, 0.1);

            Set(gl, -0.2, -0.1, -0.2, 0.1);
            Set(gl, 0, 0.1, 0, 0.1);

            Set(gl, 0.4, -0.1, 0, 0.1);
            Set(gl, 0, 0.1, 0, 0.1);

            Set(gl, -0.2, 0.2, 0, 0.1);

            if (Key1 == 0)
            {
                gl.Color(0.8, 0.4, 0.8);
                Set(gl, 0, 0.1, 0, 0.05);
                gl.Color(0.9, 0.3, 0.2);
                Set(gl, 0.2, -0.2, 0, 0.05);
                gl.Color(0.2, 0.9, 0.3);
                Set(gl, -0.2, 0, 0.2, 0.05);
                gl.Color(0.3, 0.2, 0.9);
                Set(gl, 0, 0, -0.4, 0.05);
                gl.Color(0.8, 0.7, 0.2);
                Set(gl, -0.2, 0, 0.2, 0.05);
                gl.Translate(0.2, 0.2, 0);
            }
            else
            {
                gl.Translate(0, 0.1, 0);
            }

            if (Count >= 1)
            {
                if (control == 1)
                {
                    control  = 0;
                    Temp     = 1;
                    iter1    = 1;
                    iter2    = 1;
                    Key1     = 0;
                    MainKey1 = 0;
                    MainKey2 = 0;

                    Random random = new Random();
                    for (int i = 0; i < 100; i++)
                    {
                        ColorArray1[i, 0] = (int)random.Next(255, 705);
                        ColorArray1[i, 1] = (int)random.Next(255, 705);
                        ColorArray1[i, 2] = (int)random.Next(255, 705);
                    }
                }

                if (31 == iter1)
                {
                    iter1    = 1;
                    MainKey1 = 1;
                    MainKey2 = 0;
                    Temp     = 1;
                }
                else if (Count <= (int)iter2)
                {
                    iter2    = 1;
                    MainKey2 = 1;
                    MainKey1 = 0;
                    Temp     = 1;
                }

                if (MainKey1 == 0)
                {
                    gl.Translate(-0.2, -0.2, 0);
                    Act_1(gl, (int)Temp, iter1);
                    if ((int)Temp < 31)
                    {
                        Temp += 1;
                    }
                }
                else if (MainKey2 == 0 && MainKey1 == 1)
                {
                    gl.Translate(0, (0.025 * 28) - 0.2, 0);
                    Act_2(gl, (int)Temp, (int)iter2);
                    if ((int)Temp < Count)
                    {
                        Temp += 1;
                    }
                }
            }

            gl.PopMatrix();
            gl.Flush();

            rotation += Speed;
        }
Ejemplo n.º 9
0
 private void AudioScopeInitialized1(object sender, OpenGLEventArgs args)
 {
 }
Ejemplo n.º 10
0
 private void SharpglCtrl_OnOpenGLDraw(object sender, OpenGLEventArgs args)
 {
     _logger.Trace("SharpglCtrl_OnOpenGLDraw");
 }
Ejemplo n.º 11
0
        private void OpenGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
        {
            OpenGL gl = args.OpenGL;

            //  Clear the color and depth buffers.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Reset the modelview matrix.
            gl.LoadIdentity();

            //  Move the geometry into a fairly central position.
            gl.Translate(0, 0.0f, -2f);

            //  Draw a pyramid. First, rotate the modelview matrix.
            gl.Rotate(-60f, 1.0f, 0.0f, 0.0f);
            gl.Rotate(rotatePyramid, 0.0f, 0.0f, 1.0f);

            //  Start drawing triangles.
            int xSize = 50;
            int ySize = 50;

            //gl.Begin(OpenGL.GL_QUADS);

            float z = 0.001f;
            float k = 0.6f;

            //int counter = 0;

            for (int x = 0; x < xSize - 1; x++)
            {
                for (int y = 0; y < ySize - 1; y++)
                {
                    var c      = GetColor(resultsMap[x, y]);
                    var center = Center(Center(resultsMap[x, y], resultsMap[x + 1, y + 1]), Center(resultsMap[x + 1, y], resultsMap[x, y + 1]));

                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);

                    gl.Begin(OpenGL.GL_TRIANGLES);

                    c = GetColor(resultsMap[x, y]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x, y].X - 0.5f, resultsMap[x, y].Y - 0.5f, resultsMap[x, y].Z * k);

                    c = GetColor(resultsMap[x + 1, y]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x + 1, y].X - 0.5f, resultsMap[x + 1, y].Y - 0.5f, resultsMap[x + 1, y].Z * k);

                    c = GetColor(center);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k);

                    c = GetColor(resultsMap[x + 1, y]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x + 1, y].X - 0.5f, resultsMap[x + 1, y].Y - 0.5f, resultsMap[x + 1, y].Z * k);

                    c = GetColor(resultsMap[x + 1, y + 1]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x + 1, y + 1].X - 0.5f, resultsMap[x + 1, y + 1].Y - 0.5f, resultsMap[x + 1, y + 1].Z * k);

                    c = GetColor(center);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k);

                    c = GetColor(resultsMap[x + 1, y + 1]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x + 1, y + 1].X - 0.5f, resultsMap[x + 1, y + 1].Y - 0.5f, resultsMap[x + 1, y + 1].Z * k);

                    c = GetColor(resultsMap[x, y + 1]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x, y + 1].X - 0.5f, resultsMap[x, y + 1].Y - 0.5f, resultsMap[x, y + 1].Z * k);

                    c = GetColor(center);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k);

                    c = GetColor(resultsMap[x, y + 1]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x, y + 1].X - 0.5f, resultsMap[x, y + 1].Y - 0.5f, resultsMap[x, y + 1].Z * k);

                    c = GetColor(resultsMap[x, y]);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(resultsMap[x, y].X - 0.5f, resultsMap[x, y].Y - 0.5f, resultsMap[x, y].Z * k);

                    c = GetColor(center);
                    gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k);

                    gl.End();

                    gl.Color(0.1f, 0.1f, 0.1f);
                    gl.Begin(OpenGL.GL_LINES);
                    gl.Vertex(resultsMap[x, y].X - 0.5f, resultsMap[x, y].Y - 0.5f, resultsMap[x, y].Z * k + z);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k + z);


                    gl.Vertex(resultsMap[x + 1, y].X - 0.5f, resultsMap[x + 1, y].Y - 0.5f, resultsMap[x + 1, y].Z * k + z);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k + z);

                    gl.Vertex(resultsMap[x + 1, y + 1].X - 0.5f, resultsMap[x + 1, y + 1].Y - 0.5f, resultsMap[x + 1, y + 1].Z * k + z);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k + z);

                    gl.Vertex(resultsMap[x, y + 1].X - 0.5f, resultsMap[x, y + 1].Y - 0.5f, resultsMap[x, y + 1].Z * k + z);
                    gl.Vertex(center.X - 0.5f, center.Y - 0.5f, center.Z * k + z);

                    gl.End();
                    //counter = (counter + 1) % 4;

                    //gl.Vertex(resultsMap[x, y].X - 0.5f, resultsMap[x, y].Y - 0.5f, resultsMap[x, y].Z * k);

                    ////c = GetColor(resultsMap[x + 1, y]);
                    ////gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    //gl.Vertex(resultsMap[x + 1, y].X - 0.5f, resultsMap[x + 1, y].Y - 0.5f, resultsMap[x + 1, y].Z * k);

                    ////c = GetColor(resultsMap[x + 1, y + 1]);
                    ////gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    //gl.Vertex(resultsMap[x + 1, y + 1].X - 0.5f, resultsMap[x + 1, y + 1].Y - 0.5f, resultsMap[x + 1, y + 1].Z * k);

                    ////c = GetColor(resultsMap[x, y + 1]);
                    ////gl.Color((float)c.R / 255f, (float)c.G / 255f, (float)c.B / 255f);
                    //gl.Vertex(resultsMap[x, y + 1].X - 0.5f, resultsMap[x, y + 1].Y - 0.5f, resultsMap[x, y + 1].Z * k);
                }
            }

            gl.Color(0.2f, 0.2f, 0.2f);
            gl.Begin(OpenGL.GL_QUADS);
            for (int y = 0; y < ySize - 1; y++)
            {
                gl.Vertex(resultsMap[0, y].X - 0.5f, resultsMap[0, y].Y - 0.5f, resultsMap[0, y].Z * k);
                gl.Vertex(resultsMap[0, y].X - 0.5f, resultsMap[0, y].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[0, y + 1].X - 0.5f, resultsMap[0, y + 1].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[0, y + 1].X - 0.5f, resultsMap[0, y + 1].Y - 0.5f, resultsMap[0, y + 1].Z * k);
            }
            gl.End();

            gl.Begin(OpenGL.GL_QUADS);
            for (int y = 0; y < ySize - 1; y++)
            {
                gl.Vertex(resultsMap[xSize - 1, y].X - 0.5f, resultsMap[xSize - 1, y].Y - 0.5f, resultsMap[xSize - 1, y].Z * k);
                gl.Vertex(resultsMap[xSize - 1, y].X - 0.5f, resultsMap[xSize - 1, y].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[xSize - 1, y + 1].X - 0.5f, resultsMap[xSize - 1, y + 1].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[xSize - 1, y + 1].X - 0.5f, resultsMap[xSize - 1, y + 1].Y - 0.5f, resultsMap[xSize - 1, y + 1].Z * k);
            }
            gl.End();

            gl.Begin(OpenGL.GL_QUADS);
            for (int x = 0; x < xSize - 1; x++)
            {
                gl.Vertex(resultsMap[x, 0].X - 0.5f, resultsMap[xSize - 1, 0].Y - 0.5f, resultsMap[x, 0].Z * k);
                gl.Vertex(resultsMap[x, 0].X - 0.5f, resultsMap[xSize - 1, 0].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[x + 1, 0].X - 0.5f, resultsMap[x + 1, 0].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[x + 1, 0].X - 0.5f, resultsMap[x + 1, 0].Y - 0.5f, resultsMap[x + 1, 0].Z * k);
            }
            gl.End();

            gl.Begin(OpenGL.GL_QUADS);
            for (int x = 0; x < xSize - 1; x++)
            {
                gl.Vertex(resultsMap[x, ySize - 1].X - 0.5f, resultsMap[x, ySize - 1].Y - 0.5f, resultsMap[x, ySize - 1].Z * k);
                gl.Vertex(resultsMap[x, ySize - 1].X - 0.5f, resultsMap[x, ySize - 1].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[x + 1, ySize - 1].X - 0.5f, resultsMap[x + 1, ySize - 1].Y - 0.5f, -0.05);
                gl.Vertex(resultsMap[x + 1, ySize - 1].X - 0.5f, resultsMap[x + 1, ySize - 1].Y - 0.5f, resultsMap[x + 1, ySize - 1].Z * k);
            }
            gl.End();
            //gl.Color(0.1f, 0.1f, 0.1f);


            //gl.Begin(OpenGL.GL_LINES);
            //for (int x = 0; x < xSize; x++)
            //{
            //    for (int y = 0; y < ySize; y++)
            //    {
            //        if (x + 1 < xSize)
            //        {
            //            gl.Vertex(resultsMap[x, y].X - 0.5f, resultsMap[x, y].Y - 0.5f, resultsMap[x, y].Z * k + z);
            //            gl.Vertex(resultsMap[x + 1, y].X - 0.5f, resultsMap[x + 1, y].Y - 0.5f, resultsMap[x + 1, y].Z * k + z);
            //        }

            //        if (y + 1 < ySize)
            //        {
            //            gl.Vertex(resultsMap[x, y].X - 0.5f, resultsMap[x, y].Y - 0.5f, resultsMap[x, y].Z * k + z);
            //            gl.Vertex(resultsMap[x, y + 1].X - 0.5f, resultsMap[x, y + 1].Y - 0.5f, resultsMap[x, y + 1].Z * k + z);
            //        }
            //    }
            //}

            //gl.End();

            gl.Flush();
        }
Ejemplo n.º 12
0
        private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
        {
            OpenGL gl = openGLControl.OpenGL;

            gl.ClearColor(0, 0, 0, 0);
        }
Ejemplo n.º 13
0
 private void GLControl_Resized(Object sender, OpenGLEventArgs args)
 {
     CreateProjectionMatrix(0.45F, ActualWidth, ActualHeight, 1, 300);
 }
Ejemplo n.º 14
0
 private void OpenGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
 {
     args.OpenGL.Enable(OpenGL.GL_DEPTH_TEST);
     args.OpenGL.ClearColor(1.0f, 1.0f, 1.0f, 0f);
 }
Ejemplo n.º 15
0
 private void GLControl_OpenGLDraw(Object sender, OpenGLEventArgs args)
 {
     //Does nothing. Used to prevent SharpGL error messages.
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Handles the OpenGLDraw event of the openGLControl1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
 private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
 {
     m_world.Sirina_prozora = (int)Window.GetWindow(this).ActualWidth;
     m_world.Draw(args.OpenGL);
 }
Ejemplo n.º 17
0
 private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
 {
     OpenGL gl = openGLControl.OpenGL;
 }
Ejemplo n.º 18
0
 private void OpenGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
 {
     glContext.OpenGLInit(sender, args, glContext.DEFAULT_VS, TxtBox_FS.Text);
 }
Ejemplo n.º 19
0
        public virtual void Resized(object sender, OpenGLEventArgs args)
        {
            OpenGLControl control = (OpenGLControl)sender;

            OpenGLWindow.BasicResize(OpenGLWindow, control.RenderSize);
        }
        //private void make_change(object sender, EventArgs e)
        //{
        //    second_count++;
        //    second_count %= 38;
        //    this.Title = second_count.ToString();
        //    //System.Threading.Thread.Sleep(5000);
        //    OpenGL gl = myGLCon.OpenGL;
        //    ////gl = e.OpenGL;
        //    ////  Load the identity matrix.
        //    ////gl.LoadIdentity();
        //    ////  Set the clear color.
        //    //gl.ClearColor(1, 1, 1, 0);
        //    //////  Clear the color and depth buffer.
        //    //gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
        //    //gl.LoadIdentity();
        //    //gl.Flush();
        //    for (int index = 0; index != ds.Tables[0].Rows.Count; ++index)
        //    {
        //        DataRow dr = ds.Tables[0].Rows[index];
        //        if (tag_arr[index] == true)
        //            continue;
        //        else
        //        {
        //            myGLCon_drawWireFram((float)dr["lx"], (float)dr["lz"], (float)dr["ly"], (float)dr["hx"], (float)dr["hz"], (float)dr["hy"]);
        //            myGLCon_drawCube((float)dr["lx"], (float)dr["lz"], (float)dr["ly"], (float)dr["hx"], (float)dr["hz"], (float)dr["hy"], 0.5f, 0.5f, 0.5f);
        //            tag_arr[index] = true;
        //            break;
        //        }
        //    }

        //}
        //动画演示,初始化

        //private void myGLCon_OpenGLDraw(object sender, OpenGLEventArgs args)
        //{
        //    gl = myGLCon.OpenGL;
        //    //  Clear the color and depth buffer.
        //    //gl.ClearColor(1, 1, 1, 0);
        //    //gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

        //    //  Load the identity matrix.
        //    //gl.LoadIdentity();

        //    //  Rotate around the Y axis.
        //    gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
        //    //画车厢线框图
        //    myGLCon_drawWireFram(0.0f, 0.0f, 0.0f, 5.0f, 2.0f, 2.0f);
        //    ////动态展示箱子
        //    //全部置为false
        //    for (int index = 0; index != ds.Tables[0].Rows.Count; ++index)
        //    {
        //        tag_arr[index] = false;
        //    }
        //    ////取得箱子总数
        //    int box_number = ds.Tables[0].Rows.Count;
        //    //DispatcherTimer timer = new DispatcherTimer();//定时器
        //    //timer.Interval = TimeSpan.FromMilliseconds(10000);//定时10毫秒
        //    //timer.Tick += new EventHandler(make_change);
        //    //timer.IsEnabled = true;
        //    //timer.Start();
        //    //foreach (DataRow dr in ds.Tables[0].Rows)
        //    //{
        //    //    float Blue, Red, Green;
        //    //    string temp;

        //    //    temp = dr["distance"].ToString();
        //    //    if (!ColorHashTable.ContainsKey(dr["distance"].ToString()))
        //    //    {
        //    //        Random ra = new Random();
        //    //        Blue = (float)ra.NextDouble();
        //    //        Red = (float)ra.NextDouble();
        //    //        Green = (float)ra.NextDouble();
        //    //        ColorHashTable.Add(dr["distance"].ToString(), Blue.ToString() + " " + Red.ToString() + " " + Green.ToString());
        //    //    }
        //    //    else
        //    //    {
        //    //        string AllColor = ColorHashTable[dr["distance"].ToString()].ToString();
        //    //        string[] ColorArray = AllColor.Split(' ');
        //    //        Blue = (float)Convert.ToDecimal(ColorArray[0]);
        //    //        Red = (float)Convert.ToDecimal(ColorArray[1]);
        //    //        Green = (float)Convert.ToDecimal(ColorArray[2]);
        //    //    }
        //    //    //画箱子线框图
        //    //    //drawWireFram((float)dr["lx"], (float)dr["ly"], (float)dr["lz"], (float)dr["hx"], (float)dr["hy"], (float)dr["hz"]);
        //    //    //drawCube((float)dr["lx"], (float)dr["ly"], (float)dr["lz"], (float)dr["hx"], (float)dr["hy"], (float)dr["hz"], Red, Green, Blue);
        //    //    drawWireFram((float)dr["lx"], (float)dr["lz"], (float)dr["ly"], (float)dr["hx"], (float)dr["hz"], (float)dr["hy"]);
        //    //    drawCube((float)dr["lx"], (float)dr["lz"], (float)dr["ly"], (float)dr["hx"], (float)dr["hz"], (float)dr["hy"], Red, Green, Blue);

        //    //    second_count++;
        //    //}
        //}
        /// <summary>
        /// Handles the OpenGLDraw event of the openGLControl1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
        private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
        {
            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            //gl = args.OpenGL;
            //  Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            //  Load the identity matrix.
            //gl.LoadIdentity();

            //  Rotate around the Y axis.
            gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
            //画车厢线框图
            openGLControl_drawWireFram(0.0f, 0.0f, 0.0f, 5.0f, 2.0f, 2.0f);

            //画坐标系  车厢的坐标
            //x轴
            gl.LineWidth(2.5f);
            gl.Color(1.0, 0.0, 0.0);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(-1.0f, 0.0f, 0.0f);
            gl.Vertex(6.0f, 0.0f, 0.0f);
            gl.End();

            //y轴
            gl.LineWidth(2.5f);
            gl.Color(0.0, 1.0, 0.0);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0.0f, -1.0f, 0.0f);
            gl.Vertex(0.0f, 5.0f, 0.0f);
            gl.End();

            //z轴
            gl.LineWidth(2.5f);
            gl.Color(0.0, 0.0, 1.0);
            gl.Begin(OpenGL.GL_LINES);
            gl.Vertex(0.0f, 0.0f, -1.0f);
            gl.Vertex(0.0f, 0.0f, 4.0f);
            gl.End();
            gl.Flush();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                //myTextBlock.Text += dr["box_id"].ToString() + "(" + dr["lx"].ToString() + "," + dr["ly"].ToString() + "," + dr["lz"].ToString() + ","
                //                    + dr["hx"].ToString() + "," + dr["hy"].ToString() + "," + dr["hz"].ToString() + ") ";
                float  Blue, Red, Green;
                string temp;

                temp = dr["distance"].ToString();
                string dis = dr["distance"].ToString();
                if (!ColorHashTable.ContainsKey(dr["distance"].ToString()))
                {
                    Random ra = new Random();
                    Blue  = (float)ra.NextDouble();
                    Red   = (float)ra.NextDouble();
                    Green = (float)ra.NextDouble();
                    ColorHashTable.Add(dr["distance"].ToString(), Blue.ToString() + " " + Red.ToString() + " " + Green.ToString());
                }
                else
                {
                    string   AllColor   = ColorHashTable[dr["distance"].ToString()].ToString();
                    string[] ColorArray = AllColor.Split(' ');
                    Blue  = (float)Convert.ToDecimal(ColorArray[0]);
                    Red   = (float)Convert.ToDecimal(ColorArray[1]);
                    Green = (float)Convert.ToDecimal(ColorArray[2]);
                }
                //画箱子线框图
                //drawWireFram((float)dr["lx"], (float)dr["ly"], (float)dr["lz"], (float)dr["hx"], (float)dr["hy"], (float)dr["hz"]);
                //drawCube((float)dr["lx"], (float)dr["ly"], (float)dr["lz"], (float)dr["hx"], (float)dr["hy"], (float)dr["hz"], Red, Green, Blue);
                openGLControl_drawWireFram((float)dr["lx"], (float)dr["lz"], (float)dr["ly"], (float)dr["hx"], (float)dr["hz"], (float)dr["hy"]);
                openGLControl_drawCube((float)dr["lx"], (float)dr["lz"], (float)dr["ly"], (float)dr["hx"], (float)dr["hz"], (float)dr["hy"], Red, Green, Blue);
            }
            //  Nudge the rotation.
            //rotation += 3.0f;
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Handles the OpenGLInitialized event of the openGLControl1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
 private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
 {
     m_world.Initialize(args.OpenGL);
 }
Ejemplo n.º 22
0
 private void AudioScopeDraw1(object sender, OpenGLEventArgs args)
 {
 }
Ejemplo n.º 23
0
        public void OpenGLInit(object sender, OpenGLEventArgs args, string Vertex_shader_textbox, string Fragment_shader_textbox)
        {
            //CREATE THE VAO
            args.OpenGL.GenVertexArrays(1, vao);
            args.OpenGL.BindVertexArray(vao[0]);
            //CREATE THE VBO AND POPULATE IT WITH THE QUAD VERTICIES
            args.OpenGL.GenBuffers(1, vbo);
            args.OpenGL.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vbo[0]);
            args.OpenGL.BufferData(OpenGL.GL_ARRAY_BUFFER, g_vertex_buffer_data.Length * sizeof(float), GCHandle.Alloc(g_vertex_buffer_data, GCHandleType.Pinned).AddrOfPinnedObject(), OpenGL.GL_STATIC_DRAW);
            args.OpenGL.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));



            //Tell opengl what attribute arrays we need
            args.OpenGL.EnableVertexAttribArray(0);
            args.OpenGL.EnableVertexAttribArray(1);
            args.OpenGL.EnableVertexAttribArray(2);
            args.OpenGL.EnableVertexAttribArray(3);

            //This is the position attribute pointer  (layout(location = 0) in vec2 vertexPosition;)
            args.OpenGL.VertexAttribPointer(1, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
            //This is the color attribute pointer layout(location = 1) in vec4 vertexColor;
            args.OpenGL.VertexAttribPointer(2, 4, OpenGL.GL_UNSIGNED_BYTE, false, 0, new IntPtr(2));
            //This is the UV attribute pointer layout(location = 2) in vec2 vertexUV;
            args.OpenGL.VertexAttribPointer(3, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));

            //UNBIND WHEN FINISHED
            args.OpenGL.BindVertexArray(0);
            args.OpenGL.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);


            //SET SOME GL CONSTANTS
            args.OpenGL.Enable(OpenGL.GL_DEPTH_TEST);
            args.OpenGL.Enable(OpenGL.GL_BLEND);
            args.OpenGL.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
            args.OpenGL.ShadeModel(OpenGL.GL_SMOOTH);



            //  Create a vertex shader.
            vertexShader = new VertexShader();
            vertexShader.CreateInContext(args.OpenGL);
            vertexShader.SetSource(Vertex_shader_textbox);

            //  Create a fragment shader.
            fragmentShader = new FragmentShader();
            fragmentShader.CreateInContext(args.OpenGL);
            fragmentShader.SetSource(Fragment_shader_textbox);

            //  Compile them both.
            vertexShader.Compile();
            fragmentShader.Compile();



            //  Build a program.
            m_shaderProgram.CreateInContext(args.OpenGL);

            //  Attach the shaders.
            m_shaderProgram.AttachShader(vertexShader);
            m_shaderProgram.AttachShader(fragmentShader);
            m_shaderProgram.Link();


            //SET UP TEXTURE 1

            texture.Create(args.OpenGL, Environment.CurrentDirectory + @"\1.png");
            texture.Bind(args.OpenGL);
        }
Ejemplo n.º 24
0
 private void SharpglCtrl_OnResized(object sender, OpenGLEventArgs args)
 {
     _logger.Trace("SharpglCtrl_OnResized");
 }
Ejemplo n.º 25
0
 public virtual void Initialized(object sender, OpenGLEventArgs args)
 {
     OpenGLWindow.Initialized(sender, args);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Handles the OpenGLDraw event of the openGLControl1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
 private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
 {
     m_world.Draw(args.OpenGL);
 }
Ejemplo n.º 27
0
 public virtual void Draw(object sender, OpenGLEventArgs args)
 {
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Handles the Resized event of the openGLControl1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
 private void openGLControl_Resized(object sender, OpenGLEventArgs args)
 {
     m_world.Resize(args.OpenGL, (int)openGLControl.Width, (int)openGLControl.Height);
 }
Ejemplo n.º 29
0
 private void OpenGLControl_Resized(object sender, OpenGLEventArgs args)
 {
 }
Ejemplo n.º 30
0
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or 
        /// internal processes call <see cref="M:System.Windows.FrameworkElement.ApplyTemplate"/>.
        /// </summary>
        public override void OnApplyTemplate()
        {
            //  Call the base.
            base.OnApplyTemplate();

            //  Lock on OpenGL.
            lock (gl)
            {
                //  Create OpenGL.
                gl.Create(OpenGLVersion, RenderContextType, 1, 1, 32, null);
            }

            //  Create our fast event args.
            eventArgsFast = new OpenGLEventArgs(gl);

            //  Set the most basic OpenGL styles.
            gl.ShadeModel(OpenGL.GL_SMOOTH);
            gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            gl.ClearDepth(1.0f);
            gl.Enable(OpenGL.GL_DEPTH_TEST);
            gl.DepthFunc(OpenGL.GL_LEQUAL);
            gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);

            //  Fire the OpenGL initialised event.
            var handler = OpenGLInitialized;
            if (handler != null)
                handler(this, eventArgsFast);

            timer.Interval = new TimeSpan(0, 0, 0, 0, (int)(1000.0 / FrameRate));
        }
 /// <summary>
 /// Handles the OpenGLDraw event of the openGLControl1 control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
 private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
 {
     m_world.Sirina = (int)window.ActualWidth;
     m_world.Draw(args.OpenGL);
 }