DispatchEvents() публичный Метод

Call the event handlers for each pending event
public DispatchEvents ( ) : void
Результат void
Пример #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create the main window
            Window App = new Window(new VideoMode(640, 480, 32), "SFML.Net Window");

            // Setup event handlers
            App.Closed     += new EventHandler(OnClosed);
            App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            App.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Set the color and depth clear values
            Gl.glClearDepth(1.0F);
            Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);

            // Setup a perspective projection
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);

            float Time = 0.0F;

            // Start the game loop
            while (App.IsOpened())
            {
                // Process events
                App.DispatchEvents();

                // Set the active window before using OpenGL commands
                // It's useless here because the active window is always the same,
                // but don't forget it if you use multiple windows
                App.SetActive();

                // Clear color and depth buffer
                Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

                // Apply some transformations
                Time += App.GetFrameTime();
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(0.0F, 0.0F, -200.0F);
                Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F);
                Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F);
                Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F);

                // Draw a cube
                Gl.glBegin(Gl.GL_QUADS);

                    Gl.glColor3f(1.0F, 0.0F, 0.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F, -50.0F);

                    Gl.glColor3f(1.0F, 0.0F, 0.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F, 50.0F);
                    Gl.glVertex3f( 50.0F,  50.0F, 50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F, 50.0F);

                    Gl.glColor3f(0.0F, 1.0F, 0.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F,  50.0F);
                    Gl.glVertex3f(-50.0F, -50.0F,  50.0F);

                    Gl.glColor3f(0.0F, 1.0F, 0.0F);
                    Gl.glVertex3f(50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f(50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f(50.0F,  50.0F,  50.0F);
                    Gl.glVertex3f(50.0F, -50.0F,  50.0F);

                    Gl.glColor3f(0.0F, 0.0F, 1.0F);
                    Gl.glVertex3f(-50.0F, -50.0F,  50.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F,  50.0F);

                    Gl.glColor3f(0.0F, 0.0F, 1.0F);
                    Gl.glVertex3f(-50.0F, 50.0F,  50.0F);
                    Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, 50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, 50.0F,  50.0F);

                Gl.glEnd();

                // Finally, display the rendered frame on screen
                App.Display();
            }
        }
Пример #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Create the main window
            Window window = new Window(new VideoMode(640, 480, 32), "SFML.Net Window", Styles.Default, new ContextSettings(32, 0));
            window.SetVerticalSyncEnabled(true);

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Set the color and depth clear values
            Gl.glClearDepth(1.0F);
            Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);

            // Setup a perspective projection
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);

            int startTime = Environment.TickCount;

            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                // Activate the window before using OpenGL commands.
                // This is useless here because we have only one window which is
                // always the active one, but don't forget it if you use multiple windows
                window.SetActive();

                // Clear color and depth buffer
                Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

                // Apply some transformations
                float time = (Environment.TickCount - startTime) / 1000.0F;
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(0.0F, 0.0F, -200.0F);
                Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F);
                Gl.glRotatef(time * 30, 0.0F, 1.0F, 0.0F);
                Gl.glRotatef(time * 90, 0.0F, 0.0F, 1.0F);

                // Draw a cube
                Gl.glBegin(Gl.GL_QUADS);

                    Gl.glColor3f(1.0F, 0.0F, 0.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F, -50.0F);

                    Gl.glColor3f(1.0F, 0.0F, 0.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F, 50.0F);
                    Gl.glVertex3f( 50.0F,  50.0F, 50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F, 50.0F);

                    Gl.glColor3f(0.0F, 1.0F, 0.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f(-50.0F,  50.0F,  50.0F);
                    Gl.glVertex3f(-50.0F, -50.0F,  50.0F);

                    Gl.glColor3f(0.0F, 1.0F, 0.0F);
                    Gl.glVertex3f(50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f(50.0F,  50.0F, -50.0F);
                    Gl.glVertex3f(50.0F,  50.0F,  50.0F);
                    Gl.glVertex3f(50.0F, -50.0F,  50.0F);

                    Gl.glColor3f(0.0F, 0.0F, 1.0F);
                    Gl.glVertex3f(-50.0F, -50.0F,  50.0F);
                    Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, -50.0F,  50.0F);

                    Gl.glColor3f(0.0F, 0.0F, 1.0F);
                    Gl.glVertex3f(-50.0F, 50.0F,  50.0F);
                    Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, 50.0F, -50.0F);
                    Gl.glVertex3f( 50.0F, 50.0F,  50.0F);

                Gl.glEnd();

                // Finally, display the rendered frame on screen
                window.Display();
            }
        }
