Beispiel #1
0
        /*private void keyboard(byte key, int x, int y)
         * {
         *      int mod = Glut.glutGetModifiers();
         *              if(mod==Glut.GLUT_ACTIVE_CTRL) ctrl=true;
         *              else ctrl=false;
         * }*/

        /**
         * luo glut ikkuna, aseta callbackit ja luo tyhjä texture
         */
        void create(int width, int height)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB);
            Glut.glutInitWindowSize(width, height);
            Glut.glutInitWindowPosition(100, 100);
            Glut.glutCreateWindow("CSPaint");

            Glut.glutDisplayFunc(new Glut.DisplayCallback(display));
            Glut.glutMouseFunc(new Glut.MouseCallback(mouseButton));
            Glut.glutMotionFunc(new Glut.MotionCallback(mouseMotion));
            Glut.glutCloseFunc(new Glut.CloseCallback(closeWindow));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(reshape));
            //Glut.glutKeyboardFunc(new Glut.KeyboardCallback(keyboard));

            Gl.glDisable(Gl.GL_LIGHTING);
            Gl.glClearColor(1, 1, 1, 1);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glDisable(Gl.GL_CULL_FACE);

            Gl.glDisable(Gl.GL_DEPTH_TEST);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Gl.glOrtho(0, width, height, 0, -1, 1);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();

            // luo yksi taso
            newLayer();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            int i, j;

            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGBA);
            Glut.glutInitWindowSize(320, 320);
            Glut.glutInitWindowPosition(50, 50);
            Glut.glutCreateWindow("Null");

            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));
            Glut.glutMouseFunc(new Glut.MouseCallback(Mouse));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));

            // Create a pretty color ramp
            for (j = 0; j < 256; j++)
            {
                for (i = 0; i < 256; i++)
                {
                    image[(256 * j + i) * 3 + 0] = (byte)(255 - i * j / 255);
                    image[(256 * j + i) * 3 + 1] = (byte)i;
                    image[(256 * j + i) * 3 + 2] = (byte)j;
                }
            }

            Glut.glutMainLoop();
        }
        public static void Main2

            (string[] argv)
        {
            Glut.glutInit();
            //Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_ALPHA | Glut.GLUT_DEPTH);
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(winW, winH);
            Glut.glutCreateWindow("GLViewer");

            Init();

            //if (argv.Length <= 0) return;

            model = new ThreeDSFile("c:\\bmw.3ds" /*argv[0]*/).ThreeDSModel;

            PrintInstructions();

            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutIdleFunc(new Glut.IdleCallback(Idle));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutKeyboardUpFunc(new Glut.KeyboardUpCallback(KeyboardUp));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));
            Glut.glutMainLoop();
        }
Beispiel #4
0
        static void mouse(int btn, int state, int x, int y)
        {
            switch (btn)
            {
            case Glut.GLUT_RIGHT_BUTTON:
                if (state == Glut.GLUT_DOWN)
                {
                    estado.xMouse = x;
                    estado.yMouse = y;
                    if (Glut.glutGetModifiers() == 1 & Glut.GLUT_ACTIVE_CTRL == 1)
                    {
                        Glut.glutMotionFunc(motionZoom);
                    }
                    else
                    {
                        Glut.glutMotionFunc(motionRotate);
                    }
                    Console.Write("Left down\n");
                }
                else
                {
                    Glut.glutMotionFunc(null);
                    Console.Write("Left up\n");
                }
                break;

            case Glut.GLUT_LEFT_BUTTON:
                if (state == Glut.GLUT_DOWN)
                {
                    estado.eixoTranslaccao = picking(x, y);
                    if (estado.eixoTranslaccao != -4 && estado.eixoTranslaccao < 0)
                    {
                        Glut.glutMotionFunc(motionDrag);
                    }
                    else
                    {
                        Console.Write("Right down - objecto:" + estado.eixoTranslaccao + "\n");
                    }
                }
                else
                {
                    if (estado.eixoTranslaccao != -4 && estado.eixoTranslaccao < 0)
                    {
                        estado.camera.center[0] = estado.eixo[0];
                        estado.camera.center[1] = estado.eixo[1];
                        estado.camera.center[2] = estado.eixo[2];
                        Glut.glutMotionFunc(null);
                        estado.eixoTranslaccao = -4;
                        Glut.glutPostRedisplay();
                    }
                    Console.Write("Right up\n");
                    if (estado.eixoTranslaccao >= 0)
                    {
                        Console.Write("carregou num no");
                    }
                }
                break;
            }
        }
