Ejemplo n.º 1
0
 internal static extern bool AdjustWindowRectEx(ref RECT lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
Ejemplo n.º 2
0
        private WinGLContext(IntPtr WinHandle)
        {
            this.hWnd = WinHandle;
            RegisterClassOnce();
            int Width = 512;
            int Height = 512;

            if (WinHandle == IntPtr.Zero)
            {

                WindowStyle style = WindowStyle.OverlappedWindow | WindowStyle.ClipChildren | WindowStyle.ClipSiblings;
                ExtendedWindowStyle ex_style = ParentStyleEx;

                var rect = new RECT()
                {
                    left = 0,
                    top = 0,
                    right = Width,
                    bottom = Height,
                };
                AdjustWindowRectEx(ref rect, style, false, ex_style);

                IntPtr window_name = Marshal.StringToHGlobalAuto("Title");
                hWnd = CreateWindowEx(
                    ex_style, ClassName, window_name, style,
                    rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
                    IntPtr.Zero, IntPtr.Zero, Instance, IntPtr.Zero
                );

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

            DC = GetDC(hWnd);

            var pfd = new PixelFormatDescriptor();
            pfd.Size = (short)sizeof(PixelFormatDescriptor);
            pfd.Version = 1;
            pfd.Flags = PixelFormatDescriptorFlags.DRAW_TO_WINDOW | PixelFormatDescriptorFlags.SUPPORT_OPENGL | PixelFormatDescriptorFlags.DOUBLEBUFFER;
            pfd.LayerType = 0;
            pfd.PixelType = PixelType.RGBA; // PFD_TYPE_RGBA
            //pfd.ColorBits = 32;
            pfd.ColorBits = 24;
            pfd.DepthBits = 16;
            pfd.StencilBits = 8;

            var pf = ChoosePixelFormat(DC, &pfd);
            //pf = 10;

            if (!SetPixelFormat(DC, pf, &pfd))
            {
                Console.WriteLine("Error SetPixelFormat failed.");
            }

            this.Context = WGL.wglCreateContext(DC);
            if (SharedContext != IntPtr.Zero)
            {
                //Console.WriteLine("SharedContext!"); Console.ReadKey();
                if (!WGL.wglShareLists(SharedContext, this.Context))
                {
                    throw(new InvalidOperationException("Can't share lists"));
                }
            }
            MakeCurrent();
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "Version:{0}.{1}", GL.glGetInteger(GL.GL_MAJOR_VERSION), GL.glGetInteger(GL.GL_MINOR_VERSION));
            DynamicLibraryFactory.MapLibraryToType<Extension>(new DynamicLibraryGL());
            GL.LoadAllOnce();

            #if false
            if (Extension.wglCreateContextAttribsARB != null)
            {
                ReleaseCurrent();
                WGL.wglDeleteContext(this.Context);
                fixed (int* AttribListPtr = new int[] { (int)ArbCreateContext.MajorVersion, 3, (int)ArbCreateContext.MinorVersion, 1, 0, 0 })
                {
                    this.Context = Extension.wglCreateContextAttribsARB(DC, SharedContext, AttribListPtr);
                }
                if (this.Context == IntPtr.Zero) throw(new Exception("Error creating context"));
                MakeCurrent();

                Console.WriteLine("OpenGL Version: {0}", Marshal.PtrToStringAnsi(new IntPtr(GL.glGetString(GL.GL_VERSION))));
                //Console.ReadKey();
            }
            #endif

            if (SharedContext == IntPtr.Zero)
            {
                SharedContext = this.Context;
            }

            if (Extension.wglSwapIntervalEXT != null)
            {
                Extension.wglSwapIntervalEXT(0);
            }

            //RECT clientRect;
            //GetClientRect(hWnd, &clientRect);
        }
Ejemplo n.º 3
0
 public static extern bool AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);