MakeCurrent() public method

Makes the underlying this GLControl current in the calling thread. All OpenGL commands issued are hereafter interpreted by this GLControl.
public MakeCurrent ( ) : void
return void
        public static void InitializeSharedResources()
        {
            // Only setup once. This is checked multiple times to prevent crashes.
            if (setupStatus == SharedResourceStatus.Initialized)
            {
                return;
            }

            try
            {
                // Make a permanent context to share resources.
                GraphicsContext.ShareContexts = true;
                var control = new OpenTK.GLControl();
                control.MakeCurrent();

                RenderTools.LoadTextures();
                GetOpenGLSystemInfo();
                ShaderTools.SetUpShaders();

                setupStatus = SharedResourceStatus.Initialized;
            }
            catch (AccessViolationException)
            {
                // Context creation failed.
                setupStatus = SharedResourceStatus.Failed;
            }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            if (!glContextCreated)
            {
                return; //can't do anything with this, heh
            }
            if (nudElementNum.Value < 0)
            {
                return;
            }

            if (datafile.replacedModels.Count == 0)
            {
                return; //can't do anything with no models.
            }
            glControl1.MakeCurrent();

            modelRenderer.Pitch = (trackBar3.Value - 8) * -22.5d;
            modelRenderer.Angle = (trackBar1.Value - 8) * -22.5d;
            //modelRenderer.ShowBBs = chkShowBBs.Checked;
            //modelRenderer.ShowNormals = chkNorm.Checked;
            //modelRenderer.Wireframe = chkWireframe.Checked;
            //modelRenderer.ShowRadius = chkRadius.Checked;

            modelRenderer.Draw();
            glControl1.SwapBuffers();
        }
Ejemplo n.º 4
0
        private void glControl1_Paint(object sender, PaintEventArgs e)
        {
            if (!glContextCreated)
            {
                return; //can't do anything with this, heh
            }
            glControl1.MakeCurrent();
            renderer.Pitch           = (trackBar2.Value - 8) * -22.5d;
            renderer.Angle           = (trackBar1.Value - 8) * -22.5d;
            renderer.ShowBBs         = chkShowBBs.Checked;
            renderer.ShowNormals     = chkNorm.Checked;
            renderer.Wireframe       = chkWireframe.Checked;
            renderer.ShowRadius      = chkRadius.Checked;
            renderer.EmulateSoftware = chkSoftwareOverdraw.Checked;
            if (chkAnimation.Checked)
            {
                renderer.Frame = (int)numericUpDown1.Value;
            }
            else
            {
                renderer.Frame = -1;
            }

            renderer.Draw();

            glControl1.SwapBuffers();
        }
        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;
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
    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;
    }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
        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;
        }
Ejemplo n.º 11
0
        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

            // Draw fullscreen textured rectangle

            // Activate 3D texture
            GL.ActiveTexture(TextureUnit.Texture2);
            this.mVolumeTexture.Bind();

            GL.ActiveTexture(TextureUnit.Texture3);
            this.mClassificationTexture.Bind();

            GL.ActiveTexture(TextureUnit.Texture4);
            this.mClassificationTexture.Bind_zDistance();

            this.ShaderPrograms[0].Use();
            ShaderPrograms[0].SetUniform1("backBuffer", 0);
            ShaderPrograms[0].SetUniform1("frontBuffer", 1);

            //renderingStep = 0.001f;

            foreach (var shaderAlgorithmParameter in mRenderingParameters)
            {
                if (shaderAlgorithmParameter.Value.GetType().Name == typeof(Vector3).Name)
                {
                    ShaderPrograms[0].SetUniform3(
                                         shaderAlgorithmParameter.Key.ToString(),
                                         (Vector3)shaderAlgorithmParameter.Value);
                }
                else
                {
                    ShaderPrograms[0].SetUniform1(
                                        shaderAlgorithmParameter.Key.ToString(),
                                        (float)shaderAlgorithmParameter.Value);
                }
            }

            //ShaderPrograms[0].SetUniform3( RenderingParameter.AmbientLightColor.ToString(),
            //                               (Vector3) mRenderingParameters[RenderingParameter.AmbientLightColor] );

            ShaderPrograms[0].SetUniform1("delta", renderingStep);
            ShaderPrograms[0].SetUniform1("color_text", 3);
            ShaderPrograms[0].SetUniform1("z_distance_texture", 4);

            ////DrawCube();
            mFrontSide.BindTextureToTextureUnit();
            mBackSide.BindTextureToTextureUnit();

            if (offline_render)
            {
                mTempFBO.Attach();
            }

            FullScreenArea(111, 111);
            //       FullScreenArea( width, height );

            ShaderPrograms[0].SetUniform1("volume", 2);
            GL.UseProgram(0);

            if (offline_render)
            {
                counter++;
                string fbo_bitmap_str = String.Format("{0}-fbo_save.bmp", counter);
                mTempFBO.Save(fbo_bitmap_str);
                mTempFBO.Detach();
            }

            GL.ActiveTexture(TextureUnit.Texture2);
            this.mVolumeTexture.Unbind();

            GL.ActiveTexture(TextureUnit.Texture3);
            this.mClassificationTexture.Unbind();

            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.ActiveTexture(TextureUnit.Texture3);
            GL.BindTexture(TextureTarget.Texture1D, 0);

            GL.ActiveTexture(TextureUnit.Texture4);
            GL.BindTexture(TextureTarget.Texture1D, 0);

            #endregion

            #region remove
            //GL.Viewport( 0, 0, 400, 400); // Use all of the glControl painting area
            //GL.MatrixMode( MatrixMode.Projection );
            //GL.LoadIdentity();
            //GL.Ortho( -1, 1, -1, 1, -50, 50 );
            //////FullScreenArea( width, height );

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

            //GL.PushMatrix();
            //GL.LoadIdentity();
            ////GL.Translate( 0.5, 0.5, 0 );
            ////GL.Rotate( angle, 1, 1, 0 );

            //GL.ClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
            //GL.Clear( ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit );
            //GL.ActiveTexture( TextureUnit.Texture0 );
            //GL.BindTexture( TextureTarget.Texture2D, mTempFBO.mFboTexture );

            //GL.Begin( BeginMode.Quads );
            //GL.Color4( 1.0, 1.0, 1.0, 1.0); // fixme:: jeden pes je zakopany aj tu

            ////GL.Vertex3( 0.1, 0.31, 0.0 );
            ////GL.Vertex3( -0.13, 0.21, 0.0 );
            ////GL.Vertex3( 0.23, 0.81, -0.0 );

            //GL.TexCoord2( 0.0, 0.0 ); GL.Vertex2( 0.0, 0.0 );
            //GL.TexCoord2( 1.0, 0.0 ); GL.Vertex2( 1.0, 0.0 );
            //GL.TexCoord2( 1.0, 1.0 ); GL.Vertex2( 1.0, 1.0 );
            //GL.TexCoord2( 0.0, 1.0 ); GL.Vertex2( 0.0, 1.0 );

            //GL.End();
            //GL.BindTexture( TextureTarget.Texture2D, 0 );

            ////GL.Disable( EnableCap.Blend );
            //GL.PopMatrix();

            #endregion

            mWidthOld = width;
            mHeightOld = height;
        }
