Exemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Title = "univ engine";

            shader = ShaderLibrary.Get("basic");
            line_shader = ShaderLibrary.Get("line");

            ObjLoader loader = new ObjLoader("teapot.obj");
            model = loader.Assemble();
            model.Rescale(0.02f);

            octree = new Octree(shader);
            octree.Rescale(10);

            axis = new Axis(line_shader);

            this.camera = new Camera(Width, Height);
            GL.Viewport(0, 0, Width, Height);

            /* lighting */
            sunlight = new DirectionalLight(new BaseLight(new Vector3(1.0f, 0.5f, 0.2f), 1.0f),
                                            new Vector3(0, -1, -2));
            ambient = new BaseLight(new Vector3(1.0f), 0.5f);
            point = new PointLight(new BaseLight(new Vector3(0.0f, 1.0f, 0.0f), 0.35f),
                                   new Attenuation(0.0f, 0.00f, 0.002f),
                                   new Vector3(7, 10, 0));

            shader.Use();
            /* f**k this shit for now */
            //shader.SetBlock<DirectionalLight>("sunlight", ref sunlight);
            //shader.SetBlock<BaseLight>("ambient", ref ambient);

            shader.SetBaseLight("ambient", ambient);
            shader.SetDirectionalLight("sunlight", sunlight);
            shader.SetPointLight("pointLights[0]", point);

            GL.Enable(EnableCap.DepthClamp);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.ClearColor(Color.LightGray);
        }
Exemplo n.º 2
0
        public Model Assemble()
        {
            if (vertexNormals.Count == 0)
                calculateNormals();

            Vector3[] vertexData = verticies.ToArray();
            Vector3[] normals = vertexNormals.ToArray();
            Byte3[] colors = new Byte3[vertexData.Length];
            ushort[] indices = new ushort[faces.Count * 3];

            Byte3 color = new Byte3(45, 35, 200);
            for(int i = 0; i < colors.Length; i++)
                colors[i] = color;

            int j = 0;
            foreach(UInt3 f in faces) {
                indices[j++] = (ushort)(f.Z - 1);
                indices[j++] = (ushort)(f.Y - 1);
                indices[j++] = (ushort)(f.X - 1);
            }

            VertexArray mesh = new VertexArray();
            mesh.CreateBuffer("vertex").BufferData<Vector3>(ref vertexData);
            mesh.CreateBuffer("normal").BufferData<Vector3>(ref normals);
            mesh.CreateBuffer("colors").BufferData<Byte3>(ref colors);
            mesh.CreateBuffer("index", BufferTarget.ElementArrayBuffer).BufferData<ushort>(ref indices);

            Model model = new Model(faces.Count, mesh);

            mesh.AddPointer("vertex",
                new VertexAttribute(model.Shader, "vPosition", VertexAttribPointerType.Float, 3, 0, false));
            mesh.AddPointer("colors",
                new VertexAttribute(model.Shader, "vColor", VertexAttribPointerType.UnsignedByte, 3, 0, true));
            mesh.AddPointer("normal",
                new VertexAttribute(model.Shader, "vNormal", VertexAttribPointerType.Float, 3, 0, false));

            return model;
        }