当前位置: 首页>>代码示例>>C#>>正文


C# GLControl.MakeCurrent方法代码示例

本文整理汇总了C#中OpenTK.GLControl.MakeCurrent方法的典型用法代码示例。如果您正苦于以下问题:C# GLControl.MakeCurrent方法的具体用法?C# GLControl.MakeCurrent怎么用?C# GLControl.MakeCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenTK.GLControl的用法示例。


在下文中一共展示了GLControl.MakeCurrent方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Viewport

        public Viewport(Window parentWindow)
        {
            ParentWindow = parentWindow;

            OpenTK.Graphics.GraphicsMode Mode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(8, 8, 8, 8), 24);
            GLControl = new GLControl(Mode, 4, 4, OpenTK.Graphics.GraphicsContextFlags.Default);
            GLControl.MakeCurrent();
            GLControl.Paint += GLControl_Paint;
            GLControl.Resize += GLControl_Resize;
            GLControl.MouseDown += GLControl_MouseDown;
            GLControl.MouseUp += GLControl_MouseUp;
            GLControl.MouseMove += GLControl_MouseMove;
            GLControl.MouseWheel += GLControl_MouseWheel;
            GLControl.MouseLeave += GLControl_MouseLeave;
            GLControl.Dock = System.Windows.Forms.DockStyle.Fill;

            GL.Disable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.DepthMask(true);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            _Camera = new Camera();
            _Camera.ViewportSize = new int2(GLControl.Width, GLControl.Height);
            _Camera.PropertyChanged += _Camera_PropertyChanged;
        }
开发者ID:dtegunov,项目名称:membranorama,代码行数:28,代码来源:Viewport.cs

示例2: GLHost_Initialized

        private void GLHost_Initialized(object sender, EventArgs e)
        {
            GLControl m_glControl;

            m_glControl = new GLControl(new GraphicsMode(32,24), 3, 0, GraphicsContextFlags.Default);
            m_glControl.MakeCurrent();
            m_glControl.Dock = System.Windows.Forms.DockStyle.Fill;
            m_glControl.AllowDrop = true;
            m_glControl.BackColor = System.Drawing.Color.Fuchsia;
            m_viewModel.CreateGraphicsContext(m_glControl, GLHost);

            GLHost.Child = m_glControl;
            GLHost.AllowDrop = true;
        }
开发者ID:Sage-of-Mirrors,项目名称:OpenTK-with-WPF-Tool-Framework,代码行数:14,代码来源:MainWindow.xaml.cs

示例3: Run

        public void Run()
        {
            using (Form form = CreateForm())
            {
                var mGLControl = new GLControl
                {
                    Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
                    BackColor = Color.LightGreen,
                    Location = new Point(1, 0),
                    Name = "GL Control",
                    Size = new Size(WIDTH, HEIGHT),
                    TabIndex = 0,
                    VSync = false
                };
                form.Controls.Add(mGLControl);

                //have to set this to get a -1 to 1 system view
                GL.Viewport(0, 0, WIDTH, HEIGHT);

                mPositions = new[]
                {
                    new Vector3(-1, -1, 0),
                    new Vector3(1, -1, 0),
                    new Vector3(1, 1, 0),
                    new Vector3(-1, 1, 0),
                };
                mColors = new[]
                {
                    Color.Red, Color.Green,
                    Color.Blue, Color.Yellow
                };

                Application.Idle +=
                    delegate
                    {
                        mGLControl.MakeCurrent();

                        GL.ClearColor(mGLControl.BackColor);
                        GL.Clear(ClearBufferMask.ColorBufferBit);

                        RenderFrame();

                        mGLControl.SwapBuffers();
                    };

                form.BringToFront();
                Application.Run(form);
            }
        }
开发者ID:Christof,项目名称:afterglow,代码行数:49,代码来源:SimpleQuad.cs