Beispiel #5
0
 /**
  * loppulätinät
  */
 public void shutdown()
 {
     running = false;
     Glut.glutMouseFunc(null);
     Glut.glutMotionFunc(null);
     Glut.glutCloseFunc(null);
     Glut.glutReshapeFunc(null);
 }
Beispiel #6
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_ALPHA | Glut.GLUT_STENCIL | Glut.GLUT_MULTISAMPLE);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Gl.Enable(EnableCap.DepthTest);

            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.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

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

            // create our camera
            camera = new Camera(new Vector3(0, 0, 50), 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["model_matrix"].SetValue(Matrix4.Identity);

            objectFile = new ObjLoader("enterprise/enterprise.obj", program);

            // 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  16");

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

            Glut.glutMainLoop();
        }
Beispiel #7
0
 public static void Run()
 {
     Glut.glutInit();
     Glut.glutInitDisplayMode(Glut.GLUT_SINGLE | Glut.GLUT_RGB);
     Glut.glutInitWindowSize(250, 250);
     Glut.glutInitWindowPosition(100, 100);
     Glut.glutCreateWindow("Image");
     Init();
     Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
     Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
     Glut.glutMotionFunc(new Glut.MotionCallback(Motion));
     Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));
     Glut.glutMainLoop();
 }
Beispiel #8
0
        public void SetMainLoop()
        {
            //отлов действий пользователя
            Glut.glutMotionFunc(ClickedMotion);
            Glut.glutMouseFunc(Mouse);
            Glut.glutPassiveMotionFunc(PassiveMotion);
            Glut.glutKeyboardFunc(Key);
            Glut.glutKeyboardUpFunc(KeyUp);
            Glut.glutSpecialFunc(KeySpecial);
            Glut.glutSpecialUpFunc(KeySpecialUp);

            //старт игрового цикла
            Glut.glutTimerFunc(Config.TimePerFrame, MainProcess, 0);
            Glut.glutMainLoop();
        }
Beispiel #9
0
 static void Main()
 {
     Glut.glutInit();
     Glut.glutSetOption(Glut.GLUT_MULTISAMPLE, 8);
     Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGBA | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);
     Glut.glutInitWindowSize(Globals.defaultwindowwidth, Globals.defaultwindowheight);
     Glut.glutCreateWindow("Marvis Console");
     init_graphics();
     Glut.glutDisplayFunc(on_display);
     Glut.glutPassiveMotionFunc(on_mousemove);
     Glut.glutMotionFunc(on_mousemove);
     Glut.glutMouseFunc(on_mouseclick);
     Glut.glutMouseWheelFunc(on_mousewheel);
     Glut.glutIdleFunc(idle);
     Glut.glutReshapeFunc(on_reshape);
     Glut.glutMainLoop();
 }
Beispiel #10
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Initialisation_3D();
            Glut.glutReshapeFunc(On_Changement_Taille_Fenetre);
            Glut.glutDisplayFunc(Afficher_Ma_Scene);
            Glut.glutKeyboardFunc(Gestion_Clavier);
            Glut.glutSpecialFunc(Gestion_Touches_Speciales);
            Glut.glutIdleFunc(Animation_Scene);
            Glut.glutMouseFunc(Gestion_Bouton_Souris);
            Glut.glutMouseWheelFunc(Gestion_Molette);
            Glut.glutPassiveMotionFunc(Gestion_Souris_Libre);
            Glut.glutMotionFunc(Gestion_Souris_Clique);

            Initialisation_Animation();
            Glut.glutMainLoop();
        }
Beispiel #11
0
        public static void Run()
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DEPTH | Glut.GLUT_DOUBLE | Glut.GLUT_RGB);
            Glut.glutInitWindowSize(640, 480);
            Glut.glutInitWindowPosition(50, 50);
            Glut.glutCreateWindow("Network Integration");

            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutIdleFunc(new Glut.IdleCallback(Idle));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));
            Glut.glutMouseFunc(new Glut.MouseCallback(Mouse));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));
            Glut.glutVisibilityFunc(new Glut.VisibilityCallback(Visibility));

            Glut.glutMainLoop();
        }
