Ejemplo n.º 1
0
        private void LoadData(OpenGL GL, GShaderProgram shader, vec3[] vertex, vec4[] color)
        {
            pVBO[0].Bind(GL);
            pVBO[0].SetData(GL, (uint)shader.GetAttributeID(GL, "vPosition"), Pos, false, 3);

            //  Color

            pVBO[1].Bind(GL);
            pVBO[1].SetData(GL, (uint)shader.GetAttributeID(GL, "vArgbColor"), Color, false, 4);
        }
Ejemplo n.º 2
0
        public void Create(OpenGL GL, string texPath, GShaderProgram shader)
        {
            vec3[] points = new vec3[] { /*new vec3(-C_END, -C_END, 0), new vec3(-C_END, C_END, 0), new vec3(C_END, C_END, 0), new vec3(C_END, C_END, 0) */
                new vec3(C_BOX_END, C_BOX_END, 0), new vec3(C_BOX_END, -C_BOX_END, 0), new vec3(-C_BOX_END, C_BOX_END, 0), new vec3(-C_BOX_END, -C_BOX_END, 0)
            };
            vec3[] normals = new vec3[points.Length];
            for (int i = 0; i < normals.Length; i++)
            {
                normals[i] = new vec3(0.0f, 0.0f, -1.0f);
            }
            vec2[] texCord = new vec2[] {
                new vec2(0.0f, 1.0f), new vec2(0.0f, 0.0f), new vec2(1.0f, 1.0f), new vec2(1.0f, 0.0f)
            };

            if (texPath == null)
            {
                _textureName = C_DUMMY_TEXTURE;
                TextureManager.Instance.CreateTexture1x1(C_DUMMY_TEXTURE, GL, false, Color.Blue);
            }
            else
            {
                _textureName = texPath;
                TextureManager.Instance.CreateTexture(texPath, GL, false);
            }

            arrowVAO = new VertexBufferArray();
            arrowVAO.Create(GL);
            arrowVAO.Bind(GL);

            VertexBuffer[] cVBO = new VertexBuffer[3];

            cVBO[0] = new VertexBuffer();
            cVBO[0].Create(GL);
            cVBO[0].Bind(GL);
            cVBO[0].SetData(GL, (uint)shader.GetAttributeID(GL, "vPosition"), points, false, 3);

            //  Texture
            cVBO[1] = new VertexBuffer();
            cVBO[1].Create(GL);
            cVBO[1].Bind(GL);
            cVBO[1].SetData(GL, (uint)shader.GetAttributeID(GL, "vTextureCoord"), texCord, false, 2);

            //  Normals
            cVBO[2] = new VertexBuffer();
            cVBO[2].Create(GL);
            cVBO[2].Bind(GL);
            cVBO[2].SetData(GL, (uint)shader.GetAttributeID(GL, "vSurfaceNormal"), normals, false, 3);

            arrowVAO.Unbind(GL);
        }
Ejemplo n.º 3
0
        public void Create(OpenGL GL, string texPath, GShaderProgram shader)
        {
            CircleData c = DrawCircle(0f, 0f, 1f, _numSegments);

            vec3[] points  = c.points;
            vec3[] normals = new vec3[points.Length];
            vec2[] texCord = c.texture;
            for (int i = 0; i < normals.Length; i++)
            {
                normals[i] = new vec3(0.0f, 0.0f, -1.0f);
            }


            if (texPath == null || texPath == "")
            {
                _textureName = C_DUMMY_TEXTURE;
                TextureManager.Instance.CreateTexture1x1(C_DUMMY_TEXTURE, GL, false, Color.Blue);
            }
            else
            {
                _textureName = texPath;
                TextureManager.Instance.CreateTexture(texPath, GL, false);
            }

            compassVAO = new VertexBufferArray();
            compassVAO.Create(GL);
            compassVAO.Bind(GL);

            VertexBuffer[] cVBO = new VertexBuffer[3];

            cVBO[0] = new VertexBuffer();
            cVBO[0].Create(GL);
            cVBO[0].Bind(GL);
            cVBO[0].SetData(GL, (uint)shader.GetAttributeID(GL, "vPosition"), points, false, 3);

            //  Texture
            cVBO[1] = new VertexBuffer();
            cVBO[1].Create(GL);
            cVBO[1].Bind(GL);
            cVBO[1].SetData(GL, (uint)shader.GetAttributeID(GL, "vTextureCoord"), texCord, false, 2);

            //  Normals
            cVBO[2] = new VertexBuffer();
            cVBO[2].Create(GL);
            cVBO[2].Bind(GL);
            cVBO[2].SetData(GL, (uint)shader.GetAttributeID(GL, "vSurfaceNormal"), normals, false, 3);

            compassVAO.Unbind(GL);
        }
