Beispiel #1
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            Gl.Enable(EnableCap.DepthTest);

            program = new ShaderProgram(VertexShader, FragmentShader);

            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up));

            program["light_direction"].SetValue(new Vector3(0, 0, 1));
            program["enable_lighting"].SetValue(lighting);

            crateTexture = new Texture("crate.jpg");

            cube = new VBO <Vector3>(new Vector3[] {
                new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1),         // top
                new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1),     // bottom
                new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1),         // front face
                new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1),     // back face
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1),     // left
                new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1)
            });                                                                                                     // right
            cubeNormals = new VBO <Vector3>(new Vector3[] {
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0),
                new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0),
                new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1),
                new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1),
                new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0),
                new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0)
            });
            cubeUV = new VBO <Vector2>(new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            });

            cubeQuads = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, BufferTarget.ElementArrayBuffer);


            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);   // multisampling makes things beautiful!
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            // add our mouse callbacks for this tutorial
            Glut.glutMouseFunc(OnMouse);
            Glut.glutMotionFunc(OnMove);

            Gl.Enable(EnableCap.DepthTest);

            // create our shader program
            program = new ShaderProgram(VertexShader, FragmentShader);

            // create our camera
            camera = new Camera(new Vector3(0, 0, 10), Quaternion.Identity);
            camera.SetDirection(new Vector3(0, 0, -1));

            // set up the projection and view matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            //program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up));

            program["light_direction"].SetValue(new Vector3(0, 0, 1));
            program["enable_lighting"].SetValue(lighting);
            program["normalTexture"].SetValue(1);
            program["enable_mapping"].SetValue(normalMapping);

            brickDiffuse = new Texture("AlternatingBrick-ColorMap.png");
            brickNormals = new Texture("AlternatingBrick-NormalMap.png");

            Vector3[] vertices = new Vector3[] {
                new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1),         // top
                new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1),     // bottom
                new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1),         // front face
                new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1),     // back face
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1),     // left
                new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1)
            };
            cube = new VBO <Vector3>(vertices);

            Vector2[] uvs = new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            };
            cubeUV = new VBO <Vector2>(uvs);

            List <int> triangles = new List <int>();

            for (int i = 0; i < 6; i++)
            {
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 1);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4 + 3);
            }
            cubeTriangles = new VBO <int>(triangles.ToArray(), BufferTarget.ElementArrayBuffer);

            Vector3[] normals = Geometry.CalculateNormals(vertices, triangles.ToArray());
            cubeNormals = new VBO <Vector3>(normals);

            Vector3[] tangents = CalculateTangents(vertices, normals, triangles.ToArray(), uvs);
            cubeTangents = new VBO <Vector3>(tangents);

            // load the bitmap font for this tutorial
            font        = new BMFont("font24.fnt", "font24.png");
            fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource);

            fontProgram.Use();
            fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000));
            fontProgram["color"].SetValue(new Vector3(1, 1, 1));

            information = font.CreateString(fontProgram, "OpenGL  C#  Tutorial  15");

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            // enable blending and set to accumulate the star colors
            Gl.Enable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Blend);

            // create our shader program
            program = new ShaderProgram(VertexShader, FragmentShader);

            // set up the projection and view matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 20), Vector3.Zero, Vector3.Up));
            program["model_matrix"].SetValue(Matrix4.Identity);

            // load the flag texture
            flagTexture = new Texture("flag.png");

            // create the flag, which is just a plane with a certain number of segments
            List <Vector3> vertices  = new List <Vector3>();
            List <Vector2> uvs       = new List <Vector2>();
            List <int>     triangles = new List <int>();

            for (int x = 0; x < 40; x++)
            {
                for (int y = 0; y < 40; y++)
                {
                    vertices.Add(new Vector3((x - 20) / 5.0, (y - 20) / 10.0, 0));
                    uvs.Add(new Vector2(x / 39.0, 1 - y / 39.0));

                    if (y == 39 || x == 39)
                    {
                        continue;
                    }

                    triangles.Add(x * 40 + y);
                    triangles.Add((x + 1) * 40 + y);
                    triangles.Add((x + 1) * 40 + y + 1);

                    triangles.Add(x * 40 + y);
                    triangles.Add((x + 1) * 40 + y + 1);
                    triangles.Add(x * 40 + y + 1);
                }
            }

            flagVertices  = new VBO <Vector3>(vertices.ToArray());
            flagUVs       = new VBO <Vector2>(uvs.ToArray());
            flagTriangles = new VBO <int>(triangles.ToArray(), BufferTarget.ElementArrayBuffer);

            // load the bitmap font for this tutorial
            font        = new BMFont("font24.fnt", "font24.png");
            fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource);

            fontProgram.Use();
            fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000));
            fontProgram["color"].SetValue(new Vector3(1, 1, 1));

            information = font.CreateString(fontProgram, "OpenGL  C#  Tutorial  11");

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //Open GL init
            #region
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(1280, 720);
            Glut.glutCreateWindow("Tu mama es maraca");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);
            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);
            //Keyboard functions
            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            //Gl.ClearColor(0,0,0,1);

            //Alpha enabled
            Gl.Disable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);

            #endregion

            //Load shader
            program = new ShaderProgram(VertexShader, FragmentShader);

            //Create perspective
            program.Use();
            program["projection_matrix"].SetValue(
                Matrix4.CreatePerspectiveFieldOfView(0.45f,
                                                     (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(
                Matrix4.LookAt(new Vector3(0, 0, 10),
                               new Vector3(0, 0, 0),
                               new Vector3(0, 1, 0)));

            starTexture = new Texture("star.bmp");
            //start vertices and uv
            #region
            start = new VBO <Vector3>(
                new Vector3[] {
                new Vector3(-1, 1, 0), new Vector3(1, 1, 0),
                new Vector3(1, -1, 0), new Vector3(-1, -1, 0)
            }
                );
            startElements = new VBO <int>(
                new int[] { 0, 1, 2, 3 },
                BufferTarget.ElementArrayBuffer
                );
            startUV = new VBO <Vector2>(
                new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            }
                );
            #endregion

            //Define stars
            float dist = 0;
            float r, g, b;
            for (int i = 0; i < numStars; i++)
            {
                dist = (float)i / numStars * 4f;
                r    = (float)rng.NextDouble();
                g    = (float)rng.NextDouble();
                b    = (float)rng.NextDouble();
                s.Add(new Star(0, dist, new Vector3(r, g, b)));
            }

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(Data.width, Data.height);
            Glut.glutCreateWindow("OpenGL Ind");

            Glut.glutIdleFunc(Functions.OnRenderFrame);
            Glut.glutDisplayFunc(Functions.OnDisplay);
            Glut.glutKeyboardFunc(Functions.OnKeyboardDown);
            Glut.glutKeyboardUpFunc(Functions.OnKeyboardUp);
            Glut.glutCloseFunc(Functions.OnClose);
            Glut.glutReshapeFunc(Functions.OnReshape);

            Gl.Enable(EnableCap.DepthTest);
            Gl.ClearColor(0, 0.6f, 0.56f, 1);

            Shader VertexShader   = new Shader("\\shaders\\vertex_shader.txt");
            Shader FragmentShader = new Shader("\\shaders\\fragment_shader.txt");

            Data.program = new ShaderProgram(VertexShader.shaderCode,
                                             FragmentShader.shaderCode);

            Data.program.Use();

            Data.program["projection_matrix"].SetValue(
                Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)Data.width /
                                                     Data.height, 0.1f, 1000f));
            Data.program["view_matrix"].SetValue(Matrix4.LookAt(Data.cameraPos,
                                                                Data.cameraFront, Data.cameraUp));
            Data.program["light_direction"].SetValue(Data.lightDir);
            Data.program["enable_lighting"].SetValue(Data.lighting);

            Data.objects.Add(new Pyramid());
            Data.curTexture = new Texture(Data.dir + "\\im\\crate.jpg");
            Data.objects.Add(new Cube(true));
            Data.objects.Add(new Plane(
                                 new Vector3(-2, 20, -40),
                                 new Vector3(100, 20, -10),
                                 new Vector3(100, -0.5f, -5),
                                 new Vector3(-2, -0.5f, -35),
                                 new Vector3(0.6f, 0.75f, 0.6f)
                                 ));

            Data.objects.Add(new Plane(
                                 new Vector3(-2, 20, -40),
                                 new Vector3(-100, 20, -10),
                                 new Vector3(-100, -0.5f, -5),
                                 new Vector3(-2, -0.5f, -35),
                                 new Vector3(0.2f, 0.2f, 0.64f)
                                 ));


            Data.objects.Add(new Plane(
                                 new Vector3(-200, -1.0f, 1000),
                                 new Vector3(-200, -1.0f, -1000),
                                 new Vector3(200, -1.0f, -1000),
                                 new Vector3(200, -1.0f, 1000),
                                 new Vector3(0.2f, 0.85f, 0.64f)
                                 ));

            if (Data.isTimeRotate)
            {
                Data.watch = System.Diagnostics.Stopwatch.StartNew();
            }
            Glut.glutMainLoop();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            //Open GL init
            #region
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(1280, 720);
            Glut.glutCreateWindow("Tu mama es maraca");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);
            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);
            //Keyboard functions
            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Gl.ClearColor(0, 0, 0, 1);

            //Alpha enabled

            Gl.Enable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Blend);
            //Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            #endregion

            //Load shader
            program = new ShaderProgram(VertexShader, FragmentShader);

            //Create perspective
            program.Use();
            program["projection_matrix"].SetValue(
                Matrix4.CreatePerspectiveFieldOfView(0.45f,
                                                     (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(
                Matrix4.LookAt(new Vector3(0, 0, 10),
                               new Vector3(xCam, 0, zCam),
                               new Vector3(0, 1, 0)));
            //Create light
            program["light_direction"].SetValue(new Vector3(0, 0, 1));
            program["enable_lighting"].SetValue(lighting);



            //Cube vertices and uv
            #region
            crateTexture = new Texture("crate.jpg");
            cube         = new VBO <Vector3>(
                new Vector3[] {
                new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1),
                new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1),
                new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1),
                new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1),
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1),
                new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1),
            }
                );
            cubeElements = new VBO <int>(
                new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 },
                BufferTarget.ElementArrayBuffer
                );
            cubeUV = new VBO <Vector2>(
                new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            }
                );
            #endregion

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("Project #3");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            // add our mouse callbacks for this tutorial
            Glut.glutMouseFunc(OnMouse);
            Glut.glutMotionFunc(OnMove);

            Gl.Enable(EnableCap.DepthTest);

            // create our shader program
            program = new ShaderProgram(VertexShader, FragmentShader);

            // set up the projection and view matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0)));

            program["light_direction"].SetValue(new Vector3(0, 0, 1));
            program["enable_lighting"].SetValue(lighting);
            program["normalTexture"].SetValue(1);
            program["enable_mapping"].SetValue(normalMapping);

            brickDiffuse = new Texture(@"D:\Diego Jacobs\Google Dirve\UVG\Semestre 9\Graficas\Proyecto 3\3D-House\3D-House\Images\AlternatingBrick-ColorMap.png");
            brickNormals = new Texture(@"D:\Diego Jacobs\Google Dirve\UVG\Semestre 9\Graficas\Proyecto 3\3D-House\3D-House\Images\AlternatingBrick-NormalMap.png");

            // create a pyramid
            pyramid = new VBO<Vector3>(new Vector3[] {
                new Vector3(-1, 1, 1), new Vector3(1, 1, 1), new Vector3(0, 2, 0),        // front face
                new Vector3(1, 1, 1), new Vector3(0, 2, 0), new Vector3(1, 1, -1),        // right face
                new Vector3(-1, 1, -1), new Vector3(0, 2, 0), new Vector3(1, 1, -1),      // back face
                new Vector3(-1, 1, 1), new Vector3(0, 2, 0), new Vector3(-1, 1, -1) });   // left face
            pyramidTriangles = new VBO<int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, BufferTarget.ElementArrayBuffer);


            Vector3[] vertices = new Vector3[] {
                new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1),         // top
                new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1),     // bottom
                new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1),         // front face
                new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1),     // back face
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1),     // left
                new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1) };       // right
            cube = new VBO<Vector3>(vertices);

            Vector2[] uvs = new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1) };
            cubeUV = new VBO<Vector2>(uvs);

            List<int> triangles = new List<int>();
            for (int i = 0; i < 6; i++)
            {
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 1);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4 + 3);
            }
            cubeTriangles = new VBO<int>(triangles.ToArray(), BufferTarget.ElementArrayBuffer);

            Vector3[] normals = Geometry.CalculateNormals(vertices, triangles.ToArray());
            cubeNormals = new VBO<Vector3>(normals);

            Vector3[] tangents = CalculateTangents(vertices, normals, triangles.ToArray(), uvs);
            cubeTangents = new VBO<Vector3>(tangents);
            
            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);   // multisampling makes things beautiful!
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            // enable blending and set to accumulate the star colors
            Gl.Enable(EnableCap.Blend);
            Gl.Enable(EnableCap.ProgramPointSize);
            Gl.Enable(EnableCap.Multisample);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);

            // create our shader program
            program = new ShaderProgram(VertexShader, FragmentShader);

            // set up the projection and view matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 20), Vector3.Zero, new Vector3(0, 1, 0)));
            program["model_matrix"].SetValue(Matrix4.Identity);
            program["static_colors"].SetValue(true);

            // load the particle texture
            particleTexture = new Texture("smoke.bmp");

            // set up the particlePoints VBO, which will stay constant
            int[] points = new int[particleCount];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = i;
            }
            particlePoints = new VBO <int>(points, BufferTarget.ElementArrayBuffer);

            // set up the particleColors, which we'll just keep static
            Vector3[] colors = new Vector3[particleCount];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = new Vector3(0.1f, 0.1f, 0.1f);
            }
            particleColors = new VBO <Vector3>(colors);

            // build up our first batch of 1000 particles and 1000 static colors
            for (int i = 0; i < particleCount; i++)
            {
                particles.Add(new Particle(Vector3.Zero, 0));
            }

            // load the bitmap font for this tutorial
            font        = new BMFont("font24.fnt", "font24.png");
            fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource);

            fontProgram.Use();
            fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000));
            fontProgram["color"].SetValue(new Vector3(0.2f, 0.2f, 0.2f));

            information = font.CreateString(fontProgram, "OpenGL  C#  Tutorial  12");

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("Texture 3D Car");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            Gl.Disable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            program = new ShaderProgram(VertexShader, FragmentShader);

            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, new Vector3(0, 1, 0)));

            program["light_direction"].SetValue(new Vector3(0, 0, 1));
            program["enable_lighting"].SetValue(lighting);

            glassTexture = new Texture("glass.bmp");
            kacaTexture  = new Texture("kaca.bmp");
            rodaTexture  = new Texture("tire.bmp");

            cube = new VBO <Vector3>(new Vector3[] {
                /* top of cube.*/
                new Vector3(0.2f, 0.4f, 0.6f),
                new Vector3(0.6f, 0.5f, 0.6f),
                new Vector3(0.6f, 0.5f, 0.2f),
                new Vector3(0.2f, 0.4f, 0.2f),

                /* bottom of, cube*/
                new Vector3(0.2f, 0.2f, 0.6f),
                new Vector3(0.6f, 0.2f, 0.6f),
                new Vector3(0.6f, 0.2f, 0.2f),
                new Vector3(0.2f, 0.2f, 0.2f),

                /* front of cube.*/
                new Vector3(0.2f, 0.2f, 0.6f),
                new Vector3(0.2f, 0.4f, 0.6f),
                new Vector3(0.2f, 0.4f, 0.2f),
                new Vector3(0.2f, 0.2f, 0.2f),

                /* back of cube.*/
                new Vector3(0.6f, 0.2f, 0.6f),
                new Vector3(0.6f, 0.5f, 0.6f),
                new Vector3(0.6f, 0.5f, 0.2f),
                new Vector3(0.6f, 0.2f, 0.2f),

                /* left of cube*/
                new Vector3(0.2f, 0.2f, 0.6f),
                new Vector3(0.6f, 0.2f, 0.6f),
                new Vector3(0.6f, 0.5f, 0.6f),
                new Vector3(0.2f, 0.4f, 0.6f),

                /* Right of cube */
                new Vector3(0.2f, 0.2f, 0.2f),
                new Vector3(0.6f, 0.2f, 0.2f),
                new Vector3(0.6f, 0.5f, 0.2f),
                new Vector3(0.2f, 0.4f, 0.2f),
                //****************************************************************************
                new Vector3(0.7f, 0.65f, 0.6f),
                new Vector3(0.7f, 0.65f, 0.2f),
                new Vector3(1.7f, 0.65f, 0.2f),     //top cover
                new Vector3(1.7f, 0.65f, 0.6f),

                //******************MIDDLE BODY************************************
                new Vector3(0.6f, 0.5f, 0.6f),
                new Vector3(0.6f, 0.2f, 0.6f),
                new Vector3(1.8f, 0.2f, 0.6f),
                new Vector3(1.8f, 0.5f, 0.6f),

                new Vector3(1.8f, 0.2f, 0.6f),
                new Vector3(1.8f, 0.2f, 0.2f),
                new Vector3(1.8f, 0.5f, 0.2f),
                new Vector3(1.8f, 0.5f, 0.6f),
                /* bottom of cube*/
                new Vector3(0.6f, 0.2f, 0.6f),
                new Vector3(0.6f, 0.2f, 0.2f),
                new Vector3(1.8f, 0.2f, 0.2f),
                new Vector3(1.8f, 0.2f, 0.6f),

                /* back of cube.*/
                new Vector3(0.6f, 0.5f, 0.2f),
                new Vector3(0.6f, 0.2f, 0.2f),
                new Vector3(1.8f, 0.2f, 0.2f),
                new Vector3(1.8f, 0.5f, 0.2f),

                new Vector3(0.7f, 0.65f, 0.2f),
                new Vector3(0.7f, 0.5f, .2f),    //first separation
                new Vector3(0.75f, 0.5f, 0.2f),
                new Vector3(0.77f, 0.65f, 0.2f),

                new Vector3(1.2f, 0.65f, 0.2f),
                new Vector3(1.2f, 0.5f, .2f),    //second separation
                new Vector3(1.25f, 0.5f, 0.2f),
                new Vector3(1.27f, 0.65f, 0.2f),

                new Vector3(1.65f, 0.65f, 0.2f),
                new Vector3(1.65f, 0.5f, .2f),  //3d separation
                new Vector3(1.7f, 0.5f, 0.2f),
                new Vector3(1.7f, 0.65f, 0.2f),

                new Vector3(0.75f, 0.65f, 0.2f),
                new Vector3(0.75f, 0.63f, 0.2f),     //line strip
                new Vector3(1.7f, 0.63f, 0.2f),
                new Vector3(1.7f, 0.65f, 0.2f),

                new Vector3(0.75f, 0.65f, 0.6f),
                new Vector3(0.75f, 0.63f, 0.6f),     //line strip
                new Vector3(1.7f, 0.63f, 0.6f),
                new Vector3(1.7f, 0.65f, 0.6f),


                new Vector3(0.7f, 0.65f, 0.6f),
                new Vector3(0.7f, 0.5f, .6f),    //first separation
                new Vector3(0.75f, 0.5f, 0.6f),
                new Vector3(0.77f, 0.65f, 0.6f),

                new Vector3(1.2f, 0.65f, 0.6f),
                new Vector3(1.2f, 0.5f, .6f),    //second separation
                new Vector3(1.25f, 0.5f, 0.6f),
                new Vector3(1.27f, 0.65f, 0.6f),

                new Vector3(1.65f, 0.65f, 0.6f),
                new Vector3(1.65f, 0.5f, .6f),
                new Vector3(1.7f, 0.5f, 0.6f), //3d separation
                new Vector3(1.7f, 0.65f, 0.6f),
            });                                // right


            cubeNormals = new VBO <Vector3>(new Vector3[] {
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0),
                new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0),
                new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1),
                new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1),
                new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0),
                new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0),
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0),
                new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0),
                new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1),
                new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1),
                new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0),
                new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0),
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0),
                new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0),
                new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1),
                new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1),
                new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0),
                new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0),
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0)
            });
            cubeUV = new VBO <Vector2>(new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            });

            cubeQuads = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107 }, BufferTarget.ElementArrayBuffer);

            window = new VBO <Vector3>(new Vector3[] {
                new Vector3(0.77f, 0.63f, 0.2f),
                new Vector3(0.75f, 0.5f, 0.2f),     //quad front window
                new Vector3(1.2f, 0.5f, 0.2f),
                new Vector3(1.22f, 0.63f, 0.2f),

                new Vector3(1.27f, 0.63f, .2f),
                new Vector3(1.25f, 0.5f, 0.2f),     //quad back window
                new Vector3(1.65f, 0.5f, 0.2f),
                new Vector3(1.67f, 0.63f, 0.2f),


                new Vector3(0.77f, 0.63f, 0.6f),
                new Vector3(0.75f, 0.5f, 0.6f),     //quad front window
                new Vector3(1.2f, 0.5f, 0.6f),
                new Vector3(1.22f, 0.63f, 0.6f),

                new Vector3(1.27f, 0.63f, 0.6f),
                new Vector3(1.25f, 0.5f, 0.6f),     //quad back window
                new Vector3(1.65f, 0.5f, 0.6f),
                new Vector3(1.67f, 0.63f, 0.6f),


                new Vector3(0.6f, 0.5f, 0.6f),
                new Vector3(0.6f, 0.5f, 0.2f),     //quad f,ront window
                new Vector3(0.7f, 0.65f, 0.2f),
                new Vector3(0.7f, 0.65f, 0.6f),

                new Vector3(1.7f, 0.65f, .6f),
                new Vector3(1.7f, 0.65f, 0.2f),     //quad back window
                new Vector3(1.8f, 0.5f, 0.2f),
                new Vector3(1.8f, 0.5f, 0.6f),

                new Vector3(0.6f, 0.5f, 0.6f),
                new Vector3(0.7f, 0.65f, 0.6f),    //tri f,ront window
                new Vector3(0.7f, 0.5f, 0.6f),

                new Vector3(0.6f, 0.5f, 0.2f),
                new Vector3(0.7f, 0.65f, 0.2f),    //tri f,ront window
                new Vector3(0.7f, 0.5f, 0.2f),
                new Vector3(0.7f, 0.5f, 0.3f),

                new Vector3(1.7f, 0.65f, 0.2f),
                new Vector3(1.8f, 0.5f, 0.2f),    //tri back window
                new Vector3(1.7f, 0.5f, 0.2f),
                new Vector3(1.7f, 0.5f, 0.3f),

                new Vector3(1.7f, 0.65f, 0.6f),
                new Vector3(1.8f, 0.5f, 0.6f),    //tri back window
                new Vector3(1.7f, 0.5f, 0.6f),
                new Vector3(1.7f, 0.5f, 0.7f)
            });      // right


            windowNormals = new VBO <Vector3>(new Vector3[] {
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0),
                new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0),
                new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1),
                new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1),
                new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0), new Vector3(-1, 0, 0),
                new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0),
                new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0),
                new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0), new Vector3(0, -1, 0),
                new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1), new Vector3(0, 0, 1),
                new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1), new Vector3(0, 0, -1)
            });
            windowUV = new VBO <Vector2>(new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            });

            windowQuads = new VBO <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 }, BufferTarget.ElementArrayBuffer);

            //wheeel-----------------------------------------------------------------------------------------------
            // Number of segments the circle is divided into.
            const int DIV_COUNT = 32;

            // Will use a triangle fan rooted at the origin to draw the circle. So one additional
            // point is needed for the origin, and another one because the first point is repeated
            // as the last one to close the circle.
            Vector3[] coordA = new Vector3[(DIV_COUNT + 2) * 2];

            // Origin.
            int coordIdx = 0;

            // Calculate angle increment from point to point, and its cos/sin.
            float   angInc = DIV_COUNT * 3.1415926535897932384626433832795f / 180;
            float   cosInc = (float)Math.Cos(angInc);
            float   sinInc = (float )Math.Sin(angInc);
            float   radius = 0.1f;
            float   depth  = 0.1f;
            Vector3 center = new Vector3(0.6f, 0.2f, 0.55f);

            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            float xc = radius;
            float yc = 0.0f;

            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            wheel1 = new VBO <Vector3>(coordA);      // right

            // UM --------------------------------------------------------------------------------------

            // Origin.
            coordIdx = 0;
            center   = new Vector3(0.6f, 0.2f, 0.55f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 2;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            wheel11 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.55f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 2;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            wheel21 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(0.6f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 2;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            wheel31 = new VBO <Vector3>(coordA);      // right
                                                      // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 2;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 2, center.Y, center.Z + depth);

            wheel41 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(0.6f, 0.2f, 0.55f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 4;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            wheel111 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.55f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 4;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            wheel211 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(0.6f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 4;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            wheel311 = new VBO <Vector3>(coordA);      // right
                                                       // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 4;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 4, center.Y, center.Z + depth);

            wheel411 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(0.6f, 0.2f, 0.55f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 1.5f;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            wheel112 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.55f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 1.5f;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            wheel212 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(0.6f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 1.5f;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            wheel312 = new VBO <Vector3>(coordA);      // right
                                                       // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius / 1.5f;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius / 1.5f, center.Y, center.Z + depth);

            wheel412 = new VBO <Vector3>(coordA);      // right

            // UM --------------------------------------------------------------------------------------

            // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.55f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            wheel2 = new VBO <Vector3>(coordA);      // right

            // Origin.
            coordIdx = 0;
            center   = new Vector3(0.6f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            wheel3 = new VBO <Vector3>(coordA);      // right
                                                     // Origin.
            coordIdx = 0;
            center   = new Vector3(1.5f, 0.2f, 0.15f);
            // Start with vector (1.0f, 0.0f), ...

            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            // ... and then rotate it by angInc for each point.
            xc = radius;
            yc = 0.0f;
            for (int iDiv = 0; iDiv < DIV_COUNT; ++iDiv)
            {
                float xcNew = cosInc * xc - sinInc * yc;
                yc = sinInc * xc + cosInc * yc;
                xc = xcNew;

                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z);
                coordA[coordIdx++] = new Vector3(xc + center.X, yc + center.Y, center.Z + depth);
            }
            // Start with vector (1.0f, 0.0f), ...
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z);
            coordA[coordIdx++] = new Vector3(center.X + radius, center.Y, center.Z + depth);

            wheel4 = new VBO <Vector3>(coordA);      // right

            int[]     quads   = new int[(DIV_COUNT + 2) * 2];
            Vector3[] normals = new Vector3[(DIV_COUNT + 2) * 2];
            for (int i = 0; i < (DIV_COUNT + 2) * 2; i++)
            {
                normals[i] = new Vector3(0, 1, 0);
                quads[i]   = i;
            }

            Vector2[] UVs = new Vector2[(DIV_COUNT + 2) * 2];
            for (int i = 0; i < (DIV_COUNT + 2) * 2 - 3; i = i + 4)
            {
                UVs[i]     = new Vector2(0, 0);
                UVs[i + 1] = new Vector2(1, 0);
                UVs[i + 2] = new Vector2(1, 1);
                UVs[i + 3] = new Vector2(0, 1);
            }
            wheel1Normals = new VBO <Vector3>(normals);
            wheel1UV      = new VBO <Vector2>(UVs);
            wheel1Quads   = new VBO <int>(quads, BufferTarget.ElementArrayBuffer);

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }