예제 #1
0
        public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set and initialize the SDL2 window
            Window = new SDL2_GameWindow();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Create OpenGL context
            INTERNAL_GLContext = SDL.SDL_GL_CreateContext(Window.Handle);
            OpenTK.Graphics.GraphicsContext.CurrentContext = INTERNAL_GLContext;

#if THREADED_GL
            // Create a background context
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
            Threading.WindowInfo        = Window.Handle;
            Threading.BackgroundContext = new GL_ContextHandle()
            {
                context = SDL.SDL_GL_CreateContext(Window.Handle)
            };

            // Make the foreground context current.
            SDL.SDL_GL_MakeCurrent(Window.Handle, INTERNAL_GLContext);
#endif

            // Set up the OpenGL Device. Loads entry points.
            OpenGLDevice.Initialize();

            // Create the OpenAL device
            OpenALDevice.Initialize();

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            wiiuPixelData = new byte[
                OpenGLDevice.Instance.Backbuffer.Width *
                OpenGLDevice.Instance.Backbuffer.Height *
                4
                            ];
#endif
        }
예제 #2
0
        public SDL2_GamePlatform(Game game) : base(game, Fna.FnaPlatform.Platform.GetSDLPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set and initialize the SDL2 window
            Window = new SDL2_GameWindow();

            // Create the DisplayMode list
            displayIndex = SDL.SDL_GetWindowDisplayIndex(
                Window.Handle
                );
            INTERNAL_GenerateDisplayModes();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Create the OpenAL device
            OpenALDevice.Initialize();

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            Rectangle bounds = Window.ClientBounds;
            wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
#endif
        }