예제 #1
0
        public GtkGamePlatform(Game game, GLWidget widget)
            : base(game)
        {
            this.widget = widget;
            this.Window = new GtkGameWindow(this);

            // Setup our OpenALSoundController to handle our SoundBuffer pools TODO

            /*try
             * {
             *  soundControllerInstance = OpenALSoundController.GetInstance;
             * } catch (DllNotFoundException ex)
             * {
             *  throw (new NoAudioHardwareException("Failed to init OpenALSoundController", ex));
             * }*/

#if LINUX
            // also set up SdlMixer to play background music. If one of these functions fails, we will not get any background music (but that should rarely happen)
            Tao.Sdl.Sdl.SDL_InitSubSystem(Tao.Sdl.Sdl.SDL_INIT_AUDIO);
            Tao.Sdl.SdlMixer.Mix_OpenAudio(44100, (short)Tao.Sdl.Sdl.AUDIO_S16SYS, 2, 1024);

            //even though this method is called whenever IsMouseVisible is changed it needs to be called during startup
            //so that the cursor can be put in the correct inital state (hidden)
            OnIsMouseVisibleChanged();
#endif
        }
예제 #2
0
        public void Run(IGuiExternalInterface IGuiExternalInterface)
        {
            CommonGuiDisplayOpengl = new CommonGuiDisplayOpengl(IGuiExternalInterface, this);
            CommonGuiInput = new CommonGuiInput(IGuiExternalInterface);
            this.IGuiExternalInterface = IGuiExternalInterface;
            //var Window = new Window("Hello world!");
            Application.Init();
            Window = new Window("Soywiz's Psp Emulator");
            this.GLWidget = new GLWidget(OpenglGpuImpl.UsedGraphicsMode);
            Window.WindowPosition = WindowPosition.Center;
            Window.SetSizeRequest(480, 272);
            Window.Child = GLWidget;
            GLWidget.RenderFrame += GLWidget_RenderFrame;
            GLWidget.SetSizeRequest(480, 272);
            //GLWidget.ShowAll();
            Window.Removed += Window_Removed;
            Window.KeyPressEvent += Window_KeyPressEvent;
            Window.KeysChanged += Window_KeysChanged;
            Window.KeyReleaseEvent += Window_KeyReleaseEvent;

            Window.ShowAll();

            //GLWidget.KeyPressEvent += Window_KeyPressEvent;
            //GLWidget.KeyReleaseEvent += Window_KeyReleaseEvent;

            PspDisplay.DrawEvent += PspDisplay_DrawEvent;

            OpenOpenDialog();
            CommonGuiInput.ReLoadControllerConfig();

            Application.Run();
        }
예제 #3
0
        public GLWidget(GLWidget sharedContextWidget)
        {
            base.DoubleBuffered = false;
            Realized           += new EventHandler(HandleRealized);
            ExposeEvent        += new ExposeEventHandler(HandleExposeEvent);

            this.sharedContextWidget = sharedContextWidget;
        }
예제 #4
0
        public GtkGame(GLWidget widget)
            : base((game) => new GtkGamePlatform(game, widget))
        {
            OpenTK.Toolkit.Init();
            OpenTK.Graphics.OpenGL.GL.InitNames();
            var manager = new GraphicsDeviceManager(this)
            {
            };

            DoInitialize();
        }
 public GLWidget()
      : this(null)
 {
     if( globalSharedContextWidget == null)
     {
         globalSharedContextWidget = this;
     }
     else
     {
         sharedContextWidget = globalSharedContextWidget;
     }
 }
예제 #6
0
 public GLWidget()
     : this(null)
 {
     if (globalSharedContextWidget == null)
     {
         globalSharedContextWidget = this;
     }
     else
     {
         sharedContextWidget = globalSharedContextWidget;
     }
 }
