Exemplo n.º 1
0
 public GraphicsMode SelectGraphicsMode(ColorFormat color, int depth, int stencil, int samples, ColorFormat accum, int buffers, bool stereo)
 {
     GraphicsMode gfx = new GraphicsMode((IntPtr)1, color, depth, stencil, samples,
                                          accum, buffers, stereo);
     System.Diagnostics.Debug.Print("Created dummy graphics mode.");
     return gfx;
 }
Exemplo n.º 2
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
        {
            Debug.Print("Context Type: {0}", shareContext);
            Debug.Print("Window info: {0}", window);

            this.graphics_mode = mode;
            this.carbonWindow = (CarbonWindowInfo)window;

            if (shareContext is AglContext)
                shareContextRef = ((AglContext)shareContext).Handle.Handle;
			if (shareContext is GraphicsContext)
			{
				ContextHandle shareHandle = shareContext != null ?
					(shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

				shareContextRef = shareHandle.Handle;
			}

			if (shareContextRef == IntPtr.Zero)
			{
				Debug.Print("No context sharing will take place.");
			}

            CreateContext(mode, carbonWindow, shareContextRef, true);
        }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext,
            GetInt xoffset, GetInt yoffset)
        {
            Debug.Print("Share context: {0}", shareContext);
            Debug.Print("Window info: {0}", window);
            IntPtr shareContextRef = IntPtr.Zero;

            XOffset = xoffset;
            YOffset = yoffset;

            carbonWindow = window;

            if (shareContext is AglContext)
            {
                shareContextRef = ((AglContext)shareContext).Handle.Handle;
            }
            else if (shareContext is GraphicsContext)
            {
                ContextHandle shareHandle = shareContext != null ? (shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;
                shareContextRef = shareHandle.Handle;
            }

            if (shareContextRef == IntPtr.Zero)
            {
                Debug.Print("No context sharing will take place.");
            }

            CreateContext(mode, carbonWindow, shareContextRef, true);
        }
Exemplo n.º 5
0
        public AglContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext)
        {
            Debug.Print("Context Type: {0}", shareContext);
            Debug.Print("Window info: {0}", window);

            this.graphics_mode = mode;
            this.carbonWindow = (CarbonWindowInfo)window;

            if (shareContext is AglContext)
                shareContextRef = ((AglContext)shareContext).Handle.Handle;

            CreateContext(mode, carbonWindow, shareContextRef, true);
        }
        public static Bitmap imageLoader(GBAROM ROM, int imageOffset, int paletteOffset, int width, int height, bool isImageCompressed, bool isPaletteCompressed, bool transparent, GraphicsMode mode)
        {
            DataBuffer rawGraphics = new DataBuffer(0x8000);
            DataBuffer rawPalette = new DataBuffer(0x100);
            if (isImageCompressed)
            {
                rawGraphics.ReadCompressedData(ROM, imageOffset);
            }
            else
            {
                int gfxlength = GBAGraphics.RawGraphicsLength(new Size(width * 8, height * 8), mode);
                rawGraphics.ReadData(ROM, imageOffset, gfxlength);
            }

            if (isPaletteCompressed)
            {
                rawPalette.ReadCompressedData(ROM, paletteOffset);
            }
            else
            {
                rawPalette.ReadData(ROM, paletteOffset, 0x200);
            }

            byte[] graphics = rawGraphics.ToArray();
            int bitsPerPixel = GBAGraphics.BitsPerPixel(mode);

            int length = Math.Min(bitsPerPixel * width * height / 8, graphics.Length);
            Color[] palette;

            if (rawPalette.Length > 0 && paletteOffset != 0)
                palette = GBAPalette.ToPalette(rawPalette.ToArray(), 0, rawPalette.Length / 2);
            else
            {
                palette = new Color[16];
                for (int i = 0; i < palette.Length; i++)
                    palette[i] = Color.FromArgb(i * (256 / palette.Length), i * (256 / palette.Length), i * (256 / palette.Length));
            }

            int empty;
            if(transparent)
                palette[0] = Color.FromArgb(0, palette[0]);
            return GBAGraphics.ToBitmap(graphics, length, 0, palette, width, mode, out empty);
        }
Exemplo n.º 7
0
 public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
 {
     throw new PlatformNotSupportedException(error_string);
 }
Exemplo n.º 8
0
        internal static void Main(string[] args)
        {
            CurrentHost = new Host();
            // file system
            FileSystem = FileSystem.FromCommandLineArgs(args, CurrentHost);
            FileSystem.CreateFileSystem();
            Renderer     = new NewRenderer();
            CurrentRoute = new CurrentRoute(CurrentHost, Renderer);
            Sounds       = new Sounds();
            Options.LoadOptions();
            TrainManager = new TrainManager(CurrentHost, Renderer, Interface.CurrentOptions, FileSystem);
            Plugins.LoadPlugins();

            // command line arguments
            StringBuilder objectsToLoad = new StringBuilder();

            if (args.Length != 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] != null)
                    {
                        if (System.IO.File.Exists(args[i]))
                        {
                            for (int j = 0; j < CurrentHost.Plugins.Length; j++)
                            {
                                if (CurrentHost.Plugins[j].Object != null && CurrentHost.Plugins[j].Object.CanLoadObject(args[i]))
                                {
                                    objectsToLoad.Append(args[i] + " ");
                                    continue;
                                }

                                if (CurrentHost.Plugins[j].Route != null && CurrentHost.Plugins[j].Route.CanLoadRoute(args[i]))
                                {
                                    if (string.IsNullOrEmpty(CurrentRouteFile))
                                    {
                                        CurrentRouteFile       = args[i];
                                        processCommandLineArgs = true;
                                    }
                                }
                            }
                        }
                        else if (args[i].ToLowerInvariant() == "/enablehacks")
                        {
                            //Deliberately undocumented option for debugging use
                            Interface.CurrentOptions.EnableBveTsHacks = true;
                            for (int j = 0; j < CurrentHost.Plugins.Length; j++)
                            {
                                if (CurrentHost.Plugins[j].Object != null)
                                {
                                    CompatabilityHacks enabledHacks = new CompatabilityHacks
                                    {
                                        BveTsHacks        = true,
                                        CylinderHack      = false,
                                        BlackTransparency = true
                                    };
                                    CurrentHost.Plugins[j].Object.SetCompatibilityHacks(enabledHacks);
                                }
                            }
                        }
                    }
                }
            }

            if (objectsToLoad.Length != 0)
            {
                string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe");
                if (System.IO.File.Exists(File))
                {
                    System.Diagnostics.Process.Start(File, objectsToLoad.ToString());
                    if (string.IsNullOrEmpty(CurrentRouteFile))
                    {
                        //We only supplied objects, so launch Object Viewer instead
                        Environment.Exit(0);
                    }
                }
            }

            var options = new ToolkitOptions();

            Plugins.LoadPlugins();
            options.Backend = PlatformBackend.PreferX11;
            Toolkit.Init(options);
            string folder = Program.FileSystem.GetDataFolder("Languages");

            Translations.LoadLanguageFiles(folder);
            Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000;
            Interface.CurrentOptions.ObjectOptimizationFullThreshold  = 250;
            // application
            currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel);
            if (Renderer.Screen.Width == 0 || Renderer.Screen.Height == 0)
            {
                //Duff values saved, so reset to something sensible else we crash
                Renderer.Screen.Width  = 1024;
                Renderer.Screen.Height = 768;
            }
            Renderer.CameraTrackFollower            = new TrackFollower(Program.CurrentHost);
            currentGameWindow                       = new RouteViewer(Renderer.Screen.Width, Renderer.Screen.Height, currentGraphicsMode, "Route Viewer", GameWindowFlags.Default);
            currentGameWindow.Visible               = true;
            currentGameWindow.TargetUpdateFrequency = 0;
            currentGameWindow.TargetRenderFrequency = 0;
            currentGameWindow.Title                 = "Route Viewer";
            processCommandLineArgs                  = true;
            currentGameWindow.Run();
            //Unload
            Sounds.Deinitialize();
        }