示例4: WindowsFormsHostInitialized

    private void WindowsFormsHostInitialized(object sender, EventArgs e)
    {
      var flags = GraphicsContextFlags.Default;
      _glControl = new GLControl(new GraphicsMode(32, 24), 2, 0, flags);
      _glControl.MakeCurrent();
      //_glControl.Paint += Paint;
      _glControl.MouseDown += OnMouseDown;
      _glControl.MouseUp += OnMouseUp;
      _glControl.MouseMove += OnMouseMove;
      _glControl.MouseWheel += OnMouseWheel;
      _glControl.Dock = DockStyle.Fill;
      (sender as WindowsFormsHost).Child = _glControl;

      _controller.Load();

      CompositionTarget.Rendering += Render;
    }
开发者ID:dgopena,项目名称:Starter3D.Base,代码行数:17,代码来源:OpenGLWindow.xaml.cs

示例5: Render

        public Render(string ModelPath)
        {
            dragX = 0.0f;
            dragY = 0.0f;
            dragZ = -7.5f;

            System.Windows.Forms.Integration.WindowsFormsHost wfc = MainWindow.winFormControl;

            ActiveCamera = new OldCamera((int)wfc.ActualWidth, (int)wfc.ActualHeight);
            ActiveCamera.Pos = new Vector3(10.0f, -10.0f, -7.5f);
            Console.WriteLine(ModelPath);

            if (ModelPath.EndsWith(".m2", StringComparison.OrdinalIgnoreCase))
            {
                modelLoaded = true;
                LoadM2(ModelPath);
            }
            else if (ModelPath.EndsWith(".wmo", StringComparison.OrdinalIgnoreCase))
            {
                modelLoaded = true;
                LoadWMO(ModelPath);
            }
            else
            {
                modelLoaded = false;
            }

            glControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), 3, 0, OpenTK.Graphics.GraphicsContextFlags.Default);
            glControl.Width = (int)wfc.ActualWidth;
            glControl.Height = (int)wfc.ActualHeight;
            glControl.Left = 0;
            glControl.Top = 0;
            glControl.Load += glControl_Load;
            glControl.Paint += RenderFrame;
            glControl.Resize += glControl_Resize;
               /*glControl.MouseMove += new MouseEventHandler(glControl_MouseMove);
            glControl.MouseDown += new MouseEventHandler(glControl_MouseDown);
            glControl.MouseUp += new MouseEventHandler(glControl_MouseUp);
            */
            glControl_Resize(glControl, EventArgs.Empty);
            glControl.MakeCurrent();

            wfc.Child = glControl;

            Console.WriteLine(glControl.Width + "x" + glControl.Height);
        }
开发者ID:rob3ns,项目名称:WoWFormatTest,代码行数:46,代码来源:Render.cs

示例6: winFormsHost_Initialized

        private void winFormsHost_Initialized(object sender, EventArgs e)
        {
            m_glControl = new GLControl(new GraphicsMode(32, 24), 3, 0, GraphicsContextFlags.Default);
            m_glControl.MakeCurrent();
            m_glControl.Paint += m_glControl_Paint;
            m_glControl.MouseDown += m_glControl_MouseDown;
            m_glControl.MouseUp += m_glControl_MouseUp;
            m_glControl.MouseWheel += m_glControl_MouseWheel;
            m_glControl.Dock = System.Windows.Forms.DockStyle.Fill;
            m_glControl.AllowDrop = true;
            m_glControl.DragEnter += m_glControl_DragEnter;
            m_glControl.DragLeave += m_glControl_DragLeave;
            m_glControl.BackColor = System.Drawing.Color.Black;
            m_viewModel.OnGraphicsContextInitialized(m_glControl, winFormsHost);

            winFormsHost.Child = m_glControl;
            winFormsHost.AllowDrop = true;
        }
开发者ID:CryZe,项目名称:WindEditor2,代码行数:18,代码来源:MainWindow.xaml.cs