예제 #7
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (widget != null)
                {
                    widget.Dispose();
                    widget = null;
                }
            }

            base.Dispose(disposing);
        }
        public VisualizationDisplayWidget()
        {
            Stetic.BinContainer.Attach(this);
            
            BuildHeaderExtension();

            this.visualizationList.Model = this.visualizationStore;

            CellRendererText text = new CellRendererText();
            this.visualizationList.PackStart(text, true);
            this.visualizationList.SetCellDataFunc(text, VisualizationCellDataFunc);

            this.glWidget = new GLWidget();
            this.glWidget.DoubleBuffered = true;
            this.glWidget.Render += this.OnRender;
            this.glWidget.SizeAllocated += this.OnGlSizeAllocated;
            this.glWidget.Show();
            
            this.Add(this.glWidget);
            this.Show();

            this.playerData = new BansheePlayerData(ServiceManager.PlayerEngine.ActiveEngine);
            this.playerData.Active = false;

            this.glWidget.Realized += delegate {
                if (!this.loopRunning) {
                    this.loopRunning = true;
                    this.RenderThread = new Thread(this.RenderLoop);
                    this.RenderThread.Start();
                }

                this.ConnectVisualization();
            };

            this.glWidget.Unrealized += delegate {
                this.DisposeRenderer();
            };
            
            AddinManager.AddExtensionNodeHandler("/Banshee/OpenVP/Visualization", this.OnVisualizationChanged);
        }
 public GLWidget(GLWidget sharedContextWidget)
 {
     base.DoubleBuffered = false;
     Realized += new EventHandler(HandleRealized);
     ExposeEvent += new ExposeEventHandler(HandleExposeEvent);
     
     this.sharedContextWidget = sharedContextWidget;
 }
