Esempio n. 1
0
        private void Sync(bool pollEvents)
        {
            double dt          = 1 / 60.0;
            double currentTime = GLFW.glfwGetTime();

            // Main loop
            while (GLFW.glfwWindowShouldClose(Handle) == 0)
            {
                double newTime   = GLFW.glfwGetTime();
                double frameTime = newTime - currentTime;
                currentTime = newTime;

                while (frameTime > 0)
                {
                    double deltaTime = Math.Min(frameTime, dt);
                    frameTime -= deltaTime;

                    for (var i = 0; i < blocks.Length; i++)
                    {
                        blocks[i].UseDelta = useDelta;
                        blocks[i].Update(deltaTime, width, height);
                    }
                }

                // Render a background and enable some stuff for 2d rendering with alpha
                GL10.glMatrixMode(GL11.GL_PROJECTION);
                GL10.glLoadIdentity();
                GL10.glOrtho(0, width, height, 0, -1, 1);
                GL10.glMatrixMode(GL11.GL_MODELVIEW);
                GL10.glLoadIdentity();

                GL10.glEnable(GL11.GL_BLEND);
                GL10.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                GL10.glViewport(0, 0, Width, Height);
                GL10.glClearColor(0, 0, 0, 1);
                GL10.glClear(GL11.GL_COLOR_BUFFER_BIT);

                // Render
                for (var i = 0; i < blocks.Length; i++)
                {
                    blocks[i].Render();
                }

                GLFW.glfwSwapBuffers(Handle);
                GLFW.glfwPollEvents();
            }

            GLFW.glfwDestroyWindow(Handle);
        }