/// <summary>Constructs a new GameWindow with the specified attributes.</summary>
 /// <param name="width">The width of the GameWindow in pixels.</param>
 /// <param name="height">The height of the GameWindow in pixels.</param>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
 /// <param name="title">The title of the GameWindow.</param>
 /// <param name="options">GameWindow options regarding window appearance and behavior.</param>
 /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
 public GameWindow(int width, int height, GraphicsMode mode, string title, bool nullContext,
     GameWindowFlags options, DisplayDevice device)
     : base(width, height, title, options, mode, device)
 {
     try {
         glContext = nullContext ? new NullContext() :
             Factory.Default.CreateGLContext(mode, WindowInfo);
         glContext.MakeCurrent(WindowInfo);
         glContext.LoadAll();
         VSync = true;
     } catch (Exception e) {
         Debug.Print(e.ToString());
         base.Dispose();
         throw;
     }
 }
Example #2
0
 public CarbonGLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     CreateNativeWindow(WindowClass.Document,
         WindowAttributes.StandardDocument | WindowAttributes.StandardHandler |
         WindowAttributes.InWindowMenu | WindowAttributes.LiveResize,
         new Rect((short)x, (short)y, (short)width, (short)height));
 }
Example #3
0
        static public void Initialize(Size resolution, int msaasamples, string mediapath, GameWindowFlags flags = GameWindowFlags.Default)
        {
            StartTime = DateTime.Now;
            MSAASamples = msaasamples;
            World = new World();
            Media.SearchPath = mediapath;
            Media.LoadFileMap();
            ShadowMaps = new ShadowMapsArrayTexture(512, 512);
            Resolution = resolution;
            SetCurrentThreadCores(1);

            ShaderPool = new ShaderPool();

            var thread = Task.Factory.StartNew(() =>
            {
                SetCurrentThreadCores(2);
                DisplayAdapter = new VEngineWindowAdapter("VEngine App", resolution.Width, resolution.Height, flags);

                GraphicsSettings.UseDeferred = true;
                GraphicsSettings.UseRSM = false;
                GraphicsSettings.UseVDAO = true;
                GraphicsSettings.UseFog = false;
                GraphicsSettings.UseBloom = false;
                GraphicsSettings.UseLightPoints = true;

                DisplayAdapter.CursorVisible = false;

                Invoke(() => Initialized = true);
                DisplayAdapter.Run();
            });
            while(!Initialized)
                ;
        }
Example #4
0
        public Sdl2NativeWindow(int x, int y, int width, int height,
            string title, GameWindowFlags options, DisplayDevice device)
        {
            lock (sync)
            {
                var bounds = device.Bounds;
                var flags = TranslateFlags(options);
                flags |= WindowFlags.OPENGL;
                flags |= WindowFlags.RESIZABLE;
                flags |= WindowFlags.HIDDEN;
                flags |= WindowFlags.ALLOW_HIGHDPI;

                if ((flags & WindowFlags.FULLSCREEN_DESKTOP) != 0 ||
                    (flags & WindowFlags.FULLSCREEN) != 0)
                    window_state = WindowState.Fullscreen;

                IntPtr handle;
                lock (SDL.Sync)
                {
                    EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
                    handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
                    SDL.AddEventWatch(EventFilterDelegate, handle);
                    SDL.PumpEvents();
                }
                window = new Sdl2WindowInfo(handle, null);
                window_id = SDL.GetWindowID(handle);
                windows.Add(window_id, this);
                window_title = title;

                exists = true;
            }
        }
Example #5
0
 public Main(GraphicsMode mode, string title, GameWindowFlags flags)
     : base((int)Constants.Graphics.ScreenResolution.X, (int)Constants.Graphics.ScreenResolution.Y, mode, title, flags)
 {
     Engines = new List<Engine>();
     Constants.SetupEngines(this);
     Constants.Engines.Input.SetMouseShow(false);
 }
Example #6
0
        public SDL2GLNative(int x, int y, int width, int height, string title,
            GraphicsMode mode,GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");


            Debug.Indent();

			IntPtr windowId;
			desiredSizeX = width;
			desiredSizeY = height;
			isFullscreen = options.HasFlag(GameWindowFlags.Fullscreen);
			if (isFullscreen)
			{
				FixupFullscreenRes(width,height,out width, out height);
			}
			lock (API.sdl_api_lock) {
				API.Init (API.INIT_VIDEO);
				API.VideoInit("",0);
				// NOTE: Seriously, letting the user set x and y coords is a _bad_ idea. We'll let the WM take care of it.
				windowId = API.CreateWindow(title, 0x1FFF0000, 0x1FFF0000, width, height, API.WindowFlags.OpenGL | ((isFullscreen)?API.WindowFlags.Fullscreen:0));
			}
			window = new SDL2WindowInfo(windowId);

			inputDriver = new SDL2Input(window);
            Debug.Unindent();

        }
        public Sdl2NativeWindow(int x, int y, int width, int height,
            string title, GameWindowFlags options, DisplayDevice device)
        {
            lock (sync)
            {
                var bounds = device.Bounds;
                var flags = TranslateFlags(options);
                flags |= WindowFlags.OPENGL;
                flags |= WindowFlags.HIDDEN;
                if (Toolkit.Options.EnableHighResolution)
                {
                    flags |= WindowFlags.ALLOW_HIGHDPI;
                }

                if ((flags & WindowFlags.FULLSCREEN_DESKTOP) != 0 ||
                    (flags & WindowFlags.FULLSCREEN) != 0)
                    window_state = WindowState.Fullscreen;

                if ((flags & WindowFlags.RESIZABLE) == 0)
                    window_border = WindowBorder.Fixed;

                IntPtr handle;
                lock (SDL.Sync)
                {
                    handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
                    exists = true;
                }
                ProcessEvents();
                window = new Sdl2WindowInfo(handle, null);
                window_id = SDL.GetWindowID(handle);
                windows.Add(window_id, this);
            }
        }
        public LinuxNativeWindow(IntPtr display, IntPtr gbm, int fd,
            int x, int y, int width, int height, string title,
            GraphicsMode mode, GameWindowFlags options,
            DisplayDevice display_device)
        {
            Debug.Print("[KMS] Creating window on display {0:x}", display);

            Title = title;

            display_device = display_device ?? DisplayDevice.Default;
            if (display_device == null)
            {
                throw new NotSupportedException("[KMS] Driver does not currently support headless systems");
            }

            window = new LinuxWindowInfo(display, fd, gbm, display_device.Id as LinuxDisplay);

            // Note: we only support fullscreen windows on KMS.
            // We implicitly override the requested width and height
            // by the width and height of the DisplayDevice, if any.
            width = display_device.Width;
            height = display_device.Height;
            bounds = new Rectangle(0, 0, width, height);
            client_size = bounds.Size;

            if (!mode.Index.HasValue)
            {
                mode = new EglGraphicsMode().SelectGraphicsMode(window, mode, 0);
            }
            Debug.Print("[KMS] Selected EGL mode {0}", mode);

            SurfaceFormat format = GetSurfaceFormat(display, mode);
            SurfaceFlags usage = SurfaceFlags.Rendering | SurfaceFlags.Scanout;
            if (!Gbm.IsFormatSupported(gbm, format, usage))
            {
                Debug.Print("[KMS] Failed to find suitable surface format, using XRGB8888");
                format = SurfaceFormat.XRGB8888;
            }

            Debug.Print("[KMS] Creating GBM surface on {0:x} with {1}x{2} {3} [{4}]",
                gbm, width, height, format, usage);
            IntPtr gbm_surface =  Gbm.CreateSurface(gbm,
                    width, height, format, usage);
            if (gbm_surface == IntPtr.Zero)
            {
                throw new NotSupportedException("[KMS] Failed to create GBM surface for rendering");
            }

            window.Handle = gbm_surface;
                Debug.Print("[KMS] Created GBM surface {0:x}", window.Handle);

            window.CreateWindowSurface(mode.Index.Value);
            Debug.Print("[KMS] Created EGL surface {0:x}", window.Surface);

            cursor_default = CreateCursor(gbm, Cursors.Default);
            cursor_empty = CreateCursor(gbm, Cursors.Empty);
            Cursor = MouseCursor.Default;
            exists = true;
        }