Ejemplo n.º 12
0
        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);

                int status;
                GL.GetShader(Shader_pass, ShaderParameter.CompileStatus, out status);

                if (status != 1)
                    Console.WriteLine("Shader_pass failed to compile:\n" + GL.GetShaderInfoLog(Shader_pass));

                //shadowMap will "map" the shadows onto a 1D texture
                //uniforms: u_texture, resolution
                GL.ShaderSource(Shader_shadowMap, readShader("shadowMap_frag.glsl"));
                GL.CompileShader(Shader_shadowMap);

                GL.GetShader(Shader_shadowMap, ShaderParameter.CompileStatus, out status);

                if (status != 1)
                    Console.WriteLine("Shader_shadowMap failed to compile:\n" + GL.GetShaderInfoLog(Shader_shadowMap));

                //and finally, shadowRender will take this map and render it onto the screen
                //uniforms: u_texture, resolution, softShadows
                GL.ShaderSource(Shader_shadowRender, readShader("shadowRender_frag.glsl"));
                GL.CompileShader(Shader_shadowRender);

                GL.GetShader(Shader_shadowRender, ShaderParameter.CompileStatus, out status);

                if (status != 1)
                    Console.WriteLine("Shader_shadowRender failed to compile:\n" + GL.GetShaderInfoLog(Shader_shadowRender));

                GL.AttachShader(Program_passAndMap, Shader_pass);
                GL.AttachShader(Program_passAndMap, Shader_shadowMap);

                GL.AttachShader(Program_passAndRender, Shader_pass);
                GL.AttachShader(Program_passAndRender, Shader_shadowRender);

                GL.LinkProgram(Program_passAndMap);
                GL.LinkProgram(Program_passAndRender);
            }
            #endregion

            Program.TimelineForm.addStickLayer("Stick Layer 1");
        }
        //static int numPoints = 0;

        public drawing.Bitmap ParseSqlGeometry(List <SqlGeometry> geometries, double width, double height, Func <Point, Point> transform, drawing.Pen pen, drawing.Brush brush)//, ImageSource pointSymbol = null, Geometry symbol = null)
        {
            //if (width + height > 5000)
            //{
            //    throw new NotImplementedException();
            //}

            gl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 8, 4));
            gl.MakeCurrent();

            //Debug.Print("ParseSqlGeometry started");
            //numPoints = 0;

            gl.Width = (int)width; gl.Height = (int)height;

            GL.Enable(EnableCap.PointSmooth);
            GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
            //GL.Enable(EnableCap.LineSmooth);
            //GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);

            //GL.Disable(EnableCap.Texture2D);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0, width, 0, height, -1, 1);       // Bottom-left corner pixel has coordinate (0, 0)
            GL.Viewport(0, 0, (int)width, (int)height); // Use all of the glControl painting area

            GL.ClearColor(drawing.Color.Transparent);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.Color3(pen.Color);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.PointSize(5f);
            GL.LineWidth(2f);
            //GL.Color4(System.Drawing.Color.LightBlue);
            //GL.Enable(EnableCap.VertexArray);

            //OpenTKHelper.pen = pen;

            //OpenTKHelper.brush = brush;

            int p = 0;

            if (geometries != null)
            {
                foreach (SqlGeometry item in geometries)
                {
                    p += AddGeometry(item, transform);
                }
            }
            //***************
            //var image2 = GrabScreenshot((int)width, (int)height);

            //image2.Save(DateTime.Now.ToString("yyyy,MM,dd,hh,mm,ss") + ".png", drawing.Imaging.ImageFormat.Png);

            //image2.Dispose();
            //**********
            GL.Finish();

            var result = GrabScreenshot();

            gl.Dispose();

            return(result);
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        /// <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();
        }
Ejemplo n.º 16
0
        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;
        }