Beispiel #12
0
        public static void Run()
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DEPTH | Glut.GLUT_DOUBLE | Glut.GLUT_RGB);
            Glut.glutInitWindowSize(512, 512);
            Glut.glutInitWindowPosition(50, 50);
            Glut.glutCreateWindow("Multiple Viewports");

            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));
            Glut.glutMouseFunc(new Glut.MouseCallback(Mouse));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));

            Init();
            BuildLists();

            Glut.glutMainLoop();
        }
Beispiel #13
0
 private void Objekt_Load(object sender, EventArgs e)
 {
     // OpenGL Window Initialisation ( GLUT )
     Glut.glutInit();
     Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
     Glut.glutInitWindowSize(width, height);
     Glut.glutCreateWindow("STL Viewer");
     Glut.glutInitWindowPosition(300, -300);
     Glut.glutKeyboardUpFunc(OnKeyboardMoves);
     Glut.glutReshapeFunc(Windowreshape);
     Glut.glutMouseWheelFunc(Mousewheel);
     Glut.glutMouseFunc(OnMouseMoves);
     Glut.glutMotionFunc(OnMove);
     // Glut running functions
     Glut.glutIdleFunc(OnRenderFrame);
     Glut.glutDisplayFunc(OnDisplay);
     // OpenGL Loop Method
     Glut.glutMainLoop();
 }
        static void Main()
        {
            // create an OpenGL window
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL UI: Example 1");

            // provide the Glut callbacks that are necessary for running this tutorial
            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(() => { });    // only here for mac os x
            Glut.glutCloseFunc(OnClose);
            Glut.glutMouseFunc(OnMouseClick);
            Glut.glutMotionFunc(OnMouseMove);
            Glut.glutPassiveMotionFunc(OnMouseMove);
            Glut.glutReshapeFunc(OnResize);
            Glut.glutKeyboardFunc(OnKeyboard);

            // enable depth testing to ensure correct z-ordering of our fragments
            Gl.Enable(EnableCap.DepthTest);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // initialize the user interface
            OpenGL.UI.UserInterface.InitUI(width, height);

            // create some centered text
            OpenGL.UI.Text welcome = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Welcome to OpenGL", OpenGL.UI.BMFont.Justification.Center);
            welcome.RelativeTo = OpenGL.UI.Corner.Center;

            // create some colored text
            OpenGL.UI.Text coloredText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "using C#", OpenGL.UI.BMFont.Justification.Center);
            coloredText.Position   = new Point(0, -30);
            coloredText.Color      = new Vector3(0.2f, 0.3f, 1f);
            coloredText.RelativeTo = OpenGL.UI.Corner.Center;

            // add the two text object to the UI
            OpenGL.UI.UserInterface.AddElement(welcome);
            OpenGL.UI.UserInterface.AddElement(coloredText);

            // enter the glut main loop (this is where the drawing happens)
            Glut.glutMainLoop();
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DEPTH | Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_MULTISAMPLE);
            Glut.glutInitWindowPosition(50, 50);
            Glut.glutInitWindowSize(w_win, h_win);
            Glut.glutCreateWindow("FTGL TEST");
            Glut.glutDisplayFunc(display);
            Glut.glutKeyboardFunc(parsekey);
            Glut.glutSpecialFunc(parseSpecialKey);
            Glut.glutMouseFunc(mouse);
            Glut.glutMotionFunc(motion);
            Glut.glutReshapeFunc(myReshape);
            Glut.glutIdleFunc(display);

            myinit();
            mytest();

            Glut.glutMainLoop();
        }
Beispiel #16
0
        public static void Init()
        {
            Keys              = new bool[255];
            KeysTyped         = new bool[255];
            SpecialKeys       = new bool[255];
            Mouse             = new bool[3];
            KeysTypedCooldown = new CooldownTimer[255];
            for (int i = 0; i < KeysTypedCooldown.Length; i++)
            {
                KeysTypedCooldown[i] = new CooldownTimer(3);
            }

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);
            Glut.glutSpecialFunc(OnSpecialDown);
            Glut.glutSpecialUpFunc(OnSpecialUp);
            Glut.glutMouseFunc(OnMousePress);
            Glut.glutMotionFunc(OnMouseMove);
            Glut.glutPassiveMotionFunc(OnMouseMove);
            Glut.glutMouseWheelFunc(OnMouseScroll);
        }