Example #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="name"></param>
 /// <param name="fullscreen"></param>
 public GLWindow(int width, int height, string name, GameWindowFlags fullscreen)
     : base(width, height, GraphicsMode.Default, name, fullscreen, DisplayDevice.Default, 3, 3, GraphicsContextFlags.ForwardCompatible)
 {
     Renderables = new List<IRenderable>();
     ClearColor = new Color4();
     OnLoadFunction = null;
     OnUpdateFunction = null;
     KeyEvents = new Dictionary<Key, Action>();
     MouseEvents = new Dictionary<MouseInformation, Action>();
 }
Example #10
0
 //Deliberately specify the default constructor with various overrides
 public RouteViewer(int width, int height, GraphicsMode currentGraphicsMode, string openbve, GameWindowFlags @default): base (width,height,currentGraphicsMode,openbve,@default)
 {
     try
     {
         System.Drawing.Icon ico = new System.Drawing.Icon("data\\icon.ico");
         this.Icon = ico;
     }
     catch
     {
     }
 }
Example #11
0
        public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device)
        {
            WindowProcedureDelegate = WindowProcedure;
            // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be
            // bound to the top-level window, but rather to a child window docked in the parent.
            window = new WinWindowInfo(
                CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null);
            child_window = new WinWindowInfo(
                CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window);

            exists = true;
        }
Example #12
0
		//We need to explicitly specify the default constructor
		public OpenBVEGame(int width, int height, GraphicsMode currentGraphicsMode, GameWindowFlags @default): base(width, height, currentGraphicsMode, Interface.GetInterfaceString("program_title"), @default)
		{
			try
			{
				var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				System.Drawing.Icon ico = new System.Drawing.Icon(OpenBveApi.Path.CombineFile(OpenBveApi.Path.CombineDirectory(assemblyFolder, "Data"), "icon.ico"));
				this.Icon = ico;
			}
			catch
			{
			}
		}
Example #13
0
        public DefaultWindow(DefaultDevice device, int width, int height, ref SwapChainDescription implicitSwapChainDescription, 
            string title, GameWindowFlags gameWindowFlags, DisplayDevice displayDevice, ref Context glContext)
            : base(width, height, GraphicsMode.Default, title, gameWindowFlags, displayDevice)
        {
            glContext = glContext ?? new Context(Context);
            this.glContext = glContext;

            this.device = device;
            implicitSwapChainDesc = implicitSwapChainDescription;
            swapChainSurfaces = new SwapChainSurfaces(device, width, height, ref implicitSwapChainDescription);

            keyboard = new Keyboard(this);
            mouse = new Mouse(this);
        }
        public DesktopViewController(Type rootClass, int windowWidth, int windowHeight, string windowTitle, 
                                     GameWindowFlags windowFlags, DisplayDevice device, GraphicsContextFlags flags) 
            : base(windowWidth, windowHeight, GraphicsMode.Default, windowTitle, windowFlags, device, -1, -1, flags)
        {
            Console.WriteLine("Sparrow-sharp: Starting");
            _rootClass = rootClass;

            Load += HandleLoad;

            RenderFrame += HandleRenderFrame;

            Mouse.Move += OnMouseMove;
            Mouse.ButtonDown += OnMouseButtonChange;
            Mouse.ButtonUp += OnMouseButtonChange;

            // Run the game at 60 updates per second
            Run(60.0);
        }
Example #15
0
 public Program(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device,
                   int major, int minor, GraphicsContextFlags flags, IGraphicsContext sharedContext)
     : base(width, height, title, options,
            mode == null ? GraphicsMode.Default : mode,
            device == null ? DisplayDevice.Default : device)
 {
     try
     {
         glContext = new GraphicsContext(mode == null ? GraphicsMode.Default : mode, WindowInfo, major, minor, flags);
         glContext.MakeCurrent(WindowInfo);
         (glContext as IGraphicsContextInternal).LoadAll();
     }
     catch (Exception e)
     {
         Debug.Print(e.ToString());
         base.Dispose();
         throw;
     }
 }
Example #16
0
        public Sdl2NativeWindow(int x, int y, int width, int height,
            string title, GameWindowFlags options, DisplayDevice device)
        {
            lock (sync)
            {
                var bounds = device.Bounds;
                var flags = TranslateFlags(options);
                flags |= SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;
                flags |= SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
                flags |= SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN;

                if ((flags & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP) != 0 ||
                    (flags & SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN) != 0)
                    window_state = WindowState.Fullscreen;

                IntPtr handle;
                lock (SDL.Sync)
                {
                    handle = SDL.SDL_CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
                    SDL.SDL_AddEventWatch(EventFilterDelegate, handle);
                    SDL.SDL_PumpEvents();
                }
                window = new Sdl2WindowInfo(handle, null);
                window_id = SDL.SDL_GetWindowID(handle);
                windows.Add(window_id, this);
                window_title = title;

                keyboard.Description = "Standard keyboard";
                keyboard.NumberOfFunctionKeys = 12;
                keyboard.NumberOfKeys = 101;
                keyboard.NumberOfLeds = 3;

                mouse.Description = "Standard mouse";
                mouse.NumberOfButtons = 3;
                mouse.NumberOfWheels = 1;

                keyboards.Add(keyboard);
                mice.Add(mouse);

                exists = true;
            }
        }