示例7: Render

        public Render(string ModelPath, BackgroundWorker worker = null)
        {
            dragX = 0.0f;
            dragY = 0.0f;
            dragZ = 0.0f;

            if (worker == null)
            {
                Console.WriteLine("Didn't get a backgroundworker, creating one!");
                this.worker = new BackgroundWorker();
            }
            else
            {
                this.worker = worker;
            }

            filename = ModelPath;

            System.Windows.Forms.Integration.WindowsFormsHost wfc = MainWindow.winFormControl;

            ActiveCamera = new OldCamera((int)wfc.ActualWidth, (int)wfc.ActualHeight);
            ActiveCamera.Pos = new Vector3(-15.0f, 0.0f, 4.0f);

            if (filename.EndsWith(".m2"))
            {
                M2Loader.LoadM2(filename, cache);

                ActiveCamera.Pos = new Vector3(-15.0f, 0.0f, 4.0f);

                // The next few hackfixes can be removed once WMOs are done as well
                renderbatches = cache.doodadBatches[filename].submeshes;
                materials = cache.doodadBatches[filename].mats;

                VBOid = new uint[2];

                VBOid[0] = (uint)cache.doodadBatches[filename].vertexBuffer;
                VBOid[1] = (uint)cache.doodadBatches[filename].indiceBuffer;

                gLoaded = true;
            }
            else if (filename.EndsWith(".wmo"))
            {
                WMOLoader.LoadWMO(filename, cache);
                
                //TODO

                //gLoaded = true;
                isWMO = true;
            }

            glControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), 3, 0, OpenTK.Graphics.GraphicsContextFlags.Default);
            glControl.Width = (int)wfc.ActualWidth;
            glControl.Height = (int)wfc.ActualHeight;
            glControl.Left = 0;
            glControl.Top = 0;
            glControl.Load += glControl_Load;
            glControl.Paint += RenderFrame;
            glControl.MouseEnter += glControl_MouseEnter;
            glControl.MouseLeave += glControl_MouseLeave;
            glControl.Resize += glControl_Resize;
            glControl.MakeCurrent();
            glControl.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left;

            sw.Start();

            spentTime = 0.00;

            wfc.Child = glControl;
        }
开发者ID:Ser0ja,项目名称:WoWFormatTest,代码行数:69,代码来源:Render.cs

示例8: Render

        public void Render(int width, int height, GLControl glControl, float renderingStep)
        {
            if (!glControl.Context.IsCurrent)
                glControl.MakeCurrent();

            #region First run - FBO setup

            if (firstRun == true)
            {
                // this.Setup( glControl.Width, glControl.Height );
                this.Setup(555, 555);
                // mWidthOld = width;
                // mHeightOld = height;
                mOpenglControl = glControl;

                firstRun = false;
            }

            #endregion

            #region Resolution change detection

            //if((width != mWidthOld) || (height != mHeightOld)) {
            //    mBackSide.ChangeResolution( width, height, TextureUnit.Texture0, "back" );
            //    mFrontSide.ChangeResolution( width, height, TextureUnit.Texture1, "front" );
            //}

            #endregion

            #region OpenGL states setup

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Texture3DExt);

            #endregion

            #region Projection Setup

            GL.Viewport(0, 0,555, 555); // Use all of the glControl painting area
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            float x = (float)width / height;
            //GL.Ortho( -x, x, -1.0, 1.0, 0.0, 5.0 );
            //GL.Ortho( -0.7, 0.7, -0.7, 0.7, 0, 5 );
            //GL.Ortho(-x,x,-x,x, -50, 50);
            GL.Ortho(-1.50, 1.50, -1.50, 1.50, -5, 10);
            //GL.Frustum(-50, 50, -50, 50, -1, 100);

            //GL.Ortho( 0, width, 0, height, -1, 1 ); // Bottom-left corner pixel has coordinate (0, 0)
            //GL.Viewport( 0, 0, width, height );
            //GL.Viewport( 0, 0, 222,222 );

            #endregion

            #region Cube scene preparation

            SetOrientation();

            #endregion

            #region Render Cube Back Side to FBO

            GL.FrontFace(FrontFaceDirection.Cw);
            //GL.ActiveTexture( TextureUnit.Texture0 );
            //FrameBufferObject backSide  = new FrameBufferObject( width, height, TextureUnit.Texture0,"back" );
            mBackSide.Attach();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            DrawCube();
            mBackSide.Save("back.bmp");
            mBackSide.Detach();

            #endregion

            #region Render Cube Front Side to FBO

            GL.FrontFace(FrontFaceDirection.Ccw);
            //FrameBufferObject frontSide = new FrameBufferObject( width, height, TextureUnit.Texture1, "front" );
            mFrontSide.Attach();
            //GL.ActiveTexture( TextureUnit.Texture1 );
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            DrawCube();
            //mFrontSide.Save( "front.bmp" );
            mFrontSide.Detach();
            #endregion

            #region Prepare scene for Fullscreen textured rectangle - changed by GLSL shader

            GL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.LoadIdentity();
            GL.Translate(-3.0 * width / height / 2, -3.0 / 2, 0.0);
            GL.Disable(EnableCap.CullFace);

            #endregion

            #region Setup/Release GLSL Program & setup uniform values, setup textures to textureUnits