Exemplo n.º 9
0
        /// <summary>Draw slider and background dc</summary>
        private void DrawTrack()
        {
            BitBlt(_cControlDc.Hdc, 0, 0, _cTrackDc.Width, _cTrackDc.Height, _cTrackDc.Hdc, 0, 0, 0xCC0020);
            if (TrackStyle == TrackType.Progress)
            {
                Rectangle trackRect = GetTrackRectangle();
                Rectangle buttonRect = GetButtonRectangle();
                int length;

                trackRect.Inflate(-1, -1);
                if (Orientation == Orientation.Horizontal)
                {
                    if (_iValue == _iMinimum)
                    {
                        length = 0;
                    }
                    else if (_iValue == _iMaximum)
                    {
                        if (SmoothScrolling)
                        {
                            length = buttonRect.Right - (trackRect.Left + 1);
                            trackRect.Width = length;
                        }
                        else
                        {
                            length = buttonRect.Right - (trackRect.Left + 2);
                            trackRect.Width = length;
                        }
                    }
                    else
                    {
                        length = buttonRect.Right - (trackRect.Left + (int)(buttonRect.Width * .5f));
                        trackRect.Width = length;
                    }
                }
                else
                {
                    if (_iValue == _iMinimum)
                    {
                        length = 0;
                    }
                    else if (_iValue == _iMaximum)
                    {
                        if (SmoothScrolling)
                        {
                            length = trackRect.Bottom - (buttonRect.Top + 1);
                            trackRect.Y = buttonRect.Top - 1;
                            trackRect.Height = length;
                        }
                        else
                        {
                            length = trackRect.Bottom - (buttonRect.Top + 3);
                            trackRect.Height = length;
                        }
                    }
                    else
                    {
                        length = trackRect.Bottom - (buttonRect.Top + (int)(buttonRect.Height * .5f));
                        trackRect.Y = buttonRect.Top + (int)(buttonRect.Height * .5f) - 2;
                        trackRect.Height = length;
                    }
                }
                if (length > 1)
                {
                    using (Graphics g = Graphics.FromHdc(_cControlDc.Hdc))
                    {
                        using (GraphicsMode mode = new GraphicsMode(g, SmoothingMode.HighQuality))
                        {
                            using (GraphicsPath gp = CreateRoundRectanglePath(g, trackRect, 2))
                            {
                                using (LinearGradientBrush fillBrush = new LinearGradientBrush(
                                    buttonRect,
                                    Color.FromArgb(120, Color.White),
                                    Color.FromArgb(250, TrackProgressColor),
                                    (Orientation == Orientation.Horizontal) ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal))
                                {
                                    Blend blnd = new Blend();
                                    blnd.Positions = new[] { 0f, .5f, 1f };
                                    blnd.Factors = new[] { .5f, .7f, .3f };
                                    fillBrush.Blend = blnd;
                                    g.FillPath(fillBrush, gp);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window)
 {
     //return new WinDXContext( mode, (WinWindowInfo)window );
     return new WinGLContext(mode, (WinWindowInfo)window);
 }
 public static byte[] ToGBARaw(Bitmap image, Color[] palette, GraphicsMode mode)
 {
     byte[] result = null;
     switch (mode)
     {
         case GraphicsMode.Tile8bit:
             result = ToTile8bit(image, palette);
             break;
         case GraphicsMode.Tile4bit:
             result = ToTile4bit(image, palette);
             break;
         case GraphicsMode.BitmapTrueColour:
             result = ToBitmapTrueColour(image);
             break;
         case GraphicsMode.Bitmap8bit:
             result = ToBitmapIndexed(image, palette);
             break;
     }
     return result;
 }
Exemplo n.º 13
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            Debug.Print("AGL pixel format attributes:");
            
            AGLPixelFormat myAGLPixelFormat;
            
            // Choose a pixel format with the attributes we specified.
            IntPtr gdevice;
            IntPtr cgdevice = GetQuartzDevice(carbonWindow);
                
            if (cgdevice == IntPtr.Zero)
                cgdevice = (IntPtr)DisplayDevice.Default.Id;
                
            OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);
                
            if (status != OSStatus.NoError)
                throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");

            IGraphicsMode selector = new MacOSGraphicsMode(gdevice);
            Mode = selector.SelectGraphicsMode(
                mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
            MyAGLReportError("aglChoosePixelFormat");

            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);
            myAGLPixelFormat = Mode.Index.Value;

            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");
            
            Debug.Print("IsControl: {0}", carbonWindow.IsControl);
            
            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);
            
            MakeCurrent(carbonWindow);
            Debug.Print("context: {0}", Handle.Handle);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Constructs a new GraphicsContext with the specified GraphicsMode and attaches it to the specified window.
 /// </summary>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GraphicsContext.</param>
 /// <param name="window">The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to.</param>
 public GraphicsContext(GraphicsMode mode, IWindowInfo window)
     : this(mode, window, 1, 0, GraphicsContextFlags.Default)
 {
 }
Exemplo n.º 15
0
        /// <summary>
        /// Constructs a new GraphicsContext with the specified GraphicsMode, version and flags,  and attaches it to the specified window.
        /// </summary>
        /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the GraphicsContext.</param>
        /// <param name="window">The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to.</param>
        /// <param name="major">The major version of the new GraphicsContext.</param>
        /// <param name="minor">The minor version of the new GraphicsContext.</param>
        /// <param name="flags">The GraphicsContextFlags for the GraphicsContext.</param>
        /// <remarks>
        /// Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored.
        /// </remarks>
        public GraphicsContext(GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags)
        {
            lock (SyncRoot)
            {
                bool designMode = false;
                if (mode == null && window == null)
                {
                    designMode = true;
                }
                else if (mode == null)
                {
                    throw new ArgumentNullException("mode", "Must be a valid GraphicsMode.");
                }
                else if (window == null)
                {
                    throw new ArgumentNullException("window", "Must point to a valid window.");
                }

                // Silently ignore invalid major and minor versions.
                if (major <= 0)
                {
                    major = 1;
                }
                if (minor < 0)
                {
                    minor = 0;
                }

                // Debug.Print("Creating GraphicsContext.");
                try
                {
                    // Debug.Indent();
                    // Debug.Print("GraphicsMode: {0}", mode);
                    // Debug.Print("IWindowInfo: {0}", window);
                    // Debug.Print("GraphicsContextFlags: {0}", flags);
                    // Debug.Print("Requested version: {0}.{1}", major, minor);

                    IGraphicsContext shareContext = FindSharedContext();

                    // Todo: Add a DummyFactory implementing IPlatformFactory.
                    if (designMode)
                    {
                        implementation    = Factory.Embedded.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags);
                        GetCurrentContext = Factory.Embedded.CreateGetCurrentGraphicsContext();
                    }
                    else
                    {
                        Factory factory = null;
                        GetCurrentContext = null;
                        switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded)
                        {
                        case false: factory = Factory.Default; break;

                        case true: factory = Factory.Embedded; break;
                        }

                        // Note: this approach does not allow us to mix native and EGL contexts in the same process.
                        // This should not be a problem, as this use-case is not interesting for regular applications.
                        // Note 2: some platforms may not support a direct way of getting the current context
                        // (this happens e.g. with DummyGLContext). In that case, we use a slow fallback which
                        // iterates through all known contexts and checks if any is current (check GetCurrentContext
                        // declaration).
                        if (GetCurrentContext == null)
                        {
                            GetCurrentContext = factory.CreateGetCurrentGraphicsContext();
                        }

                        implementation = factory.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags);
                    }

                    available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this));
                }
                finally
                {
                    // Debug.Unindent();
                }
            }
        }