Beispiel #17
0
        public static void Run()
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_DEPTH);
            Glut.glutCreateWindow("SurfaceOld");
            Init();
            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));
            Glut.glutMouseFunc(new Glut.MouseCallback(Mouse));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));

            Glut.glutCreateMenu(new Glut.CreateMenuCallback(Menu));
            Glut.glutAddMenuEntry("Show control points", 1);
            Glut.glutAddMenuEntry("Hide control points", 0);
            Glut.glutAddMenuEntry("Solid", 2);
            Glut.glutAddMenuEntry("Wireframe", 3);
            Glut.glutAttachMenu(Glut.GLUT_RIGHT_BUTTON);

            Glut.glutMainLoop();
        }
Beispiel #18
0
        public static void Run()
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DEPTH | Glut.GLUT_RGB | Glut.GLUT_SINGLE);
            Glut.glutInitWindowSize(320, 320);
            Glut.glutInitWindowPosition(50, 50);
            Glut.glutCreateWindow("Strip (Click to draw)");

            for (int k = 0; k < MAXMESH; k++)
            {
                for (int i = 0; i < MAXMESH; i++)
                {
                    mesh[k, i] = (float)(Math.Sin((float)(i + k) / MAXMESH * PI) * 3);
                }
            }

            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));
            Glut.glutMouseFunc(new Glut.MouseCallback(Mouse));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));

            Glut.glutMainLoop();
        }
Beispiel #19
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);
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // 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 #20
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="argv">
        /// A <see cref="System.String"/>
        /// </param>
        public static void Main(string[] argv)
        {
            // instantiate GLUT for our windowing provider
            Glut.glutInit();
            //Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_ALPHA | Glut.GLUT_DEPTH);
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(winW, winH);
            Glut.glutCreateWindow("Salmon Viewer");

            // initialize our OpenGL parameters
            Init();

            // if no arguments, show message
            if (argv.Length <= 0)
            {
                Console.WriteLine("No file was specified.");

                return;
            }

            file = null;
            switch (Path.GetExtension(argv[0]).ToLower())
            {
            case ".3ds":

                try
                {
                    // Load our 3DS model from the command line argument
                    file  = new ThreeDSFile(argv[0]);
                    model = file.Model;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An Error occured: " + ex.Message);
                }
                break;

            //			case ".obj":
            //				new ObjFile(argv[0]);
            //				break;

            default:
                Console.WriteLine("Not a supported file type.");
                break;
            }

            modelCenter = new Vector((file.MaxX - file.MinX) / 2 + file.MinX,
                                     (file.MaxY - file.MinY) / 2 + file.MinY,
                                     (file.MaxZ - file.MinZ) / 2 + file.MinZ);

            // move eye so model is entirely visible at startup

            // center x/y at model's center x/y
            double width  = file.MaxX - file.MinX;
            double height = file.MaxY - file.MinY;

            eye[0] = Convert.ToSingle(file.MinX + width / 2);
            eye[1] = Convert.ToSingle(file.MinY + height / 2);

            // use trigonometry to calculate the z value that exposes the model
            eye[2] = Convert.ToSingle(file.MaxZ + (width > height ? width : height / 2) /
                                      Math.Tan((Math.PI / 180) * 90 / 2));

            // print viewer control keys to Console
            PrintInstructions();

            // instantiate GLUT event handlers
            Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
            Glut.glutIdleFunc(new Glut.IdleCallback(Idle));
            Glut.glutKeyboardFunc(new Glut.KeyboardCallback(Keyboard));
            Glut.glutKeyboardUpFunc(new Glut.KeyboardUpCallback(KeyboardUp));
            Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));
            Glut.glutMotionFunc(new Glut.MotionCallback(Motion));

            // start loop and wait for user input
            Glut.glutMainLoop();
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            AboutApp aboutApp = new AboutApp("OpenGL App", "1.0.0", "-----------", "Sebastian Tomczak, Politechnika Lubelska ", opis);

            Application.Run(aboutApp);

            if (aboutApp.GetStateOfStartOknoObslugi() == true)
            {
                PobieranieSciezki pobieranieSciezki = new PobieranieSciezki();

                Application.Run(pobieranieSciezki);
                objPath = pobieranieSciezki.GetObjPath();

                lighting         = pobieranieSciezki.wlaczenieSw;
                natezenieSwiatla = pobieranieSciezki.natezenieSw;
                kierunekSwiatlaX = pobieranieSciezki.kierunekSwX;
                kierunekSwiatlaY = pobieranieSciezki.kierunekSwY;
                kierunekSwiatlaZ = pobieranieSciezki.kierunekSwZ;

                startOpenGL = pobieranieSciezki.startOpenGL;
            }

            if (startOpenGL == true)
            {
                Glut.glutInit();

                MakingWindow(width, height, name);

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

                Glut.glutKeyboardFunc(OnKeyboardDown);                                                                                        //Funkcja obslugujaca nacisniecia przyciskow
                Glut.glutKeyboardUpFunc(OnKeyboardUp);                                                                                        //Funkcja obslugujaca nacisniecia przyciskow
                Glut.glutMouseFunc(OnMouse);                                                                                                  //Funckja obslugujaca ruch mysza
                Glut.glutMotionFunc(OnMove);                                                                                                  //Funckja obslugujaca ruch mysza

                Glut.glutCloseFunc(OnClose);                                                                                                  //Funkcja obslugujaca zamykanie wszystkiego

                shaderProgram = new ShaderProgram(VertexShader, FragmentShader);                                                              //Tworzenie programu odpowiedzialnego za Shadery

                kamera = new Camera(new Vector3(0, 0, 10f), Quaternion.Identity);                                                             //Wykorzystanie klasy Camera i stworzenie jej
                kamera.SetDirection(new Vector3(0, 0, -1.25f));                                                                               //Ustawienie kierunku kamery.

                shaderProgram.Use();                                                                                                          //uruchomienie programu odpowiedzialnego za Shadery
                shaderProgram["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f)); //Stworzenie stożka widoku
                shaderProgram["model_matrix"].SetValue(Matrix4.Identity);                                                                     //Ustawienie macierzy swiata

                shaderProgram["enable_lighting"].SetValue(lighting);

                shaderProgram["illuminance"].SetValue(natezenieSwiatla);

                shaderProgram["lightdirX"].SetValue(kierunekSwiatlaX);
                shaderProgram["lightdirY"].SetValue(kierunekSwiatlaY);
                shaderProgram["lightdirZ"].SetValue(kierunekSwiatlaZ);

                obiekt = new ObjLoader(objPath, shaderProgram);  //Stworzenie obiektu za pomoca klasy ObjLoader

                watch = System.Diagnostics.Stopwatch.StartNew(); //Rozpoczecie Stopwatcha potrzebnego do obrotow kamery czy z klawi. czy za pomoca myszy

                Glut.glutMainLoop();                             //start glownej petli Glut
            }
            else
            {
                MessageBox.Show("Zamknąłeś aplikację bez nadania ścieżki do obiektu,\r\nOpenGL nie może się uruchomić.", "Błąd inicjacji.");
            }
        }