//.........这里部分代码省略.........
开发者ID:msup,项目名称:RayEngine,代码行数:101,代码来源:RayCaster.cs

示例9: Canvas_Load

        private void Canvas_Load(object sender, EventArgs e)
        {
            glGraphics = GL_GRAPHICS;
            glGraphics.MakeCurrent();

            bkgColor = Color.White;

            //GLControl's load event is never fired, so we have to piggyback off the canvas's load function instead
            GLLoaded = true;

            //If you are going to be resizing the canvas later or changing the background color,
            //make sure to re-do these so the GLControl will work properly
            GL_HEIGHT = GL_GRAPHICS.Height;
            GL_WIDTH = GL_GRAPHICS.Width;
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Viewport(0, 0, GL_WIDTH, GL_HEIGHT);
            GL.Ortho(0, GL_WIDTH, 0, GL_HEIGHT, -1, 1);
            GL.ClearColor(bkgColor);

            //Since we are 2d, we don't need the depth test
            GL.Disable(EnableCap.DepthTest);

            #region Shader Initialization Stuff

            try
            {
                GL.GenFramebuffers(1, out OccluderFBO);
            }
            catch (Exception x)
            {
                Console.WriteLine("Shader Initialization failed! We can't have shaders.. :C");
                MessageBox.Show("Shader initialization failed with reason: " + x.Message + ", Sorry, but shadows have been disabled. Light object is still usable, but you won't be able to see the result on your machine.", "Shader problem!");
                Program.ToolboxForm.ckb_renderShadows.Enabled = false;
                ShadersCanLoad = false;
            }

            if (ShadersCanLoad)
            {
                Program.ToolboxForm.ckb_renderShadows.Enabled = true;

                //We need to generate a texture here so we can write what we're drawing to the FBO, and then we can sample it with a shader
                GL.GenTextures(1, out OccludersTexture);
                GL.BindTexture(TextureTarget.Texture2D, OccludersTexture);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);

                //make it the size of our lights
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)lightSize, (int)lightSize, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

                //This texture will be used with the shadowMap
                GL.GenTextures(1, out ShadowsTexture);
                GL.BindTexture(TextureTarget.Texture2D, ShadowsTexture);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
                //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)lightSize, 1, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

                GL.BindTexture(TextureTarget.Texture2D, 0);

                //Generate a FBO for writing to the sampling texture

                // GL.GenFramebuffers(1, out OccluderFBO);
                //Moved to the beginning of the shader init

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, OccluderFBO);
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, OccludersTexture, 0);

                DrawBuffersEnum[] buf = new DrawBuffersEnum[1] { (DrawBuffersEnum)FramebufferAttachment.ColorAttachment0 };
                GL.DrawBuffers(buf.Length, buf);

                //and for our shadowMap, which is going to be 1xlightSize...

                GL.GenFramebuffers(1, out ShadowsFBO);

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, ShadowsFBO);
                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, ShadowsTexture, 0);

                DrawBuffersEnum[] bufferEnum = new DrawBuffersEnum[1] { (DrawBuffersEnum)FramebufferAttachment.ColorAttachment0 };
                GL.DrawBuffers(bufferEnum.Length, bufferEnum);

                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

                //Create our shaders for drawing shadows
                Shader_pass = GL.CreateShader(ShaderType.VertexShader);
                Shader_shadowMap = GL.CreateShader(ShaderType.FragmentShader);
                Shader_shadowRender = GL.CreateShader(ShaderType.FragmentShader);

                Program_passAndMap = GL.CreateProgram();
                Program_passAndRender = GL.CreateProgram();

                //pass will fill in the needed variables that are not accessable in fragment shaders (but only in vertex shaders)
                //uniforms: u_projTrans
                GL.ShaderSource(Shader_pass, readShader("pass_vert.glsl"));
                GL.CompileShader(Shader_pass);