Ejemplo n.º 4
0
        public void Render(OpenGL GL, GShaderProgram shader)
        {
            pointVAO.Bind(GL);
            GL.PointSize(Size);
            // todo: modify to use gl_PointSize = 10.0; in the vertex shader instead
            GL.Enable(OpenGL.GL_POINT_SPRITE_ARB); // MUST be enabled for gl_PointCord to be available in the frag shader
            GL.Enable(OpenGL.GL_POINT_SIZE);
            GL.Enable(OpenGL.GL_BLEND);
            GL.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
            LoadData(GL, shader, Pos, Color);

            GL.DrawArrays(OpenGL.GL_POINTS, 0, Pos.Length);
            GL.Disable(OpenGL.GL_POINT_SIZE);
            GL.Disable(OpenGL.GL_POINT_SPRITE_ARB);
            GL.PointSize(1);
            pointVAO.Unbind(GL);
        }
Ejemplo n.º 5
0
        public void Render(OpenGL GL, GShaderProgram shader)
        {
            compassVAO.Bind(GL);
            TexContainer tc;

            tc = TextureManager.Instance.GetElement(_textureName);
            tc.Tex.Bind(GL); // Bind to the current texture on texture unit 0
            GL.ActiveTexture(OpenGL.GL_TEXTURE0 + (uint)tc.ID);
            shader.SetUniform(GL, "uSampler", tc.ID);
            // Turn ON aplha blending for the arrow so the empty background is ignored
            GL.Enable(OpenGL.GL_BLEND);
            GL.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
            GL.DrawArrays(OpenGL.GL_TRIANGLE_FAN, 0, _numSegments);
            GL.Disable(OpenGL.GL_BLEND);

            compassVAO.Unbind(GL);
        }
Ejemplo n.º 6
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)
        {
            //  TODO: Initialise OpenGL here.

            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            //  Set the clear color.
            gl.ClearColor(0, 0, 0, 0);

            cWidth  = openGLControl.ActualWidth;
            cHeight = openGLControl.ActualHeight;
            Debug.WriteIf(_debug, "Width = " + cWidth.ToString() + " Height = " + cHeight.ToString());

            simpleShader            = new GShaderProgram();
            vertexShaderSource[0]   = ManifestResourceLoader.LoadTextFile("Shaders\\simple.vert");
            fragmentShaderSource[0] = ManifestResourceLoader.LoadTextFile("Shaders\\simple.frag");
            //vertexShaderSource[0] = ManifestResourceLoader.LoadTextFile("Shaders\\circle.vert");
            //fragmentShaderSource[0] = ManifestResourceLoader.LoadTextFile("Shaders\\circle.frag");
            simpleShader.Create(gl, vertexShaderSource[0], fragmentShaderSource[0], null);
            simpleShader.AssertValid(gl);

            textureShader           = new GShaderProgram();
            vertexShaderSource[1]   = ManifestResourceLoader.LoadTextFile("Shaders\\texture.vert");
            fragmentShaderSource[1] = ManifestResourceLoader.LoadTextFile("Shaders\\texture.frag");
            textureShader.Create(gl, vertexShaderSource[1], fragmentShaderSource[1], null);
            textureShader.AssertValid(gl);

            _compass = new Compass();
            _compass.Create(gl, "", textureShader); // AppDomain.CurrentDomain.BaseDirectory + "textures\\compass-dial.png"

            // Allocate memory for all the points
            for (int i = 0; i < POINT_TYPES; i++)
            {
                vec3[] v = new vec3[POINTS];
                vec4[] c = new vec4[POINTS];
                for (int j = 0; j < POINTS; j++)
                {
                    v[i] = new vec3(0, 0, 0);
                    c[i] = new vec4(0, 0, 0, 0);
                }
                _p[i] = new Point();
                _p[i].Create(gl, simpleShader, v, c, 0);
            }
        }
Ejemplo n.º 7
0
        public void Create(OpenGL GL, GShaderProgram shader, vec3[] vertex, vec4[] color, float size)
        {
            Pos   = vertex;
            Color = color;
            Size  = size;

            pointVAO = new VertexBufferArray();
            pointVAO.Create(GL);
            pointVAO.Bind(GL);

            pVBO    = new VertexBuffer[2];
            pVBO[0] = new VertexBuffer();
            pVBO[0].Create(GL);
            pVBO[1] = new VertexBuffer();
            pVBO[1].Create(GL);
            LoadData(GL, shader, Pos, Color);
            pointVAO.Unbind(GL);
        }