Exemplo n.º 16
0
        public NativeWindow(GraphicsMode mode, WindowOptions options)
        {
            if (options.ScreenMode == ScreenMode.Native && DisplayDevice.Default != null)
            {
                options.Width  = DisplayDevice.Default.Width;
                options.Height = DisplayDevice.Default.Height;
            }

            GameWindowFlags windowFlags = GameWindowFlags.Default;

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

            this.refreshMode    = options.RefreshMode;
            this.internalWindow = new InternalWindow(
                this,
                options.Width,
                options.Height,
                mode,
                options.Title,
                windowFlags);
            this.internalWindow.MakeCurrent();
            this.internalWindow.CursorVisible = true;
            if (!options.SystemCursorVisible)
            {
                this.internalWindow.Cursor = MouseCursor.Empty;
            }
            this.internalWindow.VSync = (options.RefreshMode != RefreshMode.VSync) ? VSyncMode.Off : VSyncMode.On;

            Log.Core.Write(
                "Window Specification: " + Environment.NewLine +
                "Buffers: {0}" + Environment.NewLine +
                "Samples: {1}" + Environment.NewLine +
                "ColorFormat: {2}" + Environment.NewLine +
                "AccumulatorFormat: {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)
            {
                Log.Core.WriteError(
                    "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,
                    Log.Exception(e));
            }

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

            DualityApp.TargetResolution = new Vector2(this.internalWindow.ClientSize.Width, this.internalWindow.ClientSize.Height);

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

            // Determine OpenGL capabilities and log them
            GraphicsBackend.LogOpenGLSpecs();
        }
Exemplo n.º 17
0
 public void CreateWithParams(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
 {
     WinFormsControl    = new WinGLUserControl(mode, major, minor, flags);
     Control.Focusable  = true;
     Control.Background = System.Windows.SystemColors.ControlBrush;
 }
Exemplo n.º 18
0
 public InternalWindow(NativeWindow parent, int w, int h, GraphicsMode mode, string title, GameWindowFlags flags) : base(w, h, mode, title, flags)
 {
     this.parent = parent;
 }
Exemplo n.º 19
0
 // NOTE: Only works with Compiler x64, NativeWindow runs but freezes on x86.
 public DemoWindow(int width, int height, GraphicsMode gm)
 //: base (width, height, GraphicsMode.Default, "MonoNanoGUI Demo Window", GameWindowFlags.Default, DisplayDevice.Default, 3, 3, GraphicsContextFlags.ForwardCompatible)
     : base(width, height, gm, "MonoNanoGUI Demo Window")
 {
 }
Exemplo n.º 20
0
 public EglWinContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext,
                      int major, int minor, GraphicsContextFlags flags)
     : base(mode, window, sharedContext, major, minor, flags)
 {
 }
        public static byte[][] GenerateGBAImage(Bitmap bitmap, GraphicsMode mode)
        {
            byte[][] result;
            Bitmap quantazised;
            BitmapData bmp;

            switch (mode)
            {
                case GraphicsMode.Tile8bit:
                    result = new byte[3][];
                    quantazised = Quantazase(bitmap);

                    result[0] = ToTile8bit(bitmap, quantazised.Palette.Entries);
                    result[1] = toRawGBAPalette(quantazised.Palette.Entries);

                    //yes, I'm lazy
                    result[2] = new byte[result[0].Length * 2];
                    fixed (byte* temp = &result[2][0])
                    {
                        short* pointer = (short*)temp;
                        int tiles = 0;
                        for (int i = 0; i < result[0].Length; i++)
                        {
                            pointer[i] = (short)tiles++;
                        }
                    }

                    break;
                case GraphicsMode.Tile4bit:
                    result = new byte[3][];
                    quantazised = Quantazase(bitmap);

                    result[0] = ToTile4bit(bitmap, quantazised.Palette.Entries);
                    result[1] = toRawGBAPalette(quantazised.Palette.Entries);

                    //yes, I'm lazy
                    result[2] = new byte[result[0].Length * 2];
                    fixed (byte* temp = &result[2][0])
                    {
                        short* pointer = (short*)temp;
                        int tiles = 0;
                        for (int i = 0; i < result[0].Length; i++)
                        {
                            pointer[i] = (short)tiles++;
                        }
                    }
                    break;
                default:
                    throw new ArgumentException();
            }
            return result;
        }
Exemplo n.º 22
0
 /// <summary>Constructs a new GLWidget using a given GraphicsMode</summary>
 public GLWidget(GraphicsMode graphicsMode)
     : this(graphicsMode, 1, 0, GraphicsContextFlags.Default)
 {
 }
 public static Bitmap ToBitmap(byte[] GBAGraphics, int length, int index, Color[] palette, int width, GraphicsMode mode, out int emptyGraphicBlocks)
 {
     fixed (byte* pointer = &GBAGraphics[index])
     {
         return ToBitmap(pointer, length, palette, width, mode, out emptyGraphicBlocks);
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes the <see cref="GLWidget"/> with its given values and creates a <see cref="GraphicsContext"/>.
        /// </summary>
        private void Initialize()
        {
            _Initialized = true;

            // If this looks uninitialized...  initialize.
            if (ColorBPP == 0)
            {
                ColorBPP = 32;

                if (DepthBPP == 0)
                {
                    DepthBPP = 16;
                }
            }

            GraphicsMode graphicsMode = new GraphicsMode();

            if (Configuration.RunningOnWindows)
            {
                Debug.WriteLine("OpenTK running on windows");
            }
            else if (Configuration.RunningOnMacOS)
            {
                Debug.WriteLine("OpenTK running on OSX");
            }
            else
            {
                Debug.WriteLine("OpenTK running on X11");
            }

            IntPtr widgetWindowHandle = Window.Handle;

            // IWindowInfo
            if (Configuration.RunningOnWindows)
            {
                _WindowInfo = Utilities.CreateWindowsWindowInfo(widgetWindowHandle);
            }
            else if (Configuration.RunningOnMacOS)
            {
                _WindowInfo = Utilities.CreateMacOSWindowInfo(widgetWindowHandle);
            }
            else
            {
                _WindowInfo = X11.XWindowInfoInitializer.Initialize(graphicsMode, this.Display.Handle, this.Screen.Display.NMonitors, widgetWindowHandle, this.Screen.RootWindow.Handle);
            }

            // GraphicsContext
            _GraphicsContext = new GraphicsContext(graphicsMode, _WindowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags);
            _GraphicsContext.MakeCurrent(_WindowInfo);

            if (GraphicsContext.ShareContexts)
            {
                Interlocked.Increment(ref _GraphicsContextCount);

                if (!_SharedContextInitialized)
                {
                    _SharedContextInitialized = true;
                    ((IGraphicsContextInternal)_GraphicsContext).LoadAll();
                    OnGraphicsContextInitialized();
                }
            }
            else
            {
                ((IGraphicsContextInternal)_GraphicsContext).LoadAll();
                OnGraphicsContextInitialized();
            }

            OnInitialized();
        }
Exemplo n.º 25
0
 public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     return(default_implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags));
 }
Exemplo n.º 26
0
 protected void ChildCtorOnlyResetGraphicMode(GraphicsMode mode)
 {
     this.format = mode;
 }
Exemplo n.º 27
0
        public void CreateWindow(int width, int height, GraphicsMode mode, int major, int minor, GraphicsContextFlags flags, out IGraphicsContext context)
        {
            Rect r = new Rect(0, 0, (short)width, (short)height);
            CreateNativeWindow(mWindowClass, mWindowAttrib, r);

            Show();

            this.context = new GraphicsContext(mode, window, major, minor, flags);
            this.context.MakeCurrent(window);

            context = this.context;
        }
Exemplo n.º 28
0
 /// <summary>
 /// Constructs a new GLControl with the specified GraphicsMode.
 /// </summary>
 /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the control.</param>
 public GLControl(GraphicsMode mode)
     : this(mode, 1, 0, GraphicsContextFlags.Default)
 {
 }
Exemplo n.º 29
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);
 }