Example #17
0
 /// <summary>Constructs a new NativeWindow with the specified attributes.</summary>
 /// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param>
 /// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param>
 /// <param name="width">The width of the NativeWindow in pixels.</param>
 /// <param name="height">The height of the NativeWindow in pixels.</param>
 /// <param name="title">The title of the NativeWindow.</param>
 /// <param name="options">GameWindow options specifying window appearance and behavior.</param>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
 /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
 /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
 /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
 public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, OpenTK.Graphics.GraphicsMode mode, DisplayDevice device)
 {
     // TODO: Should a constraint be added for the position?
     if (width < 1)
         throw new ArgumentOutOfRangeException("width", "Must be greater than zero.");
     if (height < 1)
         throw new ArgumentOutOfRangeException("height", "Must be greater than zero.");
     if (mode == null)
         throw new ArgumentNullException("mode");
     if (device == null)
         throw new ArgumentNullException("device");
     this.options = options;
     this.device = device;
     implementation = (INativeWindow2)Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, this.device);
     if ((options & GameWindowFlags.Fullscreen) != 0)
     {
         this.device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0);
         WindowState = WindowState.Fullscreen;
     }
 }
Example #18
0
        public AbsDisplayAdapter(string title, int width, int height, GameWindowFlags flags)
            : base(width, height,
                new OpenTK.Graphics.GraphicsMode(new ColorFormat(8, 8, 8, 8), 8, 0, 1), title, flags,
                DisplayDevice.Default, 4, 5,
                GraphicsContextFlags.ForwardCompatible | GraphicsContextFlags.Debug)
        {
            Game.DisplayAdapter = this;
            Game.Resolution = new Size(Width, Height);
            GL.Enable(EnableCap.DepthClamp);
            GL.Enable(EnableCap.DebugOutput);
            GL.Enable(EnableCap.DebugOutputSynchronous);
            GL.Enable(EnableCap.Dither);
            GL.Enable(EnableCap.Multisample);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.ClearColor(0, 0, 0, 0);
            GL.ClearDepth(1);

            GL.PatchParameter(PatchParameterInt.PatchVertices, 3);

            GL.Disable(EnableCap.Blend);
            GL.DebugMessageCallback((source, type, id, severity, length, message, userParam) =>
            {
                Console.WriteLine("{0} {1} {2} {3} {4} {5} {6}", source, type, id, severity, length, message, userParam);
            }, (IntPtr)0);

            MouseMove += Mouse_Move;
            KeyPress += VEngineWindowAdapter_KeyPress;
            KeyDown += VEngineWindowAdapter_KeyDown;
            KeyUp += VEngineWindowAdapter_KeyUp;
            MouseDown += VEngineWindowAdapter_MouseDown;
            MouseUp += VEngineWindowAdapter_MouseUp;
            MouseWheel += VEngineWindowAdapter_MouseWheel;
            Load += VEngineWindowAdapter_Load;
            Task.Factory.StartNew(() => PhysicsThread());
        }
Example #19
0
        IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
        {
            // Use win32 to create the native window.
            // Keep in mind that some construction code runs in the WM_CREATE message handler.

            // The style of a parent window is different than that of a child window.
            // Note: the child window should always be visible, even if the parent isn't.
            WindowStyle         style    = 0;
            ExtendedWindowStyle ex_style = 0;

            if (parentHandle == IntPtr.Zero)
            {
                style   |= WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
                ex_style = ParentStyleEx;
            }
            else
            {
                style   |= WindowStyle.Visible | WindowStyle.Child | WindowStyle.ClipSiblings;
                ex_style = ChildStyleEx;
            }

            // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
            Win32Rectangle rect = new Win32Rectangle();

            rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
            Functions.AdjustWindowRectEx(ref rect, style, false, ex_style);

            // Create the window class that we will use for this window.
            // The current approach is to register a new class for each top-level WinGLWindow we create.
            if (!class_registered)
            {
                ExtendedWindowClass wc = new ExtendedWindowClass();
                wc.Size      = ExtendedWindowClass.SizeInBytes;
                wc.Style     = DefaultClassStyle;
                wc.Instance  = Instance;
                wc.WndProc   = WindowProcedureDelegate;
                wc.ClassName = ClassName;
                wc.Icon      = Icon != null ? Icon.Handle : IntPtr.Zero;
#warning "This seems to resize one of the 'large' icons, rather than using a small icon directly (multi-icon files). Investigate!"
                wc.IconSm = Icon != null ? new Icon(Icon, 16, 16).Handle : IntPtr.Zero;
                wc.Cursor = Functions.LoadCursor(CursorName.Arrow);
                ushort atom = Functions.RegisterClassEx(ref wc);

                if (atom == 0)
                {
                    throw new PlatformException(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error()));
                }

                class_registered = true;
            }

            IntPtr window_name = Marshal.StringToHGlobalAuto(title);
            IntPtr handle      = Functions.CreateWindowEx(
                ex_style, ClassName, window_name, style,
                rect.left, rect.top, rect.Width, rect.Height,
                parentHandle, IntPtr.Zero, Instance, IntPtr.Zero);

            if (handle == IntPtr.Zero)
            {
                throw new PlatformException(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error()));
            }

            return(handle);
        }
Example #20
0
 /// <summary>Constructs a new GameWindow with the specified attributes.</summary>
 /// <param name="width">The width of the GameWindow in pixels.</param>
 /// <param name="height">The height of the GameWindow in pixels.</param>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
 /// <param name="title">The title of the GameWindow.</param>
 /// <param name="options">GameWindow options regarding window appearance and behavior.</param>
 /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
 public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device)
     : this(width, height, mode, title, options, device, 1, 0, GraphicsContextFlags.Default)
 {
 }
Example #21
0
 /// <summary>Constructs a new GameWindow with the specified attributes.</summary>
 /// <param name="width">The width of the GameWindow in pixels.</param>
 /// <param name="height">The height of the GameWindow in pixels.</param>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
 /// <param name="title">The title of the GameWindow.</param>
 /// <param name="options">GameWindow options regarding window appearance and behavior.</param>
 /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
 /// <param name="major">The major version for the OpenGL GraphicsContext.</param>
 /// <param name="minor">The minor version for the OpenGL GraphicsContext.</param>
 /// <param name="flags">The GraphicsContextFlags version for the OpenGL GraphicsContext.</param>
 public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device,
                   int major, int minor, GraphicsContextFlags flags)
     : this(width, height, mode, title, options, device, major, minor, flags, null)
 {
 }