Пример #3
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Request a 32-bits depth buffer when creating the window
            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 32;

            // Create the main window
            Window window = new Window(new VideoMode(640, 480), "SFML window with OpenGL", Styles.Default, contextSettings);

            // Make it the active window for OpenGL calls
            window.SetActive();

            // Initialize OpenTK
            Toolkit.Init();
            GraphicsContext context = new GraphicsContext(new ContextHandle(IntPtr.Zero), null);

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Set the color and depth clear values
            GL.ClearDepth(1);
            GL.ClearColor(0, 0, 0, 1);

            // Enable Z-buffer read and write
            GL.Enable(EnableCap.DepthTest);
            GL.DepthMask(true);

            // Disable lighting and texturing
            GL.Disable(EnableCap.Lighting);
            GL.Disable(EnableCap.Texture2D);

            // Configure the viewport (the same size as the window)
            GL.Viewport(0, 0, (int)window.Size.X, (int)window.Size.Y);

            // Setup a perspective projection
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            float ratio = (float)(window.Size.X) / window.Size.Y;
            GL.Frustum(-ratio, ratio, -1, 1, 1, 500);

            // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
            float[] cube = new float[]
            {
                // positions    // colors (r, g, b, a)
                -50, -50, -50,  0, 0, 1, 1,
                -50,  50, -50,  0, 0, 1, 1,
                -50, -50,  50,  0, 0, 1, 1,
                -50, -50,  50,  0, 0, 1, 1,
                -50,  50, -50,  0, 0, 1, 1,
                -50,  50,  50,  0, 0, 1, 1,

                 50, -50, -50,  0, 1, 0, 1,
                 50,  50, -50,  0, 1, 0, 1,
                 50, -50,  50,  0, 1, 0, 1,
                 50, -50,  50,  0, 1, 0, 1,
                 50,  50, -50,  0, 1, 0, 1,
                 50,  50,  50,  0, 1, 0, 1,

                -50, -50, -50,  1, 0, 0, 1,
                 50, -50, -50,  1, 0, 0, 1,
                -50, -50,  50,  1, 0, 0, 1,
                -50, -50,  50,  1, 0, 0, 1,
                 50, -50, -50,  1, 0, 0, 1,
                 50, -50,  50,  1, 0, 0, 1,

                -50,  50, -50,  0, 1, 1, 1,
                 50,  50, -50,  0, 1, 1, 1,
                -50,  50,  50,  0, 1, 1, 1,
                -50,  50,  50,  0, 1, 1, 1,
                 50,  50, -50,  0, 1, 1, 1,
                 50,  50,  50,  0, 1, 1, 1,

                -50, -50, -50,  1, 0, 1, 1,
                 50, -50, -50,  1, 0, 1, 1,
                -50,  50, -50,  1, 0, 1, 1,
                -50,  50, -50,  1, 0, 1, 1,
                 50, -50, -50,  1, 0, 1, 1,
                 50,  50, -50,  1, 0, 1, 1,

                -50, -50,  50,  1, 1, 0, 1,
                 50, -50,  50,  1, 1, 0, 1,
                -50,  50,  50,  1, 1, 0, 1,
                -50,  50,  50,  1, 1, 0, 1,
                 50, -50,  50,  1, 1, 0, 1,
                 50,  50,  50,  1, 1, 0, 1,
            };

            // Enable position and color vertex components
            GL.EnableClientState(EnableCap.VertexArray);
            GL.EnableClientState(EnableCap.ColorArray);
            GL.VertexPointer(3, VertexPointerType.Float, 7 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0));
            GL.ColorPointer(4, ColorPointerType.Float, 7 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3));

            // Disable normal and texture coordinates vertex components
            GL.DisableClientState(EnableCap.NormalArray);
            GL.DisableClientState(EnableCap.TextureCoordArray);

            Clock clock = new Clock();

            // Start the game loop
            while (window.IsOpen)
            {
                // Process events
                window.DispatchEvents();

                // Clear color and depth buffer
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                // Apply some transformations
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();
                GL.Translate(0.0F, 0.0F, -200.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 50, 1.0F, 0.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 30, 0.0F, 1.0F, 0.0F);
                GL.Rotate(clock.ElapsedTime.AsSeconds() * 90, 0.0F, 0.0F, 1.0F);

                // Draw the cube
                GL.DrawArrays(BeginMode.Triangles, 0, 36);

                // Finally, display the rendered frame on screen
                window.Display();
            }
        }