Exemplo n.º 30
0
        /// <summary>Initializes the default values of the screen.</summary>
        internal static void Initialize()
        {
            //Initialize the values used by the renderer
            Program.Renderer.Screen.Width      = Interface.CurrentOptions.FullscreenMode ? Interface.CurrentOptions.FullscreenWidth : Interface.CurrentOptions.WindowWidth;
            Program.Renderer.Screen.Height     = Interface.CurrentOptions.FullscreenMode ? Interface.CurrentOptions.FullscreenHeight : Interface.CurrentOptions.WindowHeight;
            Program.Renderer.Screen.Fullscreen = Interface.CurrentOptions.FullscreenMode;
            //Set a new graphics mode, using 8 bits for R,G,B,A & a 8 bit stencil buffer (Currently unused)
            GraphicsMode currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel);

            if (Interface.CurrentOptions.FullscreenMode)
            {
                IList <DisplayResolution> resolutions = OpenTK.DisplayDevice.Default.AvailableResolutions;
                bool resolutionFound = false;
                foreach (DisplayResolution currentResolution in resolutions)
                {
                    //Test resolution
                    if (currentResolution.Width == Interface.CurrentOptions.FullscreenWidth &&
                        currentResolution.Height == Interface.CurrentOptions.FullscreenHeight &&
                        currentResolution.BitsPerPixel == Interface.CurrentOptions.FullscreenBits)
                    {
                        try
                        {
                            OpenTK.DisplayDevice.Default.ChangeResolution(currentResolution);
                            Program.currentGameWindow = new OpenBVEGame(currentResolution.Width, currentResolution.Height, currentGraphicsMode,
                                                                        GameWindowFlags.Default)
                            {
                                Visible     = true,
                                WindowState = WindowState.Fullscreen,
                            };
                            resolutionFound = true;
                            break;
                        }
                        catch
                        {
                            //A candidate resolution was found, but we failed to switch to it
                            //Carry on enumerating through the rest of the resolutions, in case one with
                            //a different refresh rate but identical properties works
                            resolutionFound = false;
                        }
                    }
                }
                if (resolutionFound == false)
                {
                    //Our resolution was not found at all
                    MessageBox.Show(
                        "The graphics card driver reported that the selected resolution was not supported:" + Environment.NewLine +
                        Interface.CurrentOptions.FullscreenWidth + " x " + Interface.CurrentOptions.FullscreenHeight + " " +
                        Interface.CurrentOptions.FullscreenBits + "bit color" + Environment.NewLine +
                        "Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    return;
                }
            }
            else
            {
                try
                {
                    Program.currentGameWindow = new OpenBVEGame(Interface.CurrentOptions.WindowWidth,
                                                                Interface.CurrentOptions.WindowHeight, currentGraphicsMode, GameWindowFlags.Default)
                    {
                        Visible = true
                    };
                }
                catch
                {
                    //Windowed mode failed to launch
                    MessageBox.Show("An error occured whilst tring to launch in windowed mode at resolution:" + Environment.NewLine +
                                    Interface.CurrentOptions.WindowWidth + " x " + Interface.CurrentOptions.WindowHeight + " " +
                                    Environment.NewLine +
                                    "Please check your resolution settings.", Application.ProductName, MessageBoxButtons.OK,
                                    MessageBoxIcon.Hand);
                    Program.RestartArguments = " ";
                    return;
                }
            }
            if (Program.currentGameWindow == null)
            {
                //We should never really get an unspecified error here, but it's good manners to handle all cases
                MessageBox.Show("An unspecified error occured whilst attempting to launch the graphics subsystem.",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                Program.RestartArguments = " ";
                return;
            }

            Program.currentGameWindow.TargetUpdateFrequency = 0;
            Program.currentGameWindow.TargetRenderFrequency = 0;
            Program.currentGameWindow.VSync = Interface.CurrentOptions.VerticalSynchronization ? VSyncMode.On : VSyncMode.Off;
        }
Exemplo n.º 31
0
        void CreateContext(GraphicsMode mode, IWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            Debug.Print("AGL pixel format attributes:");


            // Choose a pixel format with the attributes we specified.
            AGLPixelFormat pixelformat;
            AglGraphicsMode selector = new AglGraphicsMode();
            Mode = selector.SelectGraphicsMode(
                mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
                out pixelformat);
            MyAGLReportError("aglChoosePixelFormat");

            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);
            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(pixelformat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(pixelformat);
            MyAGLReportError("aglDestroyPixelFormat");

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);

            MakeCurrent(carbonWindow);
            Debug.Print("context: {0}", Handle.Handle);

            dummyContext = new GraphicsContext(Handle,
                GetAddress,
                delegate()
                {
                    return new ContextHandle(Agl.aglGetCurrentContext());
                });
        }
Exemplo n.º 32
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();
        }
