Example #1
0
        static void Main(string[] _)
        {
            //Console.WriteLine("Hello World!");

            //Glfw.Init();
            Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGl);
            Glfw.WindowHint(Hint.ContextVersionMajor, 3);
            Glfw.WindowHint(Hint.ContextVersionMinor, 3);
            Glfw.WindowHint(Hint.OpenGlProfile, Profile.Core);
            Glfw.WindowHint(Hint.Doublebuffer, true);
            Glfw.WindowHint(Hint.Decorated, true);
            Glfw.WindowHint(Hint.OpenGlForwardCompat, false);


            using (Window window = Glfw.CreateWindow(1280, 720, "Test", null, null))
            {
                Glfw.MakeContextCurrent(window);

                Glfw.SwapInterval(1);

                Monitor[] monitors = Monitor.Monitors;
                foreach (Monitor monitor in monitors)
                {
                    Console.Out.WriteLine($"Monitor {monitor.Name}:");
                    Console.Out.WriteLine($"Current VideoMode: {monitor.CurrentMode.Width}x{monitor.CurrentMode.Height}");
                    foreach (VideoMode mode in monitor.VideoModes)
                    {
                        Console.Out.WriteLine($"\t{mode.Width}x{mode.Height}");
                    }
                }

                Size      size     = window.Size;
                Rectangle workArea = Monitor.PrimaryMonitor.WorkArea;
                int       x        = (workArea.Width - size.Width) / 2;
                int       y        = (workArea.Height - size.Height) / 2;
                window.Position = new Point(x, y);

                glClearColor = Glfw.GetProcAddress <glClearColorHandler>("glClearColor");
                glClear      = Glfw.GetProcAddress <glClearHandler>("glClear");

                Glfw.OnKey += keyCallback;

                long tick = 0L;
                ChangeClearColor();
                while (!Glfw.WindowShouldClose(window))
                {
                    glClear(GL_COLOR_BUFFER_BIT);

                    Glfw.SwapBuffers(window);
                    Glfw.PollEvents();
                    if (++tick % 60 == 0)
                    {
                        ChangeClearColor();
                    }
                }
            }
            //Glfw.DestroyWindow(window);
            Glfw.Terminate();
        }
Example #2
0
        static void Main(string[] args)
        {
            // Set some common hints for the OpenGL profile creation
            Glfw.WindowHint(Hint.ClientApi, ClientApi.OpenGL);
            Glfw.WindowHint(Hint.ContextVersionMajor, 3);
            Glfw.WindowHint(Hint.ContextVersionMinor, 3);
            Glfw.WindowHint(Hint.OpenglProfile, Profile.Core);
            Glfw.WindowHint(Hint.Doublebuffer, true);
            Glfw.WindowHint(Hint.Decorated, true);
            Glfw.WindowHint(Hint.OpenglForwardCompatible, true);

            rand = new Random();

            #if OBJECTORIENTED
            // // The object oriented approach
            // using (var window = new NativeWindow(WIDTH, HEIGHT, title))
            // {
            //     window.CenterOnScreen();
            //     window.KeyPress += WindowOnKeyPress;
            //     while (!window.IsClosing)
            //     {
            //         Glfw.PollEvents();
            //         window.SwapBuffers();
            //     }
            // }
            #else
            // Create window
            var window = Glfw.CreateWindow(WIDTH, HEIGHT, TITLE, Monitor.None, Window.None);
            Glfw.MakeContextCurrent(window);

            // Effectively enables VSYNC by setting to 1.
            Glfw.SwapInterval(1);

            // Find center position based on window and monitor sizes
            var screenSize = Glfw.PrimaryMonitor.WorkArea;
            var x          = (screenSize.Width - WIDTH) / 2;
            var y          = (screenSize.Height - HEIGHT) / 2;
            Glfw.SetWindowPosition(window, x, y);

            // Set a key callback
            Glfw.SetKeyCallback(window, KeyCallback);


            glClearColor = Marshal.GetDelegateForFunctionPointer <glClearColorHandler>(Glfw.GetProcAddress("glClearColor"));
            glClear      = Marshal.GetDelegateForFunctionPointer <glClearHandler>(Glfw.GetProcAddress("glClear"));


            var tick = 0L;
            ChangeRandomColor();

            while (!Glfw.WindowShouldClose(window))
            {
                // Poll for OS events and swap front/back buffers
                Glfw.PollEvents();
                Glfw.SwapBuffers(window);

                // Change background color to something random every 60 draws
                if (tick++ % 60 == 0)
                {
                    ChangeRandomColor();
                }

                // Clear the buffer to the set color
                glClear(GL_COLOR_BUFFER_BIT);
            }
            #endif
        }