예제 #10
0
        void HandleRealized(object sender, EventArgs eventArgs)
        {
            if (renderingContextHandle.Handle != IntPtr.Zero)
                return;
            
            switch (platformID)
            {
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    LoadLibrary("opengl32.dll");

                    IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle);
                    IntPtr deviceContext = GetDC(windowHandle);

                    PIXELFORMATDESCRIPTOR pixelFormatDescriptor = new PIXELFORMATDESCRIPTOR();
                    pixelFormatDescriptor.nSize = (short)System.Runtime.InteropServices.Marshal.SizeOf(pixelFormatDescriptor);
                    pixelFormatDescriptor.nVersion = 1;
                    pixelFormatDescriptor.iPixelType = PFD_TYPE_RGBA;
                    pixelFormatDescriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
                    if (doubleBuffer) pixelFormatDescriptor.dwFlags |= PFD_DOUBLEBUFFER;
                    pixelFormatDescriptor.cColorBits = colorBits;
                    pixelFormatDescriptor.cAlphaBits = alphaBits;
                    pixelFormatDescriptor.cDepthBits = depthBits;
                    pixelFormatDescriptor.cStencilBits = stencilBits;

                    int pixelFormat = ChoosePixelFormat(deviceContext, ref pixelFormatDescriptor);
                    if (!SetPixelFormat(deviceContext, pixelFormat, ref pixelFormatDescriptor)) throw new Exception("Cannot SetPixelFormat!");

                    IntPtr renderingContext = wglCreateContext(deviceContext);
                    renderingContextHandle = new HandleRef(this, renderingContext);

                    ReleaseDC(windowHandle, deviceContext);

                    if (sharedContextWidget != null)
                    {
                        GLWidget primaryWidget = sharedContextWidget;
                        while (primaryWidget.sharedContextWidget != null) primaryWidget = primaryWidget.sharedContextWidget;

                        if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero)
                        {
                            wglShareLists(primaryWidget.RenderingContextHandle.Handle, RenderingContextHandle.Handle);
                        }
                        else
                        {
                            this.sharedContextWidget = null;
                            primaryWidget.sharedContextWidget = this;
                        }
                    }

                    break;

                case PlatformID.Unix:
                default:
                    int[] attributeList = new int[24];
                    int attributeIndex = 0;

                    attributeList[attributeIndex++] = GLX_RGBA;
                    if (doubleBuffer) attributeList[attributeIndex++] = GLX_DOUBLEBUFFER;

                    attributeList[attributeIndex++] = GLX_RED_SIZE;
                    attributeList[attributeIndex++] = 1;

                    attributeList[attributeIndex++] = GLX_GREEN_SIZE;
                    attributeList[attributeIndex++] = 1;

                    attributeList[attributeIndex++] = GLX_BLUE_SIZE;
                    attributeList[attributeIndex++] = 1;

                    if (alphaBits != 0)
                    {
                        attributeList[attributeIndex++] = GLX_ALPHA_SIZE;
                        attributeList[attributeIndex++] = 1;
                    }

                    if (depthBits != 0)
                    {
                        attributeList[attributeIndex++] = GLX_DEPTH_SIZE;
                        attributeList[attributeIndex++] = 1;
                    }

                    if (stencilBits != 0)
                    {
                        attributeList[attributeIndex++] = GLX_STENCIL_SIZE;
                        attributeList[attributeIndex++] = 1;
                    }

                    attributeList[attributeIndex++] = GLX_NONE;

                    IntPtr xDisplay = gdk_x11_display_get_xdisplay(Screen.Display.Handle);
                    IntPtr visualIntPtr = IntPtr.Zero;

                    try
                    {
                        visualIntPtr = glXChooseVisual(xDisplay, Screen.Number, attributeList);
                    }
                    catch (DllNotFoundException e)
                    {
                        throw new Exception("OpenGL dll not found!", e);
                    }
                    catch (EntryPointNotFoundException enf)
                    {
                        throw new Exception("Glx entry point not found!", enf);
                    }

                    if (visualIntPtr == IntPtr.Zero)
                    {
                        throw new Exception("Visual");
                    }

                    XVisualInfo xVisualInfo = (XVisualInfo)Marshal.PtrToStructure(visualIntPtr, typeof(XVisualInfo));

                    IntPtr xRenderingContext = IntPtr.Zero;


                    if (sharedContextWidget != null)
                    {
                        GLWidget primaryWidget = sharedContextWidget;
                        while (primaryWidget.sharedContextWidget != null) primaryWidget = primaryWidget.sharedContextWidget;

                        if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero)
                        {
                            xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, primaryWidget.RenderingContextHandle, true);
                        }
                        else
                        {
                            xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true);
                            this.sharedContextWidget = null;
                            primaryWidget.sharedContextWidget = this;
                        }
                    }
                    else
                    {
                        xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true);
                    }

                    if (xRenderingContext == IntPtr.Zero)
                    {
                        throw new Exception("Unable to create rendering context");
                    }

                    renderingContextHandle = new HandleRef(this, xRenderingContext);

                    visual = (Gdk.Visual)GLib.Object.GetObject(gdk_x11_screen_lookup_visual(Screen.Handle, xVisualInfo.visualid));

                    if (visualIntPtr != IntPtr.Zero)
                    {
                        XFree(visualIntPtr);
                    }
                    break;
            }
        }
        public VisualizationDisplayWidget()
        {
            visualizationMenu = new Menu();
            noVisualizationsMenuItem = new MenuItem(
                AddinManager.CurrentLocalizer.GetString ("No visualizations installed"));
            noVisualizationsMenuItem.Sensitive = false;
            noVisualizationsMenuItem.Show();
            visualizationMenu.Add(noVisualizationsMenuItem);

            glWidget = new GLWidget();
            glWidget.DoubleBuffered = true;
            glWidget.Render += OnRender;
            glWidget.SizeAllocated += OnGlSizeAllocated;
            glWidget.Show();

            Add(glWidget);
            Show();

            playerData = new BansheePlayerData(ServiceManager.PlayerEngine.ActiveEngine);
            playerData.Active = false;

            glWidget.Realized += delegate {
                if (!loopRunning) {
                    loopRunning = true;
                    renderThread = new Thread(RenderLoop);
                    renderThread.Start();
                }

                ConnectVisualization();
            };

            glWidget.Unrealized += delegate {
                DisposeRenderer();
            };

            AddinManager.AddExtensionNodeHandler("/Banshee/OpenVP/Visualization", OnVisualizationChanged);

            InterfaceActionService ias = ServiceManager.Get<InterfaceActionService>();

            ias.GlobalActions.AddImportant(new ActionEntry(SELECT_VIS_ACTION,
                                                           null,
                                                           AddinManager.CurrentLocalizer.GetString ("Select visualization"),
                                                           null, null,
                                                           OnSelectVisualizationClicked));

            ias.GlobalActions.AddImportant(new ToggleActionEntry(LOW_RES_ACTION,
                                                                 null,
                                                                 AddinManager.CurrentLocalizer.GetString ("Low resolution"),
                                                                 null, null,
                                                                 OnHalfResolutionToggled, false));

            ias.GlobalActions.UpdateAction(SELECT_VIS_ACTION, false);
            ias.GlobalActions.UpdateAction(LOW_RES_ACTION, false);

            global_ui_id = ias.UIManager.AddUiFromResource("ActiveSourceUI.xml");
        }