Exemplo n.º 33
0
        /// <summary>Draw the slider ticks</summary>
        private void DrawTicks(Graphics g, Rectangle bounds)
        {
            Rectangle trackRect = GetTrackRectangle();
            float increment = (float)Increment();
            increment = (float)Increment();
            int count = (int)(IncrementScale());

            float endcap = (Orientation == Orientation.Horizontal ? (float)trackRect.Right - (1 + ButtonSize.Width / 2) : (float)trackRect.Bottom - (1 + ButtonSize.Height / 2));
            float offset = 0;
            int shadowlen = TickMaxLength - 1;
            int spacer = TickMaxLength + TickMinPadding;
            RectangleF buttonRect = GetButtonRectangle();

            switch (TickType)
            {
                #region Composite Style
                case TickMode.Composite:
                    {
                        using (GraphicsMode md = new GraphicsMode(g, SmoothingMode.None))
                        {
                            switch (TickStyle)
                            {
                                case TickStyle.Both:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;

                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(val, top), new PointF(val, top + TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, top + 1), new PointF(val + 1, top + shadowlen));
                                                        g.DrawLine(pn2, new PointF(val, bottom), new PointF(val, bottom - TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, bottom), new PointF(val + 1, bottom - shadowlen));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(val, top), new PointF(val, top + 2));
                                                        g.DrawLine(pn, new PointF(val, bottom), new PointF(val, bottom - 2));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(left, val), new PointF(left + TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(left + 1, val + 1), new PointF(left + shadowlen, val + 1));
                                                        g.DrawLine(pn2, new PointF(right, val), new PointF(right - TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(right, val + 1), new PointF(right - shadowlen, val + 1));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(left, val), new PointF(left + 2, val));
                                                        g.DrawLine(pn, new PointF(right, val), new PointF(right - 2, val));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.BottomRight:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(val, bottom), new PointF(val, bottom - TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, bottom), new PointF(val + 1, bottom - shadowlen));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(val, bottom), new PointF(val, bottom - 2));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(right, val), new PointF(right - TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(right, val + 1), new PointF(right - shadowlen, val + 1));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(right, val), new PointF(right - 2, val));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.TopLeft:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(val, top), new PointF(val, top + TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, top + 1), new PointF(val + 1, top + shadowlen));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(val, top), new PointF(val, top + 2));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(left, val), new PointF(left + TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(left + 1, val + 1), new PointF(left + shadowlen, val + 1));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(left, val), new PointF(left + 2, val));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                            }
                        }
                        break;
                    }
                #endregion

                #region Large Stepped Style
                case TickMode.LargeStepped:
                    {
                        using (GraphicsMode md = new GraphicsMode(g, SmoothingMode.None))
                        {
                            switch (TickStyle)
                            {
                                case TickStyle.Both:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        val = (increment * i) + offset;
                                                        g.DrawLine(pn2, new PointF(val, top), new PointF(val, top + TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, top + 1), new PointF(val + 1, top + shadowlen));
                                                        g.DrawLine(pn2, new PointF(val, bottom), new PointF(val, bottom - TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, bottom), new PointF(val + 1, bottom - shadowlen));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        val = (increment * i) + offset;
                                                        g.DrawLine(pn2, new PointF(left, val), new PointF(left + TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(left + 1, val + 1), new PointF(left + shadowlen, val + 1));
                                                        g.DrawLine(pn2, new PointF(right, val), new PointF(right - TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(right, val + 1), new PointF(right - shadowlen, val + 1));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.BottomRight:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        val = (increment * i) + offset;
                                                        g.DrawLine(pn2, new PointF(val, bottom), new PointF(val, bottom - TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, bottom), new PointF(val + 1, bottom - shadowlen));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(right, val), new PointF(right - TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(right, val + 1), new PointF(right - shadowlen, val + 1));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.TopLeft:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(val, top), new PointF(val, top + TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, top + 1), new PointF(val + 1, top + shadowlen));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(left, val), new PointF(left + TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(left + 1, val + 1), new PointF(left + shadowlen, val + 1));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                            }
                        }
                        break;
                    }
                #endregion

                #region Precision Style
                case TickMode.Precision:
                    {
                        using (GraphicsMode md = new GraphicsMode(g, SmoothingMode.None))
                        {
                            float split = increment * .5f;
                            bool valid = split > 2;
                            switch (TickStyle)
                            {
                                case TickStyle.Both:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;

                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(val, top), new PointF(val, top + TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, top + 1), new PointF(val + 1, top + shadowlen));
                                                        g.DrawLine(pn2, new PointF(val, bottom), new PointF(val, bottom - TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, bottom), new PointF(val + 1, bottom - shadowlen));
                                                        if (valid && val < endcap)
                                                        {
                                                            g.DrawLine(pn, new PointF(val + split, top), new PointF(val + split, top + 1));
                                                            g.DrawLine(pn, new PointF(val + split, bottom), new PointF(val + split, bottom - 1));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(val, top), new PointF(val, top + 2));
                                                        g.DrawLine(pn, new PointF(val, bottom), new PointF(val, bottom - 2));
                                                        if (valid && val < endcap)
                                                        {
                                                            g.DrawLine(pn, new PointF(val + split, top), new PointF(val + split, top + 1));
                                                            g.DrawLine(pn, new PointF(val + split, bottom), new PointF(val + split, bottom - 1));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(left, val), new PointF(left + TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(left + 1, val + 1), new PointF(left + shadowlen, val + 1));
                                                        g.DrawLine(pn2, new PointF(right, val), new PointF(right - TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(right, val + 1), new PointF(right - shadowlen, val + 1));
                                                        if (valid && val < endcap)
                                                        {
                                                            g.DrawLine(pn, new PointF(left, val + split), new PointF(left + 1, val + split));
                                                            g.DrawLine(pn, new PointF(right, val + split), new PointF(right - 1, val + split));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(left, val), new PointF(left + 2, val));
                                                        g.DrawLine(pn, new PointF(right, val), new PointF(right - 2, val));
                                                        if (valid && val < endcap)
                                                        {
                                                            g.DrawLine(pn, new PointF(left, val + split), new PointF(left + 1, val + split));
                                                            g.DrawLine(pn, new PointF(right, val + split), new PointF(right - 1, val + split));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.BottomRight:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(val, bottom), new PointF(val, bottom - TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, bottom), new PointF(val + 1, bottom - shadowlen));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(val + split, bottom), new PointF(val + split, bottom - 1));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(val, bottom), new PointF(val, bottom - 2));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(val + split, bottom), new PointF(val + split, bottom - 1));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(right, val), new PointF(right - TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(right, val + 1), new PointF(right - shadowlen, val + 1));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(right, val + split), new PointF(right - 2, val + split));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(right, val), new PointF(right - 2, val));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(right, val + split), new PointF(right - 2, val + split));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.TopLeft:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(val, top), new PointF(val, top + TickMaxLength));
                                                        g.DrawLine(pn3, new PointF(val + 1, top + 1), new PointF(val + 1, top + shadowlen));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(val + split, top), new PointF(val + split, top + 1));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(val, top), new PointF(val, top + 2));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(val + split, top), new PointF(val + split, top + 1));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    if (Mod(i, LargeChange))
                                                    {
                                                        g.DrawLine(pn2, new PointF(left, val), new PointF(left + TickMaxLength, val));
                                                        g.DrawLine(pn3, new PointF(left + 1, val + 1), new PointF(left + shadowlen, val + 1));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(left, val + split), new PointF(left + 2, val + split));
                                                    }
                                                    else
                                                    {
                                                        g.DrawLine(pn, new PointF(left, val), new PointF(left + 2, val));
                                                        if (valid && val < endcap)
                                                            g.DrawLine(pn, new PointF(left, val + split), new PointF(left + 2, val + split));
                                                    }
                                                }
                                            }
                                        }
                                        break;
                                    }
                            }
                        }
                        break;
                    }
                #endregion

                #region Standard Tick Style
                case TickMode.Standard:
                    {
                        using (GraphicsMode md = new GraphicsMode(g, SmoothingMode.None))
                        {
                            switch (TickStyle)
                            {
                                case TickStyle.Both:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    g.DrawLine(pn, new PointF(val, top), new PointF(val, top + 2));
                                                    g.DrawLine(pn, new PointF(val, bottom), new PointF(val, bottom - 2));
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    g.DrawLine(pn, new PointF(left, val), new PointF(left + 2, val));
                                                    g.DrawLine(pn, new PointF(right, val), new PointF(right - 2, val));
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.BottomRight:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float bottom = buttonRect.Bottom + spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    g.DrawLine(pn, new PointF(val, bottom), new PointF(val, bottom - 2));
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float right = buttonRect.Right + spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    g.DrawLine(pn, new PointF(right, val), new PointF(right - 2, val));
                                                }
                                            }
                                        }
                                        break;
                                    }
                                case TickStyle.TopLeft:
                                    {
                                        if (Orientation == Orientation.Horizontal)
                                        {
                                            float top = buttonRect.Top - spacer;
                                            offset = (ButtonSize.Width / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    g.DrawLine(pn, new PointF(val, top), new PointF(val, top + 2));
                                                }
                                            }
                                        }
                                        else
                                        {
                                            float left = buttonRect.Left - spacer;
                                            offset = (ButtonSize.Height / 2) + TrackPadding;
                                            float val = offset;
                                            using (Pen pn = new Pen(TickColor, .5f), pn2 = new Pen(TickColor, 1f), pn3 = new Pen(Color.FromArgb(100, Color.DarkGray), 1f))
                                            {
                                                for (int i = 0; i < count + 1; i++)
                                                {
                                                    val = (increment * i) + offset;
                                                    g.DrawLine(pn, new PointF(left, val), new PointF(left + 2, val));
                                                }
                                            }
                                        }
                                        break;
                                    }
                            }
                        }
                        break;
                    }
                    #endregion
            }
        }