Example #22
0
        /// <summary>Constructs a new GameWindow with the specified attributes.</summary>
        /// <param name="width">The width of the GameWindow in pixels.</param>
        /// <param name="height">The height of the GameWindow in pixels.</param>
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
        /// <param name="title">The title of the GameWindow.</param>
        /// <param name="options">GameWindow options regarding window appearance and behavior.</param>
        /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
        /// <param name="major">The major version for the OpenGL GraphicsContext.</param>
        /// <param name="minor">The minor version for the OpenGL GraphicsContext.</param>
        /// <param name="flags">The GraphicsContextFlags version for the OpenGL GraphicsContext.</param>
        /// <param name="sharedContext">An IGraphicsContext to share resources with.</param>
        public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device,
                          int major, int minor, GraphicsContextFlags flags, IGraphicsContext sharedContext)
            : base(width, height, title, options,
                   mode == null ? GraphicsMode.Default : mode,
                   device == null ? DisplayDevice.Default : device)
        {
            try
            {
                glContext = new GraphicsContext(mode == null ? GraphicsMode.Default : mode, WindowInfo, major, minor, flags);
                glContext.MakeCurrent(WindowInfo);
                (glContext as IGraphicsContextInternal).LoadAll();

                VSync = VSyncMode.On;

                //glWindow.WindowInfoChanged += delegate(object sender, EventArgs e) { OnWindowInfoChangedInternal(e); };
            }
            catch (Exception e)
            {
                Debug.Print(e.ToString());
                base.Dispose();
                throw;
            }
        }
Example #23
0
 public DualityDebuggingTester(int w, int h, GraphicsMode mode, string title, GameWindowFlags flags) : base(w, h, mode, title, flags)
 {
 }
Example #24
0
 public OpenTkRenderer(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, GraphicsContextFlags flags)
     : base(width, height, mode, title, options, device, major, minor, flags)
 {
 }
 public Window(int width, int height, GraphicsMode mode, string title, GameWindowFlags options) : base(width, height, mode, title, options)
 {
     IsMasterDisplay = true;
     ContextID       = 1;
 }
Example #26
0
 public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title,
                                         GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     return(default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device));
 }
Example #27
0
 public abstract INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device);
 public CustomGameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, GraphicsContextFlags flags, IGraphicsContext sharedContext)
     : base(width, height, mode, title, options, device, major, minor, flags, sharedContext)
 {
 }
Example #29
0
 public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     throw new PlatformNotSupportedException(error_string);
 }
 public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     return(new X11GLNative(x, y, width, height, title, mode, options, device));
 }
 public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode,
                                                  GameWindowFlags options, DisplayDevice device)
 {
     return(_platform_factory.CreateNativeWindow(x, y, width, height, title,
                                                 mode, options, device));
 }
Example #32
0
        public ChildFormWindow(string name, string caption, int width, int height, SummerGUIWindow parent, bool modal = false, GameWindowFlags flags = GameWindowFlags.Default, WindowPositions position = WindowPositions.CenterParent)
            : base(caption, width, height, parent, flags)
        {
            if (String.IsNullOrEmpty(name))
            {
                name = "ChildWindow";
            }

            Name    = name;
            IsModal = modal;

            if (!IsModal)
            {
                ShowInTaskBar = true;
                AllowMinimize = flags == GameWindowFlags.Default;
                AllowMaximize = flags == GameWindowFlags.Default;
            }
            else
            {
                // ToDo: FixMe:
                this.HideFromTaskbar();
            }

            // ToDo: Set Window Modal State on Platform

            /**	ToDo:
             * m_pDisplay->Create( NULL,  //CWnd default
             *      NULL,   //has no name
             *      WS_CHILD|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBLE,
             *      rect,
             *      this,   //this is the parent
             *      0);     //this should really be a different
             * //  number... check resource.h
             *
             * return TRUE;  // return TRUE  unless you set
             * //    the focus to a control
             **/
        }
Example #33
0
 public InternalWindow(NativeWindow parent, int w, int h, GraphicsMode mode, string title,
                       GameWindowFlags flags, GraphicsContextFlags contextFlags)
     : base(w, h, mode, title, flags, DisplayDevice.Default, 2, 0, contextFlags)
 {
     this.parent = parent;
 }
Example #34
0
        public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device)
        {
            lock (SyncRoot)
            {
                // This is the main window procedure callback. We need the callback in order to create the window, so
                // don't move it below the CreateWindow calls.
                WindowProcedureDelegate = WindowProcedure;

                //// This timer callback is called periodically when the window enters a sizing / moving modal loop.
                //ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time)
                //{
                //    // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events.
                //    if (Move != null)
                //        Move(this, EventArgs.Empty);
                //};

                int scale_width = width;
                int scale_height = height;
                int scale_x = x;
                int scale_y = y;
                if (Toolkit.Options.EnableHighResolution)
                {
                    // CreateWindow takes values in pixels.
                    // According to the high-dpi guidelines,
                    // we need to scale these values by the
                    // current DPI.
                    // Search MSDN for "How to Ensure That
                    // Your Application Displays Properly on
                    // High-DPI Displays"
                    scale_width = ScaleX(width);
                    scale_height = ScaleY(height);
                    scale_x = ScaleX(x);
                    scale_y = ScaleY(y);
                }

                // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be
                // bound to the top-level window, but rather to a child window docked in the parent.
                window = new WinWindowInfo(
                    CreateWindow(
                        scale_x, scale_y, scale_width, scale_height,
                        title, options, device, IntPtr.Zero),
                    null);
                child_window = new WinWindowInfo(
                    CreateWindow(
                        0, 0, ClientSize.Width, ClientSize.Height,
                        title, options, device, window.Handle),
                    window);

                exists = true;

                keyboard.Description = "Standard Windows keyboard";
                keyboard.NumberOfFunctionKeys = 12;
                keyboard.NumberOfKeys = 101;
                keyboard.NumberOfLeds = 3;

                mouse.Description = "Standard Windows mouse";
                mouse.NumberOfButtons = 3;
                mouse.NumberOfWheels = 1;

                keyboards.Add(keyboard);
                mice.Add(mouse);
            }
        }
Example #35
0
        // TODO: Remaining constructors.

        /// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
        /// <param name="width">The width of the NativeWindow in pixels.</param>
        /// <param name="height">The height of the NativeWindow in pixels.</param>
        /// <param name="title">The title of the NativeWindow.</param>
        /// <param name="options">GameWindow options specifying window appearance and behavior.</param>
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
        /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
        /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
        public NativeWindow(int width, int height, string title, GameWindowFlags options, GraphicsMode mode, DisplayDevice device)
            : this(device.Bounds.Left + (device.Bounds.Width - width) / 2,
                   device.Bounds.Top + (device.Bounds.Height - height) / 2,
                   width, height, title, options, mode, device)
        {
        }
Example #36
0
 /// <summary>Constructs a new GameWindow with the specified attributes.</summary>
 /// <param name="width">The width of the GameWindow in pixels.</param>
 /// <param name="height">The height of the GameWindow in pixels.</param>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
 /// <param name="title">The title of the GameWindow.</param>
 /// <param name="options">GameWindow options regarding window appearance and behavior.</param>
 /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
 public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device)
     : this(width, height, mode, title, options, device, 1, 0, GraphicsContextFlags.Default)
 { }
 public CustomGameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device)
     : base(width, height, mode, title, options, device)
 {
 }