Beispiel #22
0
        private void StartOpenGl()
        {
            exit = false;
            Glut.glutInit();


            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_ALPHA | Glut.GLUT_STENCIL |
                                     Glut.GLUT_MULTISAMPLE);

            // http://www.lighthouse3d.com/cg-topics/glut-and-freeglut/
            // Note: glutSetOption is only available with freeglut
            Glut.glutSetOption(Glut.GLUT_ACTION_ON_WINDOW_CLOSE, Glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS);

            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Test");


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

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutSpecialFunc(OnSpecialKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);
            Glut.glutSpecialUpFunc(OnSpecialKeyboardUp);

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

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

            #region GL_VERSION

            //this will return your version of opengl
            int major, minor;
            major = Gl.GetInteger(GetPName.MajorVersion);
            minor = Gl.GetInteger(GetPName.MinorVersion);
            GameCore.TheGameCore.RaiseMessage("Major " + major + " Minor " + minor);
//            Console.WriteLine("Major " + major + " Minor " + minor);
            //you can also get your GLSL version, although not sure if it varies from the above
            GameCore.TheGameCore.RaiseMessage("GLSL " + Gl.GetString(StringName.ShadingLanguageVersion));

            #endregion

            Gl.Enable(EnableCap.DepthTest);

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

            RenderObjects.RenderObjects.TheResourceManager = theResourceManager;

            Camera camera = new Camera(new Vector3(0, 20, 10), Quaternion.Identity);
            camera.SetDirection(new Vector3(1, -3, -1));
            TheGameStatus.TheEnvironment = new Environment();
            TheGameStatus.TheCamera      = camera;

            theSceneManager = new SceneManager(TheGameStatus, TheUserInputPlayer, theKeyBindings,
                                               theResourceManager, new RenderStatus()
            {
                Width = width, Height = height
            });

            theSceneManager.AddCamera(camera);

            theSceneManager.AddLayer(new RenderLayerSkyBox());
            theSceneManager.AddLayer(new RenderLayerGame());
            theSceneManager.AddLayer(new RenderLayerMapDrawArrays());
            theSceneManager.AddLayer(new RenderLayerHud());
            theSceneManager.AddLayer(layerInfo = new RenderLayerTextInfo());


            theSceneManager.OnLoad();

            watch = Stopwatch.StartNew();

            Glut.glutMainLoop();


            GameCore.TheGameCore.OnGameEventHandler(new GameEventArgs(GameEventArgs.Types.RendererExited));
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("Input the number of levels to recurse. Must be greater than or equal to zero.\r\n" +
                                      "Mouse to look and WASD to move. Hold R to run. F to toggle fullscreen.\r\n" +
                                      "O to toggle between walking and flying. When flying, use E/Q to ascend/descend.");
                    if ((levelNum = Convert.ToInt32(Console.ReadLine())) >= 0)
                    {
                        break;
                    }
                }
                catch
                {
                    Console.WriteLine("Please input an integer greater than or equal to zero.");
                }
            }

            // init GLUT and create window
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);   // multisampling purportedly "makes things beautiful!"
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("Fractal");

            // register main loop callbacks
            Glut.glutDisplayFunc(renderScene);
            Glut.glutIdleFunc(idle);
            Glut.glutCloseFunc(onClose);

            //register resize callback
            Glut.glutReshapeFunc(OnReshape);

            // register keyboard callbacks
            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            // register mouse callbacks
            Glut.glutMotionFunc(OnMove);
            Glut.glutPassiveMotionFunc(OnMove);

            //hide mouse
            Glut.glutSetCursor(Glut.GLUT_CURSOR_NONE);

            //enable depth testing
            Gl.Enable(EnableCap.DepthTest);

            //enable alpha blending
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

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

            //make a camera
            camera = new Camera(new Vector3(0, 0, 0), Quaternion.Identity); //set the camera starting location here
            camera.SetDirection(new Vector3(0, 0, -1));

            // set the view and projection matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.90f, (float)width / height, 0.01f, 1000f));

            program["light_direction"].SetValue(new Vector3(-0.3f, -0.8f, -0.7f));  //pink
            program["light2_direction"].SetValue(new Vector3(0.7f, -0.8f, 0.3f));   //cyan
            program["light3_direction"].SetValue(new Vector3(0.3f, -0.8f, 0.7f));   //celadon
            program["light4_direction"].SetValue(new Vector3(-0.7f, -0.8f, -0.3f)); //yellow
            program["enable_lighting"].SetValue(lighting);

            //set background color
            Gl.ClearColor(0.99f, 0.93f, 0.85f, 1f);

            // load each block's model and decomposition rule from files and add to blockRef
            int fCount = Directory.GetFiles("assets", "*", SearchOption.TopDirectoryOnly).Length;

            for (int n = 0; n < fCount / 2; ++n)
            {
                List <Vector3> indexVertices = new List <Vector3>();
                List <Vector3> indexNormals  = new List <Vector3>();
                List <Vector3> vertices      = new List <Vector3>();
                List <Vector3> normals       = new List <Vector3>();
                List <Vector3> edgeVertices  = new List <Vector3>();

                StreamReader sr = new StreamReader("assets/" + n.ToString() + ".txt");
                while (!sr.EndOfStream)
                {
                    string[] fields = sr.ReadLine().Split();
                    if (fields[0] == "v") //a vertex
                    {
                        Vector3 vertex = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                        indexVertices.Add(vertex);
                    }
                    else if (fields[0] == "vn") //a vertex normal
                    {
                        Vector3 normal = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                        indexNormals.Add(normal);
                    }
                    else if (fields[0] == "f") //a face
                    {
                        for (int i = 1; i < fields.Length; ++i)
                        {
                            string[] indices = fields[i].Split('/');
                            vertices.Add(indexVertices[Convert.ToInt32(indices[0]) - 1]);
                            normals.Add(indexNormals[Convert.ToInt32(indices[2]) - 1]);
                        }
                    }
                    else if (fields[0] == "l") //an edge
                    {
                        edgeVertices.Add(indexVertices[Convert.ToInt32(fields[1]) - 1]);
                        edgeVertices.Add(indexVertices[Convert.ToInt32(fields[2]) - 1]);
                    }
                }
                sr.Close();

                //create the block object
                Block newBlock = new Block();
                newBlock.position     = new Vector3(0, 0, 0);
                newBlock.yOrientation = 0;
                newBlock.scale        = new Vector3(1, 1, 1);
                newBlock.ID           = n;

                //fill the block object with data loaded from .obj above
                newBlock.verticeData = vertices.ToArray();
                newBlock.normalData  = normals.ToArray();

                newBlock.edgeVerticeData = edgeVertices.ToArray();

                blockRef.Add(newBlock);

                //load the decomposition rule for this block
                List <DecompBlock> newDRule = new List <DecompBlock>();
                float scaleConst            = 1;
                float unitConst             = 1;

                sr = new StreamReader("assets/" + n.ToString() + "rule.txt");
                while (!sr.EndOfStream)
                {
                    string[] fields = sr.ReadLine().Split();
                    if (fields[0] != "#") //check its not a comment
                    {
                        if (fields[0] == "!")
                        {
                            //setting scale down values. e.g. if set to 1/3 and 2/3, each new block would be scaled down
                            //by 1/3, and each 1 unit offset written in the rule file would be scaled to move the block 2/3 units instead.
                            //default 1 and 1: no scaling applied.
                            scaleConst = Convert.ToSingle(fields[1]);
                            unitConst  = Convert.ToSingle(fields[2]);
                        }
                        else
                        {
                            //load in fields
                            DecompBlock newDBlock = new DecompBlock();
                            newDBlock.ID             = Convert.ToInt32(fields[0]);
                            newDBlock.posOffset      = new Vector3(Convert.ToSingle(fields[1]), Convert.ToSingle(fields[2]), Convert.ToSingle(fields[3]));
                            newDBlock.xAngleOffset   = Convert.ToSingle(fields[4]);
                            newDBlock.extraScale     = new Vector3(1, 1, 1);
                            newDBlock.unitScaleConst = unitConst;
                            newDBlock.scaleDownConst = scaleConst;
                            if (fields.Length > 5)
                            {
                                newDBlock.extraScale = new Vector3(Convert.ToInt32(fields[5]), Convert.ToInt32(fields[6]), Convert.ToInt32(fields[7]));
                            }

                            //add block to rule
                            newDRule.Add(newDBlock);
                        }
                    }
                }
                sr.Close();

                decompRules.Add(newDRule);
            }

            Block seedBlock = blockRef[0];

            blocks = Decompose(seedBlock, levelNum);

            //merge all vertices and normals into a an interleaved vbo
            List <Vector3> preVertices = new List <Vector3>();
            List <Vector3> preNormals  = new List <Vector3>();
            List <Vector3> preEdges    = new List <Vector3>();

            foreach (Block block in blocks)
            {
                foreach (Vector3 point in block.verticeData)
                {
                    Vector4 preVertex = (new Vector4(point, 1)
                                         * Matrix4.CreateScaling(block.scale)
                                         * Matrix4.CreateRotationY(block.yOrientation)
                                         + new Vector4(block.position, 1));
                    preVertices.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2)));
                }

                foreach (Vector3 normal in block.normalData)
                {
                    Vector4 preNormal = (new Vector4(normal, 1)
                                         * Matrix4.CreateScaling(new Vector3(Math.Sign(block.scale[0]),
                                                                             Math.Sign(block.scale[1]),
                                                                             Math.Sign(block.scale[2])))
                                         * Matrix4.CreateRotationY(block.yOrientation));

                    preNormals.Add(new Vector3(Convert.ToSingle(Math.Round(preNormal.Get(0))),
                                               Convert.ToSingle(Math.Round(preNormal.Get(1))),
                                               Convert.ToSingle(Math.Round(preNormal.Get(2)))));
                }

                foreach (Vector3 point in block.edgeVerticeData)
                {
                    Vector4 preVertex = (new Vector4(point, 1)
                                         * Matrix4.CreateScaling(block.scale)
                                         * Matrix4.CreateRotationY(block.yOrientation)
                                         + new Vector4(block.position, 1));
                    preEdges.Add(new Vector3(preVertex.Get(0), preVertex.Get(1), preVertex.Get(2)));
                }
            }

            //exportOBJ(preVertices, preNormals); //exports fractal if left uncommented

            drawVertices = new VBO <Vector3>(preVertices.ToArray());
            drawNormals  = new VBO <Vector3>(preNormals.ToArray());
            drawEdges    = new VBO <Vector3>(preEdges.ToArray());

            List <uint> drawOrder = new List <uint>();

            for (int x = 0; x < preVertices.Count; ++x)
            {
                drawOrder.Add(Convert.ToUInt32(x));
            }
            drawElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer);

            drawOrder.Clear();
            for (int x = 0; x < preEdges.Count; ++x)
            {
                drawOrder.Add(Convert.ToUInt32(x));
            }
            drawEdgeElements = new VBO <uint>(drawOrder.ToArray(), BufferTarget.ElementArrayBuffer);

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

            // enter GLUT event processing cycle
            Glut.glutMainLoop();
        }