Exemplo n.º 34
0
 public GLSurface(GraphicsMode graphicsMode) :
     this(graphicsMode, 1, 0, GraphicsContextFlags.Default)
 {
 }
Exemplo n.º 35
0
 public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     throw new PlatformNotSupportedException(error_string);
 }
Exemplo n.º 36
0
 public GLSurface(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
 {
     Handler.CreateWithParams(mode, major, minor, flags);
     Initialize();
 }
 public static int BitsPerPixel(GraphicsMode mode)
 {
     switch (mode)
     {
         case GraphicsMode.Tile8bit:
             return 8;
         case GraphicsMode.Tile4bit:
             return 4;
         case GraphicsMode.BitmapTrueColour:
             return 16;
         case GraphicsMode.Bitmap8bit:
             return 8;
         default:
             return 0;
     }
 }
        /// <summary>
        /// Try to create the graphics context.
        /// </summary>
        /// <param name="requestedWidth">The requested width.</param>
        /// <param name="requestedHeight">The requested height.</param>
        /// <param name="graphicMode">The graphics mode.</param>
        /// <param name="versionMajor">The major version of OpenGL.</param>
        /// <param name="versionMinor">The minor version of OpenGL.</param>
        /// <param name="creationFlags">The creation flags.</param>
        /// <returns>The created GameWindow.</returns>
        private static OpenTK.GameWindow TryGameWindow(int requestedWidth, int requestedHeight, GraphicsMode graphicMode, int versionMajor, int versionMinor, GraphicsContextFlags creationFlags)
        {
            try
            {
#if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGL || SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES
                // Preload proper SDL native library (depending on CPU type)
                // This is for OpenGL ES on desktop
                Core.NativeLibrary.PreloadLibrary("SDL2.dll");
#endif

                var gameWindow = new OpenTK.GameWindow(requestedWidth, requestedHeight, graphicMode, GameContext.ProductName, GameWindowFlags.Default, DisplayDevice.Default, versionMajor, versionMinor,
                                                       creationFlags);
                return(gameWindow);
            }
            catch (Exception)
            {
                return(null);
            }
        }
 public static int RawGraphicsLength(Size size, GraphicsMode mode)
 {
     return size.Width * size.Height * BitsPerPixel(mode) / 8;
 }
Exemplo n.º 40
0
 public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode,
                                                  GameWindowFlags options, DisplayDevice device)
 {
     return((INativeWindow)_platform_factory.CreateNativeWindow(x, y, width, height, title,
                                                                mode, options, device));
 }
 public static Bitmap ToBitmap(byte* GBAGraphics, int length, Color[] palette, int width, GraphicsMode mode, out int emptyGraphicBlocks)
 {
     Bitmap result = null;
     emptyGraphicBlocks = 0;
     switch (mode)
     {
         case GraphicsMode.Tile8bit:
             result = FromTile8bit(GBAGraphics, length, palette, width, out emptyGraphicBlocks);
             break;
         case GraphicsMode.Tile4bit:
             result = FromTile4bit(GBAGraphics, length, palette, width, out emptyGraphicBlocks);
             break;
         case GraphicsMode.BitmapTrueColour:
             result = FromBitmapTrueColour(GBAGraphics, length, palette, width, out emptyGraphicBlocks);
             break;
         case GraphicsMode.Bitmap8bit:
             result = FromBitmapIndexed(GBAGraphics, length, palette, width, out emptyGraphicBlocks);
             break;
     }
     return result;
 }
 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));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="graphics"></param>
 /// <param name="mode"></param>
 /// <param name="TSAdata"></param>
 /// <param name="offset"></param>
 /// <param name="TSAsize"></param>
 /// <returns>Tile8bit raw GBA graphics</returns>
 public static byte[] TSAmap(byte[] graphics, GraphicsMode mode, byte[] TSAdata, int offset, Size TSAsize)
 {
     byte[] result;
     if (TSAsize.Height * TSAsize.Width > TSAdata.Length / 2)
     {
         TSAsize.Height = TSAdata.Length / (2 * TSAsize.Width);
     }
     fixed (byte* graphicsPointer = &graphics[0])
     {
         fixed (byte* TSApointer = &TSAdata[offset])
         {
             switch (mode)
             {
                 case GraphicsMode.Tile8bit:
                     result = TSAmapFrom8bitTileGraphics(graphicsPointer, graphics.Length / 64, TSApointer, TSAsize);
                     break;
                 case GraphicsMode.Tile4bit:
                     result = TSAmapFrom4bitTileGraphics(graphicsPointer, graphics.Length / 32, TSApointer, TSAsize);
                     break;
                 default:
                     throw new ArgumentException("GraphicsMode has to be either Tile8bit or Tile4bit");
             }
         }
     }
     return result;
 }
 public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     return(new X11GLContext(mode, window, shareContext, directRendering, major, minor, flags));
 }
Exemplo n.º 45
0
 public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     throw new PlatformNotSupportedException(error_string);
 }
Exemplo n.º 46
0
 public static extern GraphicsMode SetGraphicsMode(IntPtr hdc, GraphicsMode iMode);
Exemplo n.º 47
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            List<int> aglAttributes = new List<int>();
            
            Debug.Print("AGL pixel format attributes:");
            Debug.Indent();
            
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);
            
            if (mode.Depth > 0)
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
            
            if (mode.Stencil > 0)
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
            
            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
            }
            
            if (mode.Samples > 1)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
            }
            
            if (fullscreen)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
            }
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);
            
            Debug.Unindent();
            
            Debug.Write("Attribute array:  ");
            for (int i = 0; i < aglAttributes.Count; i++)
                Debug.Write(aglAttributes[i].ToString() + "  ");
            Debug.WriteLine("");
            
            AGLPixelFormat myAGLPixelFormat;
            
            // Choose a pixel format with the attributes we specified.
            if (fullscreen)
            {
                IntPtr gdevice;
                IntPtr cgdevice = GetQuartzDevice(carbonWindow);
                
                if (cgdevice == IntPtr.Zero)
                    cgdevice = (IntPtr)DisplayDevice.Default.Id;
                
                OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);
                
                if (status != OSStatus.NoError)
                    throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
                
                myAGLPixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, aglAttributes.ToArray());
                
                Agl.AglError err = Agl.GetError();
                
                if (err == Agl.AglError.BadPixelFormat)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");
                    
                    CreateContext(mode, carbonWindow, shareContextRef, false);
                    return;
                }
            }

            else
            {
                myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());
                
                MyAGLReportError("aglChoosePixelFormat");
            }
            
            
            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);
            
            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");
            
            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");
            
            Debug.Print("IsControl: {0}", carbonWindow.IsControl);
            
            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);
            
            MakeCurrent(carbonWindow);
            
            Debug.Print("context: {0}", Handle.Handle);
        }