Example #38
0
        public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
            }
            XVisualInfo template = new XVisualInfo();

            using (new XLock(this.window.Display))
            {
                if (!mode.Index.HasValue)
                {
                    throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
                }
                template.VisualID = mode.Index.Value;
                int nitems;
                this.window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(Functions.XGetVisualInfo(this.window.Display, XVisualInfoMask.ID, ref template, out nitems), typeof(XVisualInfo));
                XSetWindowAttributes attributes = new XSetWindowAttributes();
                attributes.background_pixel = IntPtr.Zero;
                attributes.border_pixel     = IntPtr.Zero;
                attributes.colormap         = Functions.XCreateColormap(this.window.Display, this.window.RootWindow, this.window.VisualInfo.Visual, 0);
                this.window.EventMask       = EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PointerMotionMask | EventMask.KeymapStateMask | EventMask.ExposureMask | EventMask.StructureNotifyMask | EventMask.FocusChangeMask | EventMask.PropertyChangeMask;
                attributes.event_mask       = (IntPtr)((long)this.window.EventMask);
                uint num = 10250U;
                this.window.WindowHandle = Functions.XCreateWindow(this.window.Display, this.window.RootWindow, x, y, width, height, 0, this.window.VisualInfo.Depth, 1, this.window.VisualInfo.Visual, (UIntPtr)num, ref attributes);
                if (this.window.WindowHandle == IntPtr.Zero)
                {
                    throw new ApplicationException("XCreateWindow call failed (returned 0).");
                }
                if (title != null)
                {
                    Functions.XStoreName(this.window.Display, this.window.WindowHandle, title);
                }
            }
            this.SetWindowMinMax((short)30, (short)30, (short)-1, (short)-1);
            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)12L;
            using (new XLock(this.window.Display))
            {
                Functions.XSetWMNormalHints(this.window.Display, this.window.WindowHandle, ref hints);
                Functions.XSetWMProtocols(this.window.Display, this.window.WindowHandle, new IntPtr[1]
                {
                    this._atom_wm_destroy
                }, 1);
            }
            this.RefreshWindowBounds(ref new XEvent()
            {
                ConfigureEvent =
                {
                    x      = x,
                    y      = y,
                    width  = width,
                    height = height
                }
            });
            this.driver      = new X11Input((IWindowInfo)this.window);
            this.mouse       = this.driver.Mouse[0];
            this.EmptyCursor = X11GLNative.CreateEmptyCursor(this.window);
            this.exists      = true;
        }
Example #39
0
 public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     throw new PlatformNotSupportedException(error_string);
 }
Example #40
0
 public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice display_device)
 {
     return(new LinuxNativeWindow(egl_display, gbm_device, gpu_fd, x, y, width, height, title, mode, options, display_device));
 }
Example #41
0
 public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     throw new NotImplementedException();
 }
Example #42
0
        public X11GLNative(int x, int y, int width, int height, string title,
                           GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
            }

            Debug.Print("Creating X11GLNative window.");
            // Open a display connection to the X server, and obtain the screen and root window.
            window.Display    = API.DefaultDisplay;
            window.Screen     = API.XDefaultScreen(window.Display);             //API.DefaultScreen;
            window.RootWindow = API.XRootWindow(window.Display, window.Screen); // API.RootWindow;

            Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow);
            RegisterAtoms(window);
            XVisualInfo info = new XVisualInfo();

            mode = X11GLContext.SelectGraphicsMode(mode, out info);
            window.VisualInfo = info;
            // Create a window on this display using the visual above
            Debug.Print("Opening render window... ");

            XSetWindowAttributes attributes = new XSetWindowAttributes();

            attributes.background_pixel = IntPtr.Zero;
            attributes.border_pixel     = IntPtr.Zero;
            attributes.colormap         = API.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0 /*AllocNone*/);
            window.EventMask            = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                                          EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                                          EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                          EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                                          EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                                          EventMask.PropertyChangeMask;
            attributes.event_mask = (IntPtr)window.EventMask;

            uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                        (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

            window.WindowHandle = API.XCreateWindow(window.Display, window.RootWindow,
                                                    x, y, width, height, 0, window.VisualInfo.Depth /*(int)CreateWindowArgs.CopyFromParent*/,
                                                    (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (IntPtr)mask, ref attributes);

            if (window.WindowHandle == IntPtr.Zero)
            {
                throw new ApplicationException("XCreateWindow call failed (returned 0).");
            }

            if (title != null)
            {
                API.XStoreName(window.Display, window.WindowHandle, title);
            }

            // Set the window hints
            SetWindowMinMax(_min_width, _min_height, -1, -1);

            XSizeHints hints = new XSizeHints();

            hints.base_width  = width;
            hints.base_height = height;
            hints.flags       = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            API.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints);
            // Register for window destroy notification
            API.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { wm_destroy }, 1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();

            e.ConfigureEvent.x      = x;
            e.ConfigureEvent.y      = y;
            e.ConfigureEvent.width  = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            Debug.Print("X11GLNative window created successfully (id: {0}).", Handle);
            SetupInput();
            exists = true;
        }
Example #43
0
 //Deliberately specify the default constructor with various overrides
 public RouteViewer(int width, int height, GraphicsMode currentGraphicsMode, string openbve, GameWindowFlags @default) : base(width, height, currentGraphicsMode, openbve, @default)
 {
     try
     {
         System.Drawing.Icon ico = new System.Drawing.Icon("data\\icon.ico");
         this.Icon = ico;
     }
     catch
     {
         // Ignored- Just an icon
     }
 }
Example #44
0
 public CarbonGLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     this.CreateNativeWindow(WindowClass.Document, WindowAttributes.StandardDocument | WindowAttributes.StandardHandler | WindowAttributes.InWindowMenu | WindowAttributes.LiveResize, new Rect((short)x, (short)y, (short)width, (short)height));
     this.mDisplayDevice = device;
 }
 /// <summary>Constructs a new GameWindow with the specified attributes.</summary>
 /// <param name="width">The width of the GameWindow in pixels.</param>
 /// <param name="height">The height of the GameWindow in pixels.</param>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
 /// <param name="title">The title of the GameWindow.</param>
 /// <param name="options">GameWindow options regarding window appearance and behavior.</param>
 public MyGameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options)
     : this(width, height, mode, title, options, DisplayDevice.Default) { }