Beispiel #24
0
        static void Main()
        {
            // create an OpenGL window
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL UI: Example 2");

            // provide the Glut callbacks that are necessary for running this tutorial
            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(() => { });    // only here for mac os x
            Glut.glutCloseFunc(OnClose);
            Glut.glutMouseFunc(OnMouseClick);
            Glut.glutMotionFunc(OnMouseMove);
            Glut.glutPassiveMotionFunc(OnMouseMove);
            Glut.glutReshapeFunc(OnResize);
            Glut.glutKeyboardFunc(OnKeyboard);

            // enable depth testing to ensure correct z-ordering of our fragments
            Gl.Enable(EnableCap.DepthTest);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // initialize the user interface
            OpenGL.UI.UserInterface.InitUI(width, height);

            // create some centered text
            OpenGL.UI.Text selectText = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._24pt, "Select A Character", OpenGL.UI.BMFont.Justification.Center);
            selectText.Position   = new Point(0, 50);
            selectText.RelativeTo = OpenGL.UI.Corner.Center;

            OpenGL.UI.Text characterName = new OpenGL.UI.Text(OpenGL.UI.Text.FontSize._16pt, "", OpenGL.UI.BMFont.Justification.Center);
            characterName.RelativeTo = OpenGL.UI.Corner.Center;
            characterName.Position   = new Point(0, -70);

            // add the two text object to the UI
            OpenGL.UI.UserInterface.AddElement(selectText);
            OpenGL.UI.UserInterface.AddElement(characterName);

            // the license for these icons is located in the data folder
            string[] characters = new string[] { "boy.png", "man.png", "girl1.png", "girl2.png", "girl3.png" };
            textures = new Texture[characters.Length];
            int xoffset = -characters.Length * 80 / 2 + 40;

            for (int i = 0; i < characters.Length; i++)
            {
                string character = characters[i];

                // load a texture that will be used by a button
                textures[i] = new Texture(string.Format("data/{0}", character));

                // create buttons in a row, each of which uses a Texture (the Texture gives the initial size of the Button in pixels)
                OpenGL.UI.Button button = new OpenGL.UI.Button(textures[i]);
                button.Position   = new Point(xoffset, 5);
                button.RelativeTo = OpenGL.UI.Corner.Center;

                // change the color of the button when entering/leaving/clicking with the mouse
                button.OnMouseEnter = (sender, e) => button.BackgroundColor = new Vector4(0, 1f, 0.2f, 1.0f);
                button.OnMouseLeave = (sender, e) => button.BackgroundColor = Vector4.Zero;
                button.OnMouseDown  = (sender, e) => button.BackgroundColor = new Vector4(0, 0.6f, 1f, 1f);
                button.OnMouseUp    = (sender, e) => button.BackgroundColor = (OpenGL.UI.UserInterface.Selection == button ? new Vector4(0, 1f, 0.2f, 1.0f) : Vector4.Zero);

                // update the text with the character name when the button is clicked
                button.OnMouseClick = (sender, e) => characterName.String = string.Format("You selected {0}!", character);

                OpenGL.UI.UserInterface.AddElement(button);

                xoffset += 80;
            }

            // enter the glut main loop (this is where the drawing happens)
            Glut.glutMainLoop();
        }
Beispiel #25
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();
        }