コード例 #1
0
 // TODO: App should only be closed when the final window is closed.
 // TODO: What if a window never opens??? Need a safety measure to auto-close.
 // TODO: Fix vsync stuttering.
 public IAppWindow NewWindow(IWindowArgs args)
 => this.parent_.Instantiator.Wrap(
     this.parent_.root_,
     new WindowOpenTk(
         this.discardableImpl_,
         args,
         this.parent_.input_,
         this.parent_.ScheduleCloseApp_));
コード例 #2
0
                public WindowOpenTk(
                    IDiscardableNode parentDiscardable,
                    IWindowArgs args,
                    InputOpenTk input,
                    Action onClose)
                {
                    this.discardableImpl_            = parentDiscardable.CreateChild();
                    this.discardableImpl_.OnDiscard += _ => this.Discard_();

                    var initialWidth  = args.Dimensions.Width;
                    var initialHeight = args.Dimensions.Height;

                    this.nativeWindow_ = new NativeWindow(initialWidth,
                                                          initialHeight,
                                                          "SimpleGame",
                                                          GameWindowFlags.Default,
                                                          GraphicsMode.Default,
                                                          DisplayDevice.Default);

                    this.AttachToNativeInputEvents_(input);

                    this.nativeWindow_.Closed += (_, _2) => onClose();

                    var windowInfo = this.nativeWindow_.WindowInfo;

                    this.glContext_ = new GraphicsContext(GraphicsMode.Default,
                                                          windowInfo,
                                                          1,
                                                          0,
                                                          GraphicsContextFlags.Default);
                    this.glContext_.MakeCurrent(windowInfo);
                    ((IGraphicsContextInternal)this.glContext_).LoadAll();

                    //this.glContext_.SwapInterval = 0;

                    this.windowBoundingBox_ =
                        new MutableBoundingBox <int>(0, 0, initialWidth, initialHeight);
                    var windowTopLeft    = this.windowBoundingBox_.TopLeft;
                    var windowDimensions = this.windowBoundingBox_.Dimensions;

                    this.nativeWindow_.Move += (_, _2) =>
                                               (windowTopLeft.X,
                                                windowTopLeft.Y) =
                        (this.nativeWindow_.X, this.nativeWindow_.Y);
                    this.nativeWindow_.Resize += (_, _2) =>
                                                 (windowDimensions.Width, windowDimensions.Height) =
                        (this.nativeWindow_.Width, this.nativeWindow_.Height);

                    this.viewport_.Push(new AggregationBoundingBox <int>(
                                            new ImmutableVector2 <int>(0, 0),
                                            this.windowBoundingBox_.Dimensions));
                }