Example #46
0
        public NativeWindow(GraphicsMode mode, WindowOptions options)
        {
            if ((options.ScreenMode & (ScreenMode.ChangeResolution | ScreenMode.FullWindow)) != 0)
            {
                if (DisplayDevice.Default != null)
                {
                    options.Size = new Point2(
                        DisplayDevice.Default.Width,
                        DisplayDevice.Default.Height);
                }
            }

            screenMode = options.ScreenMode & (ScreenMode.FullWindow | ScreenMode.FixedSize | ScreenMode.ChangeResolution);

            GameWindowFlags windowFlags = GameWindowFlags.Default;

            if ((screenMode & ScreenMode.FixedSize) != 0)
            {
                windowFlags = GameWindowFlags.FixedWindow;
            }
            else if ((screenMode & ScreenMode.ChangeResolution) != 0)
            {
                windowFlags = GameWindowFlags.Fullscreen;
            }

            VSyncMode vsyncMode;

            switch (options.RefreshMode)
            {
            default:
            case RefreshMode.NoSync:
            case RefreshMode.ManualSync:
                vsyncMode = VSyncMode.Off;
                break;

            case RefreshMode.VSync:
                vsyncMode = VSyncMode.On;
                break;

            case RefreshMode.AdaptiveVSync:
                vsyncMode = VSyncMode.Adaptive;
                break;
            }

            this.refreshMode    = options.RefreshMode;
            this.internalWindow = new InternalWindow(
                this,
                options.Size.X,
                options.Size.Y,
                mode,
                options.Title,
                windowFlags);
            this.internalWindow.MakeCurrent();
            this.internalWindow.CursorVisible = true;
            if (!options.SystemCursorVisible)
            {
                this.internalWindow.Cursor = MouseCursor.Empty;
            }
            this.internalWindow.VSync = vsyncMode;

            Console.WriteLine(
                "Window Specification: " + Environment.NewLine +
                "  Buffers: {0}" + Environment.NewLine +
                "  Samples: {1}" + Environment.NewLine +
                "  ColorFormat: {2}" + Environment.NewLine +
                "  AccumFormat: {3}" + Environment.NewLine +
                "  Depth: {4}" + Environment.NewLine +
                "  Stencil: {5}" + Environment.NewLine +
                "  VSync: {6}" + Environment.NewLine +
                "  SwapInterval: {7}",
                this.internalWindow.Context.GraphicsMode.Buffers,
                this.internalWindow.Context.GraphicsMode.Samples,
                this.internalWindow.Context.GraphicsMode.ColorFormat,
                this.internalWindow.Context.GraphicsMode.AccumulatorFormat,
                this.internalWindow.Context.GraphicsMode.Depth,
                this.internalWindow.Context.GraphicsMode.Stencil,
                this.internalWindow.VSync,
                this.internalWindow.Context.SwapInterval);

            // Retrieve icon from executable file and set it as window icon
            string executablePath = null;

            try {
                Assembly entryAssembly = Assembly.GetEntryAssembly();
                if (entryAssembly != null)
                {
                    executablePath = Path.GetFullPath(entryAssembly.Location);
                    if (File.Exists(executablePath))
                    {
                        this.internalWindow.Icon = Icon.ExtractAssociatedIcon(executablePath);
                    }
                }
            }
            // As described in issue 301 (https://github.com/AdamsLair/duality/issues/301), the
            // icon extraction can fail with an exception under certain circumstances. Don't fail
            // just because of an icon. Log the error and continue.
            catch (Exception e) {
                Console.WriteLine(
                    "There was an exception while trying to extract the " +
                    "window icon from the game's main executable '{0}'. This is " +
                    "uncritical, but still an error: {1}",
                    executablePath,
                    e);
            }

            if ((screenMode & ScreenMode.FullWindow) != 0)
            {
                this.internalWindow.WindowState = WindowState.Fullscreen;
            }

            DualityApp.WindowSize = new Point2(this.internalWindow.ClientSize.Width,
                                               this.internalWindow.ClientSize.Height);

            // Register events and input
            this.HookIntoDuality();

            // Determine OpenGL capabilities and log them
            GraphicsBackend.LogOpenGLSpecs();
        }
Example #47
0
        #pragma warning restore 414

        #endregion

        #region Constructors

        public X11GLNative(int x, int y, int width, int height, string title,
            GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");

            Debug.Indent();

            using (new XLock(window.Display))
            {
                IntPtr visual;
                IntPtr fbconfig;
                window.GraphicsMode = new X11GraphicsMode()
                    .SelectGraphicsMode(mode, out visual, out fbconfig);

                window.Visual = visual;
                window.FBConfig = fbconfig;

                // Create a window on this display using the visual above
                Debug.Write("Opening render window... ");

                XSetWindowAttributes attributes = new XSetWindowAttributes();
                attributes.background_pixel = IntPtr.Zero;
                attributes.border_pixel = IntPtr.Zero;
                attributes.colormap = Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/);
                window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                                   EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                                   EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                   EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                                   EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                                   EventMask.PropertyChangeMask;
                attributes.event_mask = (IntPtr)window.EventMask;

                SetWindowValuemask mask =
                    SetWindowValuemask.ColorMap | SetWindowValuemask.EventMask |
                    SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel;

                window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
                    x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/,
                    CreateWindowArgs.InputOutput, window.VisualInfo.Visual, mask, attributes);

                if (window.Handle == IntPtr.Zero)
                    throw new ApplicationException("XCreateWindow call failed (returned 0).");

                if (title != null)
                    Functions.XStoreName(window.Display, window.Handle, title);
            }

            XSizeHints hints = new XSizeHints();
            hints.base_width = width;
            hints.base_height = height;
            hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);

            XClassHint class_hint = new XClassHint();
            class_hint.Name = Assembly.GetEntryAssembly().GetName().Name.ToLower();
            class_hint.Class = Assembly.GetEntryAssembly().GetName().Name;

            using (new XLock(window.Display))
            {
                Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);

                // Register for window destroy notification
                Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { _atom_wm_destroy }, 1);

                // Set the window class hints
                Functions.XSetClassHint(window.Display, window.Handle, ref class_hint);
            }

            SetWindowMinMax(_min_width, _min_height, -1, -1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();
            e.ConfigureEvent.x = x;
            e.ConfigureEvent.y = y;
            e.ConfigureEvent.width = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            EmptyCursor = CreateEmptyCursor(window);

            Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle));
            Debug.Unindent();

            using (new XLock(window.Display))
            {
                // Request that auto-repeat is only set on devices that support it physically.
                // This typically means that it's turned off for keyboards (which is what we want).
                // We prefer this method over XAutoRepeatOff/On, because the latter needs to
                // be reset before the program exits.
                if (Xkb.IsSupported(window.Display))
                {
                    bool supported;
                    Xkb.SetDetectableAutoRepeat(window.Display, true, out supported);
                }
            }

            // The XInput2 extension makes keyboard and mouse handling much easier.
            // Check whether it is available.
            xi2_supported = XI2MouseKeyboard.IsSupported(window.Display);
            if (xi2_supported)
            {
                xi2_opcode = XI2MouseKeyboard.XIOpCode;
                xi2_version = XI2MouseKeyboard.XIVersion;
            }

            exists = true;
        }
