Ejemplo n.º 1
0
        private static VertexArray MeshInstances(MyCameraShaderProgram shaderProgram)
        {
            var mesh        = MeshTools.LoadFromResource("content.suzanne.obj");
            var vertexArray = new VertexArray(PrimitiveType.Triangles);

            vertexArray.AddIndices(mesh.ID.ToArray());

            const int count = 100;
            var       rnd   = new Random();

            float RndRange(float min, float max) => min + (max - min) * (float)rnd.NextDouble();

            var position = new Vector3[count];

            for (int i = 0; i < count; ++i)
            {
                position[i] = new Vector3(RndRange(-8f, 8f), RndRange(-.5f, .5f), RndRange(-40f, -0f));
            }
            vertexArray.AddAttribute(shaderProgram.LocationInstancePosition, position, 3, VertexAttribPointerType.Float, true);

            vertexArray.AddAttribute(shaderProgram.LocationPosition, mesh.Position.ToArray(), 3, VertexAttribPointerType.Float);
            if (mesh.Normal.Count > 0 && -1 != shaderProgram.LocationNormal)
            {
                vertexArray.AddAttribute(shaderProgram.LocationNormal, mesh.Normal.ToArray(), 3, VertexAttribPointerType.Float);
            }
            if (mesh.TextureCoordinate.Count > 0 && -1 != shaderProgram.LocationTexCoord)
            {
                vertexArray.AddAttribute(shaderProgram.LocationTexCoord, mesh.TextureCoordinate.ToArray(), 2, VertexAttribPointerType.Float);
            }
            return(vertexArray);
        }
Ejemplo n.º 2
0
Archivo: View.cs Proyecto: Michizev/ACG
        public View()
        {
            shaderProgram = new MyMeshShaderProgram();
            var mesh = MeshTools.LoadFromResource("content.chalet.obj");

            texture = TextureTools.LoadFromResource("content.chalet.jpg");

            // copy position and velocity data to GPU
            vertexArray = new VertexArray(PrimitiveType.Triangles);
            vertexArray.AddIndices(mesh.ID.ToArray());
#if SOLUTION
            vertexArray.AddAttribute(shaderProgram.LocationPosition, mesh.Position.ToArray(), 3, VertexAttribPointerType.Float);
            if (mesh.Normal.Count > 0 && -1 != shaderProgram.LocationNormal)
            {
                vertexArray.AddAttribute(shaderProgram.LocationNormal, mesh.Normal.ToArray(), 3, VertexAttribPointerType.Float);
            }
            if (mesh.TextureCoordinate.Count > 0 && -1 != shaderProgram.LocationTexCoord)
            {
                vertexArray.AddAttribute(shaderProgram.LocationTexCoord, mesh.TextureCoordinate.ToArray(), 2, VertexAttribPointerType.Float);
            }
#endif
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.BindTexture(TextureTarget.Texture2D, texture);
        }
Ejemplo n.º 3
0
Archivo: View.cs Proyecto: Michizev/ACG
        public View()
        {
            shaderProgram = new MyMeshShaderProgram();
            var mesh = MeshTools.LoadFromResource("content.suzanne.obj");

            // copy data to GPU
            vertexArray = new VertexArray(PrimitiveType.Triangles);
            vertexArray.AddIndices(mesh.ID.ToArray());
#if SOLUTION
            const int count = 500;
            var       rnd   = new Random(12);
            float Rnd01() => (float)rnd.NextDouble();
            float RndCoord() => (Rnd01() - 0.5f) * 10.0f;

            var position = new Vector3[count];
            for (int i = 0; i < count; ++i)
            {
                position[i] = new Vector3(RndCoord(), RndCoord(), RndCoord());
            }
            vertexArray.AddAttribute(shaderProgram.LocationInstancePosition, position, 3, VertexAttribPointerType.Float, true);

            vertexArray.AddAttribute(shaderProgram.LocationPosition, mesh.Position.ToArray(), 3, VertexAttribPointerType.Float);
            if (mesh.Normal.Count > 0 && -1 != shaderProgram.LocationNormal)
            {
                vertexArray.AddAttribute(shaderProgram.LocationNormal, mesh.Normal.ToArray(), 3, VertexAttribPointerType.Float);
            }
            if (mesh.TextureCoordinate.Count > 0 && -1 != shaderProgram.LocationTexCoord)
            {
                vertexArray.AddAttribute(shaderProgram.LocationTexCoord, mesh.TextureCoordinate.ToArray(), 2, VertexAttribPointerType.Float);
            }
#endif
            time = Stopwatch.StartNew();

            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
        }