Пример #4
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            // Request a 32-bits depth buffer when creating the window
            ContextSettings contextSettings = new ContextSettings();
            contextSettings.DepthBits = 32;

            // Create the main window
            Window window = new Window(new VideoMode(640, 480), "SFML window with OpenGL", Styles.Default, contextSettings);

            // Make it the active window for OpenGL calls
            window.SetActive();

            // Setup event handlers
            window.Closed     += new EventHandler(OnClosed);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
            window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

            // Set the color and depth clear values
            Gl.glClearDepth(1);
            Gl.glClearColor(0, 0, 0, 1);

            // Enable Z-buffer read and write
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthMask(Gl.GL_TRUE);

            // Disable lighting and texturing
            Gl.glDisable(Gl.GL_LIGHTING);
            Gl.glDisable(Gl.GL_TEXTURE_2D);

            // Configure the viewport (the same size as the window)
            Gl.glViewport(0, 0, (int)window.Size.X, (int)window.Size.Y);

            // Setup a perspective projection
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            float ratio = (float)(window.Size.X) / window.Size.Y;
            Gl.glFrustum(-ratio, ratio, -1, 1, 1, 500);

            // Define a 3D cube (6 faces made of 2 triangles composed by 3 vertices)
            float[] cube = new float[]
            {
                // positions    // colors (r, g, b, a)
                -50, -50, -50,  0, 0, 1, 1,
                -50,  50, -50,  0, 0, 1, 1,
                -50, -50,  50,  0, 0, 1, 1,
                -50, -50,  50,  0, 0, 1, 1,
                -50,  50, -50,  0, 0, 1, 1,
                -50,  50,  50,  0, 0, 1, 1,

                 50, -50, -50,  0, 1, 0, 1,
                 50,  50, -50,  0, 1, 0, 1,
                 50, -50,  50,  0, 1, 0, 1,
                 50, -50,  50,  0, 1, 0, 1,
                 50,  50, -50,  0, 1, 0, 1,
                 50,  50,  50,  0, 1, 0, 1,

                -50, -50, -50,  1, 0, 0, 1,
                 50, -50, -50,  1, 0, 0, 1,
                -50, -50,  50,  1, 0, 0, 1,
                -50, -50,  50,  1, 0, 0, 1,
                 50, -50, -50,  1, 0, 0, 1,
                 50, -50,  50,  1, 0, 0, 1,

                -50,  50, -50,  0, 1, 1, 1,
                 50,  50, -50,  0, 1, 1, 1,
                -50,  50,  50,  0, 1, 1, 1,
                -50,  50,  50,  0, 1, 1, 1,
                 50,  50, -50,  0, 1, 1, 1,
                 50,  50,  50,  0, 1, 1, 1,

                -50, -50, -50,  1, 0, 1, 1,
                 50, -50, -50,  1, 0, 1, 1,
                -50,  50, -50,  1, 0, 1, 1,
                -50,  50, -50,  1, 0, 1, 1,
                 50, -50, -50,  1, 0, 1, 1,
                 50,  50, -50,  1, 0, 1, 1,

                -50, -50,  50,  1, 1, 0, 1,
                 50, -50,  50,  1, 1, 0, 1,
                -50,  50,  50,  1, 1, 0, 1,
                -50,  50,  50,  1, 1, 0, 1,
                 50, -50,  50,  1, 1, 0, 1,
                 50,  50,  50,  1, 1, 0, 1,
            };

            // Enable position and color vertex components
            Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
            Gl.glEnableClientState(Gl.GL_COLOR_ARRAY);
            Gl.glVertexPointer(3, Gl.GL_FLOAT, 7 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 0));
            Gl.glColorPointer(4, Gl.GL_FLOAT, 7 * sizeof(float), Marshal.UnsafeAddrOfPinnedArrayElement(cube, 3));

            // Disable normal and texture coordinates vertex components
            Gl.glDisableClientState(Gl.GL_NORMAL_ARRAY);
            Gl.glDisableClientState(Gl.GL_TEXTURE_COORD_ARRAY);

            int startTime = Environment.TickCount;

            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                // Clear color and depth buffer
                Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

                // Apply some transformations
                float time = (Environment.TickCount - startTime) / 1000.0F;
                Gl.glMatrixMode(Gl.GL_MODELVIEW);
                Gl.glLoadIdentity();
                Gl.glTranslatef(0.0F, 0.0F, -200.0F);
                Gl.glRotatef(time * 50, 1.0F, 0.0F, 0.0F);
                Gl.glRotatef(time * 30, 0.0F, 1.0F, 0.0F);
                Gl.glRotatef(time * 90, 0.0F, 0.0F, 1.0F);

                // Draw the cube
                Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 36);

                // Finally, display the rendered frame on screen
                window.Display();
            }
        }