Example #48
0
 public InternalWindow(NativeWindow parent, int w, int h, GraphicsMode mode, string title,
                       GameWindowFlags flags)
     : base(w, h, mode, title, flags)
 {
     this.parent = parent;
 }
Example #49
0
 public INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title,
     GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     return default_implementation.CreateNativeWindow(x, y, width, height, title, mode, options, device);
 }
Example #50
0
 public InternalWindow(NativeWindow parent, int w, int h, GraphicsMode mode, string title, GameWindowFlags flags)
     : base(w, h, mode, title, flags,
            DisplayDevice.Default,
            GraphicsBackend.MinOpenGLVersion.Major,
            GraphicsBackend.MinOpenGLVersion.Minor,
            GraphicsContextFlags.ForwardCompatible)
 {
     this.parent = parent;
 }
Example #51
0
        // TODO: Remaining constructors.

        /// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary>
        /// <param name="width">The width of the NativeWindow in pixels.</param>
        /// <param name="height">The height of the NativeWindow in pixels.</param>
        /// <param name="title">The title of the NativeWindow.</param>
        /// <param name="options">GameWindow options specifying window appearance and behavior.</param>
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param>
        /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception>
        /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception>
        public NativeWindow(int width, int height, string title, GameWindowFlags options, OpenTK.Graphics.GraphicsMode mode, DisplayDevice device)
            : this(device.Bounds.Left + (device.Bounds.Width - width) / 2,
                   device.Bounds.Top + (device.Bounds.Height - height) / 2,
                   width, height, title, options, mode, device)
        { }
Example #52
0
        public NativeWindow(GraphicsMode mode, WindowOptions options)
        {
            if (options.ScreenMode == ScreenMode.Fullscreen || options.ScreenMode == ScreenMode.FullWindow)
            {
                if (DisplayDevice.Default != null)
                {
                    options.Size = new Point2(
                        DisplayDevice.Default.Width,
                        DisplayDevice.Default.Height);
                }
            }

            GameWindowFlags windowFlags = GameWindowFlags.Default;

            if (options.ScreenMode == ScreenMode.FixedWindow)
            {
                windowFlags = GameWindowFlags.FixedWindow;
            }
            else if (options.ScreenMode == ScreenMode.Fullscreen)
            {
                windowFlags = GameWindowFlags.Fullscreen;
            }

            VSyncMode vsyncMode;

            switch (options.RefreshMode)
            {
            default:
            case RefreshMode.NoSync:
            case RefreshMode.ManualSync:
                vsyncMode = VSyncMode.Off;
                break;

            case RefreshMode.VSync:
                vsyncMode = VSyncMode.On;
                break;

            case RefreshMode.AdaptiveVSync:
                vsyncMode = VSyncMode.Adaptive;
                break;
            }

            this.refreshMode    = options.RefreshMode;
            this.internalWindow = new InternalWindow(
                this,
                options.Size.X,
                options.Size.Y,
                mode,
                options.Title,
                windowFlags);
            this.internalWindow.MakeCurrent();
            this.internalWindow.CursorVisible = true;
            if (!options.SystemCursorVisible)
            {
                this.internalWindow.Cursor = MouseCursor.Empty;
            }
            this.internalWindow.VSync = vsyncMode;

            // Log some general info on the graphics context we've set up
            GraphicsBackend.LogOpenGLContextSpecs(this.internalWindow.Context);

            // Retrieve icon from executable file and set it as window icon
            string executablePath = null;

            try
            {
                Assembly entryAssembly = Assembly.GetEntryAssembly();
                if (entryAssembly != null)
                {
                    executablePath = Path.GetFullPath(entryAssembly.Location);
                    if (File.Exists(executablePath))
                    {
                        this.internalWindow.Icon = Icon.ExtractAssociatedIcon(executablePath);
                    }
                }
            }
            // As described in issue 301 (https://github.com/AdamsLair/duality/issues/301), the
            // icon extraction can fail with an exception under certain circumstances. Don't fail
            // just because of an icon. Log the error and continue.
            catch (Exception e)
            {
                Logs.Core.WriteWarning(
                    "There was an exception while trying to extract the " +
                    "window icon from the game's main executable '{0}'. This is " +
                    "uncritical, but still means something went wrong: {1}",
                    executablePath,
                    LogFormat.Exception(e));
            }

            if (options.ScreenMode == ScreenMode.FullWindow)
            {
                this.internalWindow.WindowState = WindowState.Fullscreen;
            }

            DualityApp.WindowSize = new Point2(this.internalWindow.ClientSize.Width, this.internalWindow.ClientSize.Height);

            // Register events and input
            this.HookIntoDuality();

            // Let's see what rendering features we have available
            GraphicsBackend.ActiveInstance.QueryOpenGLCapabilities();
        }
Example #53
0
        public WinGLNative(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device)
        {
            lock (SyncRoot)
            {
                // This is the main window procedure callback. We need the callback in order to create the window, so
                // don't move it below the CreateWindow calls.
                WindowProcedureDelegate = WindowProcedure;

                //// This timer callback is called periodically when the window enters a sizing / moving modal loop.
                //ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time)
                //{
                //    // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events.
                //    if (Move != null)
                //        Move(this, EventArgs.Empty);
                //};

                // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be
                // bound to the top-level window, but rather to a child window docked in the parent.
                window = new WinWindowInfo(
                    CreateWindow(x, y, width, height, title, options, device, IntPtr.Zero), null);
                child_window = new WinWindowInfo(
                    CreateWindow(0, 0, ClientSize.Width, ClientSize.Height, title, options, device, window.WindowHandle), window);

                exists = true;

                keyboard.Description = "Standard Windows keyboard";
                keyboard.NumberOfFunctionKeys = 12;
                keyboard.NumberOfKeys = 101;
                keyboard.NumberOfLeds = 3;

                mouse.Description = "Standard Windows mouse";
                mouse.NumberOfButtons = 3;
                mouse.NumberOfWheels = 1;

                keyboards.Add(keyboard);
                mice.Add(mouse);
            }
        }
        public LinuxNativeWindow(IntPtr display, IntPtr gbm, int fd,
                                 int x, int y, int width, int height, string title,
                                 GraphicsMode mode, GameWindowFlags options,
                                 DisplayDevice display_device)
        {
            Debug.Print("[KMS] Creating window on display {0:x}", display);

            Title = title;

            display_device = display_device ?? DisplayDevice.Default;
            if (display_device == null)
            {
                throw new NotSupportedException("[KMS] Driver does not currently support headless systems");
            }

            window = new LinuxWindowInfo(display, fd, gbm, display_device.Id as LinuxDisplay);

            // Note: we only support fullscreen windows on KMS.
            // We implicitly override the requested width and height
            // by the width and height of the DisplayDevice, if any.
            width       = display_device.Width;
            height      = display_device.Height;
            bounds      = new Rectangle(0, 0, width, height);
            client_size = bounds.Size;

            if (!mode.Index.HasValue)
            {
                mode = new EglGraphicsMode().SelectGraphicsMode(window, mode, 0);
            }
            Debug.Print("[KMS] Selected EGL mode {0}", mode);

            SurfaceFormat format = GetSurfaceFormat(display, mode);
            SurfaceFlags  usage  = SurfaceFlags.Rendering | SurfaceFlags.Scanout;

            if (!Gbm.IsFormatSupported(gbm, format, usage))
            {
                Debug.Print("[KMS] Failed to find suitable surface format, using XRGB8888");
                format = SurfaceFormat.XRGB8888;
            }

            Debug.Print("[KMS] Creating GBM surface on {0:x} with {1}x{2} {3} [{4}]",
                        gbm, width, height, format, usage);
            IntPtr gbm_surface = Gbm.CreateSurface(gbm,
                                                   width, height, format, usage);

            if (gbm_surface == IntPtr.Zero)
            {
                throw new NotSupportedException("[KMS] Failed to create GBM surface for rendering");
            }

            window.Handle = gbm_surface;
            Debug.Print("[KMS] Created GBM surface {0:x}", window.Handle);

            window.CreateWindowSurface(mode.Index.Value);
            Debug.Print("[KMS] Created EGL surface {0:x}", window.Surface);

            cursor_default = CreateCursor(gbm, Cursors.Default);
            cursor_empty   = CreateCursor(gbm, Cursors.Empty);
            Cursor         = MouseCursor.Default;
            exists         = true;
        }