예제 #12
0
        void HandleRealized(object sender, EventArgs eventArgs)
        {
            if (renderingContextHandle.Handle != IntPtr.Zero)
            {
                return;
            }

            switch (platformID)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
                LoadLibrary("opengl32.dll");

                IntPtr windowHandle  = gdk_win32_drawable_get_handle(GdkWindow.Handle);
                IntPtr deviceContext = GetDC(windowHandle);

                PIXELFORMATDESCRIPTOR pixelFormatDescriptor = new PIXELFORMATDESCRIPTOR();
                pixelFormatDescriptor.nSize      = (short)System.Runtime.InteropServices.Marshal.SizeOf(pixelFormatDescriptor);
                pixelFormatDescriptor.nVersion   = 1;
                pixelFormatDescriptor.iPixelType = PFD_TYPE_RGBA;
                pixelFormatDescriptor.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
                if (doubleBuffer)
                {
                    pixelFormatDescriptor.dwFlags |= PFD_DOUBLEBUFFER;
                }
                pixelFormatDescriptor.cColorBits   = colorBits;
                pixelFormatDescriptor.cAlphaBits   = alphaBits;
                pixelFormatDescriptor.cDepthBits   = depthBits;
                pixelFormatDescriptor.cStencilBits = stencilBits;

                int pixelFormat = ChoosePixelFormat(deviceContext, ref pixelFormatDescriptor);
                if (!SetPixelFormat(deviceContext, pixelFormat, ref pixelFormatDescriptor))
                {
                    throw new Exception("Cannot SetPixelFormat!");
                }

                IntPtr renderingContext = wglCreateContext(deviceContext);
                renderingContextHandle = new HandleRef(this, renderingContext);

                ReleaseDC(windowHandle, deviceContext);

                if (sharedContextWidget != null)
                {
                    GLWidget primaryWidget = sharedContextWidget;
                    while (primaryWidget.sharedContextWidget != null)
                    {
                        primaryWidget = primaryWidget.sharedContextWidget;
                    }

                    if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero)
                    {
                        wglShareLists(primaryWidget.RenderingContextHandle.Handle, RenderingContextHandle.Handle);
                    }
                    else
                    {
                        this.sharedContextWidget          = null;
                        primaryWidget.sharedContextWidget = this;
                    }
                }

                break;

            case PlatformID.Unix:
            default:
                int[] attributeList  = new int[24];
                int   attributeIndex = 0;

                attributeList[attributeIndex++] = GLX_RGBA;
                if (doubleBuffer)
                {
                    attributeList[attributeIndex++] = GLX_DOUBLEBUFFER;
                }

                attributeList[attributeIndex++] = GLX_RED_SIZE;
                attributeList[attributeIndex++] = 1;

                attributeList[attributeIndex++] = GLX_GREEN_SIZE;
                attributeList[attributeIndex++] = 1;

                attributeList[attributeIndex++] = GLX_BLUE_SIZE;
                attributeList[attributeIndex++] = 1;

                if (alphaBits != 0)
                {
                    attributeList[attributeIndex++] = GLX_ALPHA_SIZE;
                    attributeList[attributeIndex++] = 1;
                }

                if (depthBits != 0)
                {
                    attributeList[attributeIndex++] = GLX_DEPTH_SIZE;
                    attributeList[attributeIndex++] = 1;
                }

                if (stencilBits != 0)
                {
                    attributeList[attributeIndex++] = GLX_STENCIL_SIZE;
                    attributeList[attributeIndex++] = 1;
                }

                attributeList[attributeIndex++] = GLX_NONE;

                IntPtr xDisplay     = gdk_x11_display_get_xdisplay(Screen.Display.Handle);
                IntPtr visualIntPtr = IntPtr.Zero;

                try
                {
                    visualIntPtr = glXChooseVisual(xDisplay, Screen.Number, attributeList);
                }
                catch (DllNotFoundException e)
                {
                    throw new Exception("OpenGL dll not found!", e);
                }
                catch (EntryPointNotFoundException enf)
                {
                    throw new Exception("Glx entry point not found!", enf);
                }

                if (visualIntPtr == IntPtr.Zero)
                {
                    throw new Exception("Visual");
                }

                XVisualInfo xVisualInfo = (XVisualInfo)Marshal.PtrToStructure(visualIntPtr, typeof(XVisualInfo));

                IntPtr xRenderingContext = IntPtr.Zero;


                if (sharedContextWidget != null)
                {
                    GLWidget primaryWidget = sharedContextWidget;
                    while (primaryWidget.sharedContextWidget != null)
                    {
                        primaryWidget = primaryWidget.sharedContextWidget;
                    }

                    if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero)
                    {
                        xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, primaryWidget.RenderingContextHandle, true);
                    }
                    else
                    {
                        xRenderingContext                 = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true);
                        this.sharedContextWidget          = null;
                        primaryWidget.sharedContextWidget = this;
                    }
                }
                else
                {
                    xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true);
                }

                if (xRenderingContext == IntPtr.Zero)
                {
                    throw new Exception("Unable to create rendering context");
                }

                renderingContextHandle = new HandleRef(this, xRenderingContext);

                visual = (Gdk.Visual)GLib.Object.GetObject(gdk_x11_screen_lookup_visual(Screen.Handle, xVisualInfo.visualid));

                if (visualIntPtr != IntPtr.Zero)
                {
                    XFree(visualIntPtr);
                }
                break;
            }
        }