/// <summary>
        ///  Create a new SDL renderer.
        /// </summary>
        /// <param name="surface">Pointer to unmanaged SDL_Surface.</param>
        public SDLRenderer(SDLWindow window)
        {
            // Make sure the window is valid!
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            // Generate appropriate renderer flags.
            uint renderFlags = (uint)SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED |
                               (uint)SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC;

            // Create the renderer object and ensure that it was actually instantiated.
            mRenderer = SDL.SDL_CreateRenderer(window.WindowPtr, -1, renderFlags);

            if (mRenderer == IntPtr.Zero)
            {
                throw new SDLException("Failed to create SDL renderer");
            }
        }
Exemple #2
0
        /// <summary>
        ///  Create a new SDL renderer.
        /// </summary>
        /// <param name="surface">Pointer to unmanaged SDL_Surface.</param>
        public SDLRenderer( SDLWindow window )
        {
            // Make sure the window is valid!
            if ( window == null )
            {
                throw new ArgumentNullException( "window" );
            }

            // Generate appropriate renderer flags.
            uint renderFlags = (uint) SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED |
                               (uint) SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC;

            // Create the renderer object and ensure that it was actually instantiated.
            mRenderer = SDL.SDL_CreateRenderer( window.WindowPtr, -1, renderFlags );

            if ( mRenderer == IntPtr.Zero )
            {
                throw new SDLException( "Failed to create SDL renderer" );
            }
        }
Exemple #3
0
        private static void RunGame()
        {
            // Create the main render window.
            SDLWindow window = new SDLWindow( "An SDL2 window", 100, 100, 800, 600 );
            SDLRenderer renderer = new SDLRenderer( window );

            // Load a test image.
            SDLTexture texture = new SDLTexture( renderer, "hello.bmp" );

            SDLFont font = new SDLFont( renderer, "hello.ttf", 24 );
            SDLTexture textTexture = font.RenderTextBlended( renderer, "Hello World!!", Color.BlueColor );

            // Event loop.
            SDL.SDL_Event eventInfo = new SDL.SDL_Event();
            bool shouldQuit = false;

            while ( !shouldQuit )
            {
                CheckForSDLErrors();

                // Pump and process pending OS events.
                while ( SDL.SDL_PollEvent( out eventInfo ) != 0 )
                {
                    if ( eventInfo.type == SDL.SDL_EventType.SDL_QUIT )
                    {
                        shouldQuit = true;
                    }
                }

                // Render all of our stuffs.
                renderer.Clear();
                renderer.Draw( texture, 32, 32 );
                renderer.Draw( textTexture, 0, 400 );
                renderer.Present();    
            }
        }