Example #55
0
        IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
        {
            // Use win32 to create the native window.
            // Keep in mind that some construction code runs in the WM_CREATE message handler.

            // The style of a parent window is different than that of a child window.
            // Note: the child window should always be visible, even if the parent isn't.
            WindowStyle style = 0;
            ExtendedWindowStyle ex_style = 0;
            if (parentHandle == IntPtr.Zero)
            {
                style |= WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
                ex_style = ParentStyleEx;
            }
            else
            {
                style |= WindowStyle.Visible | WindowStyle.Child | WindowStyle.ClipSiblings;
                ex_style = ChildStyleEx;
            }

            // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
            Win32Rectangle rect = new Win32Rectangle();
            rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
            Functions.AdjustWindowRectEx(ref rect, style, false, ex_style);

            // Create the window class that we will use for this window.
            // The current approach is to register a new class for each top-level WinGLWindow we create.
            if (!class_registered)
            {
                ExtendedWindowClass wc = new ExtendedWindowClass();
                wc.Size = ExtendedWindowClass.SizeInBytes;
                wc.Style = DefaultClassStyle;
                wc.Instance = Instance;
                wc.WndProc = WindowProcedureDelegate;
                wc.ClassName = ClassName;
                wc.Icon = Icon != null ? Icon.Handle : IntPtr.Zero;
#warning "This seems to resize one of the 'large' icons, rather than using a small icon directly (multi-icon files). Investigate!"
                wc.IconSm = Icon != null ? new Icon(Icon, 16, 16).Handle : IntPtr.Zero;
                wc.Cursor = Functions.LoadCursor(CursorName.Arrow);
                ushort atom = Functions.RegisterClassEx(ref wc);

                if (atom == 0)
                    throw new PlatformException(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error()));

                class_registered = true;
            }

            IntPtr window_name = Marshal.StringToHGlobalAuto(title);
            IntPtr handle = Functions.CreateWindowEx(
                ex_style, ClassName, window_name, style,
                rect.left, rect.top, rect.Width, rect.Height,
                parentHandle, IntPtr.Zero, Instance, IntPtr.Zero);

            if (handle == IntPtr.Zero)
                throw new PlatformException(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error()));

            return handle;
        }
Example #56
0
        static public void Initialize(Size resolution, int msaasamples, string mediapath, GameWindowFlags flags = GameWindowFlags.Default)
        {
            StartTime        = DateTime.Now;
            MSAASamples      = msaasamples;
            World            = new World();
            Media.SearchPath = mediapath;
            Media.LoadFileMap();
            //CascadeShadowMaps = new CascadeShadows(Vector3.One, new float[] { 10, 25, 50, 500, 1000, 10000 }, 10000);
            //CascadeShadowMaps = new CascadeShadows(Vector3.One, new float[] { }, 10000);
            Resolution = resolution;
            SetCurrentThreadCores(1);

            ShaderPool = new ShaderPool();

            var thread = Task.Factory.StartNew(() =>
            {
                SetCurrentThreadCores(2);
                DisplayAdapter = new VEngineWindowAdapter("VEngine App", resolution.Width, resolution.Height, flags);

                DisplayAdapter.MainRenderer.GraphicsSettings.UseDeferred  = false;
                DisplayAdapter.MainRenderer.GraphicsSettings.UseRSM       = false;
                DisplayAdapter.MainRenderer.GraphicsSettings.UseVDAO      = false;
                DisplayAdapter.MainRenderer.GraphicsSettings.UseFog       = false;
                DisplayAdapter.MainRenderer.GraphicsSettings.UseBloom     = false;
                DisplayAdapter.MainRenderer.GraphicsSettings.UseCubeMapGI = false;

                DisplayAdapter.CursorVisible = false;

                Invoke(() => Initialized = true);
                DisplayAdapter.Run();
            });

            while (!Initialized)
            {
                ;
            }
        }
Example #57
0
 /// <summary>Constructs a new GameWindow with the specified attributes.</summary>
 /// <param name="width">The width of the GameWindow in pixels.</param>
 /// <param name="height">The height of the GameWindow in pixels.</param>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GameWindow.</param>
 /// <param name="title">The title of the GameWindow.</param>
 /// <param name="options">GameWindow options regarding window appearance and behavior.</param>
 /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the GameWindow in.</param>
 /// <param name="major">The major version for the OpenGL GraphicsContext.</param>
 /// <param name="minor">The minor version for the OpenGL GraphicsContext.</param>
 /// <param name="flags">The GraphicsContextFlags version for the OpenGL GraphicsContext.</param>
 public GameWindow(int width, int height, GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device,
     int major, int minor, GraphicsContextFlags flags)
     : this(width, height, mode, title, options, device, major, minor, flags, null)
 { }
Example #58
0
 public DualityLauncher(int w, int h, GraphicsMode mode, string title, GameWindowFlags flags)
     : base(w, h, mode, title, flags)
 {
 }
Example #59
0
 public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     return new X11GLNative(x, y, width, height, title, mode, options, device);
 }
Example #60
0
 private RobustPopup(int W, int H, string Title, GameWindowFlags GWF, DisplayDevice DD) : base(W, H, Title, GWF, GraphicsMode.Default, DD)
 {
 }