Exemplo n.º 48
0
        private IntPtr SelectPixelFormat(GraphicsMode mode, int majorVersion, int minorVersion)
        {
            List <NSOpenGLPixelFormatAttribute> attributes = new List <NSOpenGLPixelFormatAttribute>();

            var profile = NSOpenGLProfile.VersionLegacy;

            if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 2))
            {
                profile = NSOpenGLProfile.Version3_2Core;
                Debug.Print("Running the OpenGL core profile.");
            }
            else
            {
                Debug.Print("Running the legacy OpenGL profile. Start with version major=3, minor=2 or later for the 3.2 profile.");
            }

            Debug.Print("NSGL pixel format attributes:");
            Debug.Indent();

            AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.OpenGLProfile, (int)profile);

            if (mode.ColorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.ColorSize, mode.ColorFormat.BitsPerPixel);
            }

            if (mode.Depth > 0)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.DepthSize, mode.Depth);
            }

            if (mode.Stencil > 0)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.StencilSize, mode.Stencil);
            }

            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.AccumSize, mode.AccumulatorFormat.BitsPerPixel);
            }

            if (mode.Samples > 1)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.SampleBuffers, 1);
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.Samples, mode.Samples);
            }

            if (mode.Buffers > 1)
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.DoubleBuffer);
            }

            // If at least a single accelerated pixel format is available,
            // then use that. If no accelerated formats are available, fall
            // back to software rendering.
            if (IsAccelerationSupported())
            {
                AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.Accelerated);
            }

            AddPixelAttrib(attributes, (NSOpenGLPixelFormatAttribute)0);

            Debug.Unindent();

            Debug.Write("Attribute array:  ");
            for (int i = 0; i < attributes.Count; i++)
            {
                Debug.Write(attributes[i].ToString() + "  ");
            }
            Debug.WriteLine("");

            // Create pixel format
            var pixelFormat = Cocoa.SendIntPtr(Class.Get("NSOpenGLPixelFormat"), Selector.Alloc);

            unsafe
            {
                fixed(NSOpenGLPixelFormatAttribute *ptr = attributes.ToArray())
                {
                    pixelFormat = Cocoa.SendIntPtr(pixelFormat, Selector.Get("initWithAttributes:"), (IntPtr)ptr);
                }
            }

            return(pixelFormat);
        }
Exemplo n.º 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));
 }
Exemplo n.º 50
0
 public virtual IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     return new X11GLContext(mode, window, shareContext, directRendering, major, minor, flags);
 }
Exemplo n.º 51
0
 public IGraphicsContext CreateESContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags)
 {
     throw new PlatformNotSupportedException(error_string);
 }
Exemplo n.º 52
0
        private void Initialize()
        {
            _Initialized = true;

            // If this looks uninitialized...  initialize.
            if (ColorBPP == 0)
            {
                ColorBPP = 32;

                if (DepthBPP == 0)
                {
                    DepthBPP = 16;
                }
            }

            ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);

            ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);

            int buffers = 2;

            if (SingleBuffer)
            {
                buffers--;
            }

            GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);

            if (Configuration.RunningOnWindows)
            {
                Console.WriteLine("OpenTK running on windows");
            }
            else if (Configuration.RunningOnMacOS)
            {
                Console.WriteLine("OpenTK running on OSX");
            }
            else
            {
                Console.WriteLine("OpenTK running on X11");
            }

            // IWindowInfo
            if (Configuration.RunningOnWindows)
            {
                _WindowInfo = InitializeWindows();
            }
            else if (Configuration.RunningOnMacOS)
            {
                _WindowInfo = InitializeOSX();
            }
            else
            {
                _WindowInfo = InitializeX(graphicsMode);
            }

            // GraphicsContext
            _GraphicsContext = new GraphicsContext(graphicsMode, _WindowInfo, GLVersionMajor, GLVersionMinor, GraphicsContextFlags);
            _GraphicsContext.MakeCurrent(_WindowInfo);

            if (GraphicsContext.ShareContexts)
            {
                Interlocked.Increment(ref _GraphicsContextCount);

                if (!_SharedContextInitialized)
                {
                    _SharedContextInitialized = true;
                    ((IGraphicsContextInternal)_GraphicsContext).LoadAll();
                    OnGraphicsContextInitialized();
                }
            }
            else
            {
                ((IGraphicsContextInternal)_GraphicsContext).LoadAll();
                OnGraphicsContextInitialized();
            }

            OnInitialized();
        }
Exemplo n.º 53
0
 public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     return default_implementation.CreateGLContext(mode, window, shareContext, directRendering, major, minor, flags);
 }
Exemplo n.º 54
0
        /// <summary>Create the track dc</summary>
        private void CreateTrack()
        {
            Rectangle bounds = new Rectangle(0, 0, Width, Height);
            Rectangle trackRect = GetTrackRectangle();

            using (Graphics g = Graphics.FromHdc(_cTrackDc.Hdc))
            {
                // fill it in
                if (BackgroundImage != null)
                {
                    using (GraphicsMode md = new GraphicsMode(g, SmoothingMode.HighQuality))
                    {
                        using (ImageAttributes ia = new ImageAttributes())
                            g.DrawImage(BackgroundImage, bounds, 0, 0, BackgroundImage.Width, BackgroundImage.Height, GraphicsUnit.Pixel, ia);
                    }
                }
                else
                {
                    DrawBackGround(g, bounds);
                }
                // draw ticks
                if (TickStyle != TickStyle.None)
                    DrawTicks(g, bounds);
                // create the path
                if (Orientation == Orientation.Horizontal)//***offsets wrong on createpath?
                    trackRect.Width -= 1;
                else
                    trackRect.Height -= 1;
                using (GraphicsMode mode = new GraphicsMode(g, SmoothingMode.HighQuality))
                {
                    // draw track shadow
                    if (TrackShadow)
                    {
                        trackRect.Inflate(2, 2);
                        using (GraphicsPath gp = CreateRoundRectanglePath(g, trackRect, 2))
                        {
                            // light shadow
                            using (Pen pn = new Pen(Color.FromArgb(80, TrackShadowColor), 1f))
                                g.DrawPath(pn, gp);
                        }
                        trackRect.Inflate(-1, -1);
                        using (GraphicsPath gp = CreateRoundRectanglePath(g, trackRect, 2))
                        {
                            // darker
                            using (Pen pn = new Pen(Color.FromArgb(120, TrackShadowColor), 1f))
                                g.DrawPath(pn, gp);
                        }
                        trackRect.Inflate(-1, -1);
                    }

                    using (GraphicsPath gp = CreateRoundRectanglePath(g, trackRect, 2))
                    {
                        // fill color
                        if (TrackFillColor != Color.Transparent)
                        {
                            using (Brush br = new SolidBrush(TrackFillColor))
                                g.FillPath(br, gp);
                        }
                        // draw the outline
                        using (Pen pn = new Pen(TrackBorderColor, 1f))
                            g.DrawPath(pn, gp);
                    }
                }
            }
        }
Exemplo n.º 55
0
 public IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window)
 {
     return new AglContext(mode, window);
 }
