Пример #1
0
        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);
        }
Пример #2
0
        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);
        }