Ejemplo n.º 1
0
        void IHasObjectSpace.PushObjectSpace(OpenGL gl)
        {
            // Update matrices.
            IScientificCamera camera = this.Camera;

            if (camera == null)
            {
                return;
            }
            if (camera.CameraType == CameraTypes.Perspecitive)
            {
                IPerspectiveViewCamera perspective = camera;
                this.projectionMatrix = perspective.GetProjectionMat4();
                this.viewMatrix       = perspective.GetViewMat4();
            }
            else if (camera.CameraType == CameraTypes.Ortho)
            {
                IOrthoViewCamera ortho = camera;
                this.projectionMatrix = ortho.GetProjectionMat4();
                this.viewMatrix       = ortho.GetViewMat4();
            }
            else
            {
                throw new NotImplementedException();
            }

            modelMatrix = mat4.identity();
        }
Ejemplo n.º 2
0
        protected void BeforeRendering(OpenGL gl, RenderMode renderMode)
        {
            IScientificCamera camera = this.camera;

            if (camera != null)
            {
                if (camera.CameraType == CameraTypes.Perspecitive)
                {
                    IPerspectiveViewCamera perspective = camera;
                    this.projectionMatrix = perspective.GetProjectionMat4();
                    this.viewMatrix       = perspective.GetViewMat4();
                }
                else if (camera.CameraType == CameraTypes.Ortho)
                {
                    IOrthoViewCamera ortho = camera;
                    this.projectionMatrix = ortho.GetProjectionMat4();
                    this.viewMatrix       = ortho.GetViewMat4();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            modelMatrix = glm.scale(mat4.identity(), new vec3(1, 1, this.ZAxisScale));

            gl.Enable(OpenGL.GL_VERTEX_PROGRAM_POINT_SIZE);
            gl.Enable(OpenGL.GL_POINT_SPRITE_ARB);
            gl.TexEnv(OpenGL.GL_POINT_SPRITE_ARB, OpenGL.GL_COORD_REPLACE_ARB, OpenGL.GL_TRUE);
            gl.Enable(OpenGL.GL_POINT_SMOOTH);
            gl.Hint(OpenGL.GL_POINT_SMOOTH_HINT, OpenGL.GL_NICEST);
            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendEquation(OpenGL.GL_FUNC_ADD_EXT);
            gl.BlendFuncSeparate(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA, OpenGL.GL_ONE, OpenGL.GL_ONE);

            ShaderProgram shaderProgram = this.shaderProgram;

            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);

            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
            shaderProgram.SetUniform1(gl, "canvasWidth", viewport[2] + 0.0f);
            shaderProgram.SetUniform1(gl, "canvasHeight", viewport[3] + 0.0f);
            shaderProgram.SetUniform1(gl, "opacity", this.Opacity);

            this.texture.Bind(gl);
            shaderProgram.SetUniform1(gl, "tex", this.texture.TextureName);
            shaderProgram.SetUniform1(gl, "brightness", this.Brightness);
        }
Ejemplo n.º 3
0
        //private void GeneratePoints(out float[] vertices, out float[] colors)
        //{
        //    const int length = 256 * 3;
        //    vertices = new float[length]; colors = new float[length];

        //    Random random = new Random();

        //    int direction = this.positiveGrowth ? 1 : -1;
        //    // points
        //    for (int i = 0; i < length; i++)
        //    {
        //        vertices[i] = direction * (float)i / (float)length;
        //        colors[i] = (float)((random.NextDouble() * 2 - 1) * 1);
        //        //colors[i] = (float)i / (float)length;
        //    }

        //    //// triangles
        //    //for (int i = 0; i < length / 9; i++)
        //    //{
        //    //    var x = random.NextDouble(); var y = random.NextDouble(); var z = random.NextDouble();
        //    //    for (int j = 0; j < 3; j++)
        //    //    {
        //    //        vertices[i * 9 + j * 3] = (float)(x + random.NextDouble() / 5 - 1);
        //    //    }
        //    //    for (int j = 0; j < 3; j++)
        //    //    {
        //    //        vertices[i * 9 + j * 3 + 1] = (float)(y + random.NextDouble() / 5 - 1);
        //    //    }
        //    //    for (int j = 0; j < 3; j++)
        //    //    {
        //    //        vertices[i * 9 + j * 3 + 2] = (float)(z + random.NextDouble() / 5 - 1);
        //    //    }
        //    //}
        //}

        #region IRenderable 成员

        void IRenderable.Render(OpenGL gl, RenderMode renderMode)
        {
            // Update matrices.
            IScientificCamera camera = this.Camera;

            if (camera != null)
            {
                if (camera.CameraType == CameraTypes.Perspecitive)
                {
                    IPerspectiveViewCamera perspective = camera;
                    this.projectionMatrix = perspective.GetProjectionMat4();
                    this.viewMatrix       = perspective.GetViewMat4();
                }
                else if (camera.CameraType == CameraTypes.Ortho)
                {
                    IOrthoViewCamera ortho = camera;
                    this.projectionMatrix = ortho.GetProjectionMat4();
                    this.viewMatrix       = ortho.GetViewMat4();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            modelMatrix = mat4.identity();

            gl.PointSize(3);

            var shader = (renderMode == RenderMode.HitTest) ? pickingShaderProgram : shaderProgram;

            //  Bind the shader, set the matrices.
            shader.Bind(gl);
            shader.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shader.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shader.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
            if (renderMode == RenderMode.HitTest)
            {
                shader.SetUniform1(gl, "pickingBaseID", ((IColorCodedPicking)this).PickingBaseID);
            }

            //  Bind the out vertex array.
            vertexBufferArray.Bind(gl);

            //  Draw the square.
            gl.DrawArrays((uint)this.mode, 0, positions.Length / 3);

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(gl);
            shader.Unbind(gl);
        }
        protected void BeforeRendering(OpenGL gl, RenderMode renderMode)
        {
            IScientificCamera camera = this.camera;

            if (camera != null)
            {
                if (camera.CameraType == CameraTypes.Perspecitive)
                {
                    IPerspectiveViewCamera perspective = camera;
                    this.projectionMatrix = perspective.GetProjectionMat4();
                    this.viewMatrix       = perspective.GetViewMat4();
                }
                else if (camera.CameraType == CameraTypes.Ortho)
                {
                    IOrthoViewCamera ortho = camera;
                    this.projectionMatrix = ortho.GetProjectionMat4();
                    this.viewMatrix       = ortho.GetViewMat4();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            modelMatrix = mat4.identity();

            gl.Enable(OpenGL.GL_VERTEX_PROGRAM_POINT_SIZE);
            gl.Enable(OpenGL.GL_POINT_SPRITE_ARB);
            gl.TexEnv(OpenGL.GL_POINT_SPRITE_ARB, OpenGL.GL_COORD_REPLACE_ARB, OpenGL.GL_TRUE);
            gl.Enable(OpenGL.GL_POINT_SMOOTH);
            gl.Hint(OpenGL.GL_POINT_SMOOTH_HINT, OpenGL.GL_NICEST);
            gl.Enable(OpenGL.GL_BLEND);
            gl.BlendEquation(OpenGL.GL_FUNC_ADD_EXT);
            gl.BlendFuncSeparate(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA, OpenGL.GL_ONE, OpenGL.GL_ONE);


            gl.BindTexture(OpenGL.GL_TEXTURE_2D, this.texture[0]);

            int[] viewport = new int[4];
            gl.GetInteger(OpenGL.GL_VIEWPORT, viewport);

            ShaderProgram shader = this.shaderProgram;

            shader.Bind(gl);
            shader.SetUniform1(gl, "tex", this.texture[0]);
            shader.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shader.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shader.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
            shader.SetUniform1(gl, "pointSize", this.textureWidth * 1.0f);
            shader.SetUniform3(gl, "textColor", this.textColor.x, this.textColor.y, this.textColor.z);
        }
Ejemplo n.º 5
0
        protected void BeforeRendering(OpenGL gl, RenderMode renderMode)
        {
            IScientificCamera camera = this.camera;

            if (camera != null)
            {
                if (camera.CameraType == CameraTypes.Perspecitive)
                {
                    IPerspectiveViewCamera perspective = camera;
                    this.projectionMatrix = perspective.GetProjectionMat4();
                    this.viewMatrix       = perspective.GetViewMat4();
                }
                else if (camera.CameraType == CameraTypes.Ortho)
                {
                    IOrthoViewCamera ortho = camera;
                    this.projectionMatrix = ortho.GetProjectionMat4();
                    this.viewMatrix       = ortho.GetViewMat4();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            gl.Enable(OpenGL.GL_TEXTURE_2D);
            this.texture.Bind(gl);

            modelMatrix = mat4.identity();
            ShaderProgram shaderProgram = this.shaderProgram;

            //  Bind the shader, set the matrices.
            shaderProgram.Bind(gl);
            shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());

            shaderProgram.SetUniform1(gl, "tex", this.texture.TextureName);
            shaderProgram.SetUniform1(gl, "brightness", this.Brightness);


            gl.Enable(OpenGL.GL_POLYGON_SMOOTH);
            gl.Hint(OpenGL.GL_POLYGON_SMOOTH_HINT, OpenGL.GL_NICEST);
        }
        void IRenderable.Render(OpenGL gl, RenderMode renderMode)
        {
            if (!this.RenderModel)
            {
                return;
            }

            if (!initialised)
            {
                this.Initialise(gl);
            }
            // Update matrices.
            IScientificCamera camera = this.Camera;

            if (camera != null)
            {
                if (camera.CameraType == CameraTypes.Perspecitive)
                {
                    IPerspectiveViewCamera perspective = camera;
                    this.projectionMatrix = perspective.GetProjectionMat4();
                    this.viewMatrix       = perspective.GetViewMat4();
                }
                else if (camera.CameraType == CameraTypes.Ortho)
                {
                    IOrthoViewCamera ortho = camera;
                    this.projectionMatrix = ortho.GetProjectionMat4();
                    this.viewMatrix       = ortho.GetViewMat4();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            modelMatrix = glm.scale(mat4.identity(), new vec3(1, 1, this.ZAxisScale));

            //gl.PointSize(3);

            var shader = (renderMode == RenderMode.HitTest) ? pickingShaderProgram : shaderProgram;

            //  Bind the shader, set the matrices.
            shader.Bind(gl);
            shader.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
            shader.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
            shader.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
            if (renderMode == RenderMode.HitTest)
            {
                shader.SetUniform1(gl, "pickingBaseID", ((IColorCodedPicking)this).PickingBaseID);
            }

            //  Bind the out vertex array.
            vertexBufferArray.Bind(gl);

            //  Draw the square.
            ScientificModel model = this.Model;

            if (model.First != null && model.Count != null && model.PrimitiveCount > 0)
            {
                gl.MultiDrawArrays((uint)model.Mode, model.First, model.Count, model.PrimitiveCount);
            }
            else
            {
                gl.DrawArrays((uint)this.Model.Mode, 0, this.Model.VertexCount);
            }

            //  Unbind our vertex array and shader.
            vertexBufferArray.Unbind(gl);
            shader.Unbind(gl);
        }