//.........这里部分代码省略.........
开发者ID:Aearnus,项目名称:TISFAT-Zero,代码行数:101,代码来源:Canvas.cs

示例10: Run

        public void Run()
        {
            using (Form form = CreateForm())
            {
                var mGLControl = new GLControl
                {
                    Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
                    BackColor = Color.LightGreen,
                    Location = new Point(1, 0),
                    Name = "GL Control",
                    Size = new Size(WIDTH, HEIGHT),
                    TabIndex = 0,
                    VSync = false
                };
                form.Controls.Add(mGLControl);

                //have to set this to get a -1 to 1 system view
                GL.Viewport(0, 0, WIDTH, HEIGHT);

                if (false)//!GL.SupportsExtension("VERSION_1_5"))
                {
                    Assert.Fail("You need at least OpenGL 1.5 to run this example. Aborting.", "VBOs not supported");
                }

                var positions = new[]
                {
                    new Vector3(-1, -1, 0),
                    new Vector3(1, -1, 0),
                    new Vector3(1, 1, 0),
                    new Vector3(-1, 1, 0),
                };
                var colors = new[]
                {
                    new Vector3(1, 0, 0), new Vector3(0, 1, 0),
                    new Vector3(0, 0, 1), new Vector3(1, 1, 0)
                };

                var indices = new uint[] { 0, 1, 2, 0, 2, 3 };

                LoadBuffers(positions, indices, colors);

                Application.Idle +=
                    delegate
                    {
                        mGLControl.MakeCurrent();

                        GL.ClearColor(mGLControl.BackColor);
                        GL.Clear(ClearBufferMask.ColorBufferBit);

                        RenderFrame();

                        mGLControl.SwapBuffers();
                    };

                form.BringToFront();
                Application.Run(form);
            }
        }
开发者ID:Christof,项目名称:afterglow,代码行数:58,代码来源:QuadWithBuffers.cs

示例11: LoadROM

        /// <summary>
        /// Defines the control that renders the game and initializes
        /// all video related objects.
        /// </summary>
        /// <param name="ctrl">A reference to the GLControl renderer.</param>
        public static void LoadROM(ref byte[] romBuffer, ref GLControl ctrl)
        {
            _control = ctrl;

            IsColorGameBoy = GBCEmulator.IsColorGameBoy;

            _vram = new byte[8192];
            _oam = new byte[160];
            Buffer.BlockCopy(romBuffer, 0x8000, _vram, 0, 8192);
            Buffer.BlockCopy(romBuffer, 0xFE00, _oam, 0, 160);

            STAT = 0;
            ModeFlag = (byte)ModeFlags.OAM;
            LYC = 0;
            SCX = 0;
            SCY = 0;
            WX = 0;
            WY = 0;

            // Graphics initialization
            _pixelBuffer = new byte[160,144,3];
            ctrl.MakeCurrent(); // Make it current for OpenGL
            GL.ClearColor(Color.White);
            ctrl.Invalidate();
        }
开发者ID:Warpten,项目名称:mzmdbg,代码行数:30,代码来源:GPU.cs

示例12: WindowsFormsHost_Initialized

        private void WindowsFormsHost_Initialized(object sender, EventArgs e)
        {
            var flags = GraphicsContextFlags.Default;

            glControl = new GLControl(new GraphicsMode(32, 24), 2, 0, flags);

            glControl.MakeCurrent();

            glControl.Paint += Render;

            glControl.Dock = DockStyle.Fill;

            (sender as WindowsFormsHost).Child = glControl;
        }
开发者ID:Zargess,项目名称:OpenGL-Projects,代码行数:14,代码来源:MainWindow.xaml.cs


注:本文中的OpenTK.GLControl.MakeCurrent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。