Example #1
0
        public void loadScene()
        {
            vertexShader = Shader.CreateFromFile(ShaderType.VertexShader, "../data/shaders/vertex.vs");

            fragmentShader = Shader.CreateFromFile(ShaderType.FragmentShader, "../data/shaders/fragment.fs");

            shaderProgram = new ShaderProgram(vertexShader, fragmentShader);

            Error.checkGLError("Scene.loadScene");

            shaderProgram.Use();
            Mesh.PositionDataIndex = shaderProgram.GetAttributeLocation("vPosition");
            Mesh.TexCoordDataIndex = shaderProgram.GetAttributeLocation("vTexCoord");
            Mesh.ColorDataIndex    = shaderProgram.GetUniformLocation("uDiffuseColor");
            Mesh.ScaleDataIndex    = shaderProgram.GetUniformLocation("uScale");
            shaderProgram.setSamplerUniform("inputTexture", 0);

            origoTriangle = addMesh(Mesh.CreateTriangleMesh(), new Vector3(0, 0, 0), new Color4(1.0f, 1.0f, 1.0f, 1.0f), 0.1f);
            xTriangle     = addMesh(Mesh.CreateTriangleMesh(), new Vector3(1, 0, 0), new Color4(1, 0.2f, 0.2f, 1), 0.1f);
            zTriangle     = addMesh(Mesh.CreateTriangleMesh(), new Vector3(0, 0, 1), new Color4(0.2f, 1, 0.2f, 1), 0.1f);
            yTriangle     = addMesh(Mesh.CreateTriangleMesh(), new Vector3(0, 1, 0), new Color4(0.2f, 0.2f, 1, 1), 0.1f);

            voxelMesh = addMesh(Mesh.CreateFromFile("../data/models/monu9/monu9.obj"), new Vector3(0.0f, 0.0f, 0.0f), new Color4(1.0f, 1.0f, 1.0f, 1.0f), 0.1f);

            projectionMatrix        = new Matrix4Uniform("projectionMatrix");
            projectionMatrix.Matrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 16.0f / 9.0f, 0.1f, 100f);

            cameraPosition  = new Vector3(0, 0, -2);
            cameraDirection = new Vector3(0, 0, 1.0f);
            sceneUp         = new Vector3(0.0f, 1.0f, 0.0f);

            viewMatrix        = new Matrix4Uniform("viewMatrix");
            viewMatrix.Matrix = Matrix4.CreateTranslation(cameraPosition);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);

            Error.checkGLError("Scene.loadScene");
        }
Example #2
0
        public Mesh(List <PosNorTexVertex> vertices, MaterialManager.Material meshMaterial)
        {
            BufferHandle      = GL.GenBuffer();
            VAOHandle         = GL.GenVertexArray();
            IndexBufferHandle = GL.GenBuffer();

            VertexAmount = vertices.Count;

            Error.checkGLError("Mesh constructor");

            rawVertices = vertices;

            MeshMaterial = meshMaterial;

            // Transformcomponent
            worldMatrix        = new Matrix4Uniform("modelMatrix");
            worldMatrix.Matrix = Matrix4.Identity;

            // RenderingComponent
            Scale        = 1.0f;
            DiffuseColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
            rotationY    = 0.0f;
        }