Exemplo n.º 56
0
        private void DrawFlyOut(Graphics g)
        {
            Rectangle buttonRect = GetButtonRectangle();
            Rectangle flyoutRect;
            int pos;
            string data = "";

            if (Orientation == Orientation.Horizontal)
            {
                pos = buttonRect.Left + (int)(buttonRect.Width * .5f);
                int offset = (int)(FlyOutMaxWidth * .5f);
                flyoutRect = new Rectangle(pos - offset, buttonRect.Top - (FlyOutMaxDepth + FlyOutSpacer), FlyOutMaxWidth, FlyOutMaxDepth);
                offset -= 8;
                using (GraphicsMode mode = new GraphicsMode(g, SmoothingMode.HighQuality))
                {
                    using (GraphicsPath gp = CreatePointedRectangularPath(g, flyoutRect, PointDirection.Bottom, 5, 4, offset))
                    {
                        using (Brush br = new SolidBrush(Color.FromArgb(220, Color.White)))
                            g.FillPath(br, gp);
                        using (Pen pn = new Pen(Color.FromArgb(160, Color.DimGray)))
                            g.DrawPath(pn, gp);

                        if (FlyOutInfo != null)
                            FlyOutInfo(ref data);
                        if (data.Length == 0)
                            data = Value.ToString("0");
                        using (StringFormat sf = new StringFormat())
                        {
                            sf.FormatFlags = StringFormatFlags.NoWrap;
                            sf.Alignment = StringAlignment.Center;
                            sf.LineAlignment = StringAlignment.Center;
                            using (Font ft = new Font("Arial", 8f, FontStyle.Regular))
                                g.DrawString(data, ft, Brushes.Black, flyoutRect, sf);
                        }
                    }
                }
            }
            else
            {
                pos = buttonRect.Top + (int)(buttonRect.Height * .5f);
                int offset = (int)(FlyOutMaxWidth * .5f);
                flyoutRect = new Rectangle(buttonRect.Left - (FlyOutMaxDepth + FlyOutSpacer), pos - offset, FlyOutMaxDepth, FlyOutMaxWidth);
                using (GraphicsMode mode = new GraphicsMode(g, SmoothingMode.HighQuality))
                {
                    using (GraphicsPath gp = CreatePointedRectangularPath(g, flyoutRect, PointDirection.Right, 5, 4, 1))
                    {
                        using (Brush br = new SolidBrush(Color.FromArgb(200, Color.White)))
                            g.FillPath(br, gp);
                        using (Pen pn = new Pen(Color.FromArgb(240, ButtonBorderColor)))
                            g.DrawPath(pn, gp);

                        if (FlyOutInfo != null)
                            FlyOutInfo(ref data);
                        if (data.Length == 0)
                            data = Value.ToString("0");
                        flyoutRect.Width -= 4;
                        using (StringFormat sf = new StringFormat())
                        {
                            sf.FormatFlags = StringFormatFlags.NoWrap;
                            sf.Alignment = StringAlignment.Center;
                            sf.LineAlignment = StringAlignment.Center;
                            using (Font ft = new Font("Arial", 8f, FontStyle.Regular))
                                g.DrawString(data, ft, Brushes.Black, flyoutRect, sf);
                        }
                    }
                }
            }
        }
Exemplo n.º 57
0
 public void CreateWithParams(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags)
 {
     Control          = new MacGLView8(mode, major, minor, flags);
     Control.CanFocus = true;
 }
Exemplo n.º 58
0
 public WinGLContext(GraphicsMode format, WinWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags)
 {
     lock (WinGLContext.SyncRoot)
     {
         if (window == null)
         {
             throw new ArgumentNullException("window", "Must point to a valid window.");
         }
         if (window.WindowHandle == IntPtr.Zero)
         {
             throw new ArgumentException("window", "Must be a valid window.");
         }
         this.Mode = format;
         this.SetGraphicsModePFD(format, window);
         lock (WinGLContext.LoadLock)
         {
             if (!WinGLContext.wgl_loaded)
             {
                 ContextHandle local_0 = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
                 Wgl.Imports.MakeCurrent(window.DeviceContext, local_0.Handle);
                 Wgl.LoadAll();
                 Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
                 Wgl.Imports.DeleteContext(local_0.Handle);
                 WinGLContext.wgl_loaded = true;
             }
             if (Wgl.Delegates.wglCreateContextAttribsARB != null)
             {
                 try
                 {
                     List <int> local_1 = new List <int>();
                     local_1.Add(8337);
                     local_1.Add(major);
                     local_1.Add(8338);
                     local_1.Add(minor);
                     if (flags != GraphicsContextFlags.Default)
                     {
                         local_1.Add(8340);
                         local_1.Add((int)flags);
                     }
                     local_1.Add(0);
                     local_1.Add(0);
                     this.Handle = new ContextHandle(Wgl.Arb.CreateContextAttribs(window.DeviceContext, sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero, local_1.ToArray()));
                     int temp_84 = this.Handle == ContextHandle.Zero ? 1 : 0;
                 }
                 catch (EntryPointNotFoundException exception_0)
                 {
                 }
                 catch (NullReferenceException exception_1)
                 {
                 }
             }
         }
         if (this.Handle == ContextHandle.Zero)
         {
             this.Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
             if (this.Handle == ContextHandle.Zero)
             {
                 this.Handle = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
             }
             if (this.Handle == ContextHandle.Zero)
             {
                 throw new GraphicsContextException(string.Format("Context creation failed. Wgl.CreateContext() error: {0}.", (object)Marshal.GetLastWin32Error()));
             }
         }
         if (sharedContext == null)
         {
             return;
         }
         Marshal.GetLastWin32Error();
         Wgl.Imports.ShareLists((sharedContext as IGraphicsContextInternal).Context.Handle, this.Handle.Handle);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 60
0
        void CreateContext(GraphicsMode mode, CarbonWindowInfo carbonWindow, IntPtr shareContextRef, bool fullscreen)
        {
            List <int> aglAttributes = new List <int>();

            Debug.Print("AGL pixel format attributes:");
            Debug.Indent();

            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RGBA);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DOUBLEBUFFER);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_RED_SIZE, mode.ColorFormat.Red);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_GREEN_SIZE, mode.ColorFormat.Green);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_BLUE_SIZE, mode.ColorFormat.Blue);
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ALPHA_SIZE, mode.ColorFormat.Alpha);

            if (mode.Depth > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_DEPTH_SIZE, mode.Depth);
            }

            if (mode.Stencil > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_STENCIL_SIZE, mode.Stencil);
            }

            if (mode.AccumulatorFormat.BitsPerPixel > 0)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_RED_SIZE, mode.AccumulatorFormat.Red);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha);
            }

            if (mode.Samples > 1)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLE_BUFFERS_ARB, 1);
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_SAMPLES_ARB, mode.Samples);
            }

            if (fullscreen)
            {
                AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_FULLSCREEN);
            }
            AddPixelAttrib(aglAttributes, Agl.PixelFormatAttribute.AGL_NONE);

            Debug.Unindent();

            Debug.Write("Attribute array:  ");
            for (int i = 0; i < aglAttributes.Count; i++)
            {
                Debug.Write(aglAttributes[i].ToString() + "  ");
            }
            Debug.WriteLine("");

            AGLPixelFormat myAGLPixelFormat;

            // Choose a pixel format with the attributes we specified.
            if (fullscreen)
            {
                IntPtr gdevice;
                IntPtr cgdevice = GetQuartzDevice(carbonWindow);

                if (cgdevice == IntPtr.Zero)
                {
                    cgdevice = (IntPtr)DisplayDevice.Default.Id;
                }

                OSStatus status = Carbon.API.DMGetGDeviceByDisplayID(cgdevice, out gdevice, false);

                if (status != OSStatus.NoError)
                {
                    throw new MacOSException(status, "DMGetGDeviceByDisplayID failed.");
                }

                myAGLPixelFormat = Agl.aglChoosePixelFormat(ref gdevice, 1, aglAttributes.ToArray());

                Agl.AglError err = Agl.GetError();

                if (err == Agl.AglError.BadPixelFormat)
                {
                    Debug.Print("Failed to create full screen pixel format.");
                    Debug.Print("Trying again to create a non-fullscreen pixel format.");

                    CreateContext(mode, carbonWindow, shareContextRef, false);
                    return;
                }
            }

            else
            {
                myAGLPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, aglAttributes.ToArray());

                MyAGLReportError("aglChoosePixelFormat");
            }


            Debug.Print("Creating AGL context.  Sharing with {0}", shareContextRef);

            // create the context and share it with the share reference.
            Handle = new ContextHandle(Agl.aglCreateContext(myAGLPixelFormat, shareContextRef));
            MyAGLReportError("aglCreateContext");

            // Free the pixel format from memory.
            Agl.aglDestroyPixelFormat(myAGLPixelFormat);
            MyAGLReportError("aglDestroyPixelFormat");

            Debug.Print("IsControl: {0}", carbonWindow.IsControl);

            SetDrawable(carbonWindow);
            SetBufferRect(carbonWindow);
            Update(carbonWindow);

            MakeCurrent(carbonWindow);

            Debug.Print("context: {0}", Handle.Handle);
        }