Example #1
0
        private void RenderControl_Render_GLSL(object sender, GlControlEventArgs e)
        {
            Control control = (Control)sender;

            PerspectiveProjectionMatrix projectionMatrix = new PerspectiveProjectionMatrix(45.0f, (float)control.Width / (float)control.Height, 0.1f, 100.0f);
            ModelMatrix viewMatrix  = new ModelMatrix();
            ModelMatrix modelMatrix = new ModelMatrix();

            modelMatrix.Translate(new Vertex3f(modelPosition.X, modelPosition.Y, modelPosition.Z));
            modelMatrix.Scale(new Vertex3f(0.2f, 0.2f, 0.2f));

            Gl.Viewport(0, 0, control.Width, control.Height);
            Gl.ClearColor(0.05f, 0.05f, 0.05f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            modelShader.Use();
            modelMatrix.RotateX(modelAngle.X);
            modelMatrix.RotateY(modelAngle.Y);
            modelMatrix.RotateZ(modelAngle.Z);
            //viewMatrix.Translate(new Vertex3f(-2.0f * (float)Math.Sin(modelAngle.Y * PI_OVER_180), 0.0f, -2.0f*(float)Math.Cos(modelAngle.Y*PI_OVER_180)));
            Gl.UniformMatrix4(modelShader.uLocation_Projection, 1, false, projectionMatrix.ToArray());
            Gl.UniformMatrix4(modelShader.uLocation_View, 1, false, viewMatrix.ToArray());
            Gl.UniformMatrix4(modelShader.uLocation_Model, 1, false, modelMatrix.ToArray());

            modelNanosuit.Draw(modelShader);
        }
Example #2
0
        void glControl_Render(object sender, GlControlEventArgs e)
        {
            var time   = sw.ElapsedMilliseconds / 1000.0F;
            var sz     = ClientSize;
            var width  = (float)sz.Width;
            var height = (float)sz.Height;

            Control senderControl = (Control)sender;

            Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            switch (Gl.CurrentVersion.Api)
            {
            case KhronosVersion.ApiGl:
                if (Gl.CurrentVersion >= Gl.Version_320)
                {
                    RenderControl_RenderGL320(time, width, height);
                }
                else if (Gl.CurrentVersion >= Gl.Version_110)
                {
                    RenderControl_RenderGL110(time, width, height);
                }
                else
                {
                    RenderControl_RenderGL100(time, width, height);
                }
                break;

            case KhronosVersion.ApiGles2:
                RenderControl_RenderGLES2(time, width, height);
                break;
            }
        }
Example #3
0
        /// <summary>
        /// Update framebuffer.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_Render(object sender, GlControlEventArgs e)
        {
            GlControl senderControl     = (GlControl)sender;
            float     senderAspectRatio = (float)senderControl.Width / senderControl.Height;

            // Clear
            Gl.Viewport(0, 0, senderControl.Width, senderControl.Height);
            Gl.ClearColor(1.0f, 0.0f, 0.0f, 1.0f);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _CubeScene.CurrentView.ProjectionMatrix = Matrix4x4f.Perspective(45.0f, senderAspectRatio, 0.1f, 100.0f);
            // _CubeScene.CurrentView.LocalModelView = Matrix4x4f.Translated(0.0f, 0.0f, 10.0f);
            //_CubeScene.CurrentView.LocalModelView =
            //	Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f) *
            //	Matrix4x4f.RotatedY(_ViewAzimuth) *
            //	Matrix4x4f.RotatedX(_ViewElevation) *
            //	Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever);
            //_CubeScene.CurrentView.LocalModelView =
            //	Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever) *
            //	Matrix4x4f.RotatedX(_ViewElevation) *
            //	Matrix4x4f.RotatedY(_ViewAzimuth) *
            //	Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f);
            _CubeScene.UpdateViewMatrix();

            _CubeScene.Draw(_Context);
        }
Example #4
0
        private void RenderControl_Render_ES(object sender, GlControlEventArgs e)
        {
            Control control = (Control)sender;
            OrthoProjectionMatrix projectionMatrix = new OrthoProjectionMatrix(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
            ModelMatrix           modelMatrix      = new ModelMatrix();

            // Animate triangle
            modelMatrix.RotateZ(_Angle);

            Gl.Viewport(0, 0, control.Width, control.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            Gl.UseProgram(_Es2_Program);

            using (MemoryLock arrayPosition = new MemoryLock(_ArrayPosition))
                using (MemoryLock arrayColor = new MemoryLock(_ArrayColor))
                {
                    Gl.VertexAttribPointer((uint)_Es2_Program_Location_aPosition, 2, VertexAttribType.Float, false, 0, arrayPosition.Address);
                    Gl.EnableVertexAttribArray((uint)_Es2_Program_Location_aPosition);

                    Gl.VertexAttribPointer((uint)_Es2_Program_Location_aColor, 3, VertexAttribType.Float, false, 0, arrayColor.Address);
                    Gl.EnableVertexAttribArray((uint)_Es2_Program_Location_aColor);

                    Gl.UniformMatrix4(_Es2_Program_Location_uMVP, false, (projectionMatrix * modelMatrix).ToArray());

                    Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                }
        }
Example #5
0
        private void glControl_Render(object sender, GlControlEventArgs e)
        {
            try {
                Gl.VertexPointer(2, VertexPointerType.Float, 0, ArrayPosition);
                Gl.EnableClientState(EnableCap.VertexArray);
                Gl.TexCoordPointer(2, TexCoordPointerType.Float, 0, ArrayTexCoord);
                Gl.EnableClientState(EnableCap.TextureCoordArray);

                var control = sender as Control;
                Gl.Viewport(0, 0, control.ClientSize.Width, control.ClientSize.Height);
                Gl.Clear(ClearBufferMask.ColorBufferBit);
                Gl.BindTexture(TextureTarget.Texture2d, texture);

                if (Gl.CurrentVersion >= Gl.Version_110)
                {
                    Gl.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
                }
                else
                {
                    Gl.Begin(PrimitiveType.TriangleStrip);
                    for (var i = 0; i < ArrayPosition.Length; i += 2)
                    {
                        Gl.TexCoord2(ArrayTexCoord[i], ArrayTexCoord[i + 1]);
                        Gl.Vertex2(ArrayPosition[i], ArrayPosition[i + 1]);
                    }
                    Gl.End();
                }
            }
            catch {
            }
        }
Example #6
0
        private void Render(object sender, GlControlEventArgs e)
        {
            if (_shader == null)
            {
                return;
            }
            Gl.Clear(ClearBufferMask.DepthBufferBit);

            var v = _cameraHelper.CameraMatrix;

            _shader.M = v;

            _shader.ShadingLevel = 0;
            FiguresHelper.Draw3DCross(10, 1);
            _shader.ShadingLevel = 1;

            var qIntern = Quaternion.Slerp(qStart, qEnd, _t);

            _t += _dt;

            var m = Matrix4x4.CreateFromQuaternion(qIntern) * Matrix4x4.CreateTranslation(_x, 0, 0) * v;

            _shader.M = m;

            _quad.Draw(0.8f, 0.5f, 1.6f, true);

            _x += _dx;
        }
Example #7
0
        private void RenderControl_Render(object sender, GlControlEventArgs e)
        {
            // Common GL commands
            Control senderControl = (Control)sender;

            Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            switch (Gl.CurrentVersion.Api)
            {
            case KhronosVersion.ApiGl:
                if (Gl.CurrentVersion >= Gl.Version_320)
                {
                    RenderControl_RenderGL320();
                }
                else if (Gl.CurrentVersion >= Gl.Version_110)
                {
                    RenderControl_RenderGL110();
                }
                else
                {
                    RenderControl_RenderGL100();
                }
                break;

            case KhronosVersion.ApiGles2:
                RenderControl_RenderGLES2();
                break;
            }
        }
Example #8
0
        private void Render(object sender, GlControlEventArgs e)
        {
            if (_shader == null)
            {
                return;
            }

            Gl.Clear(ClearBufferMask.DepthBufferBit);
            Gl.MatrixMode(MatrixMode.Modelview);

            var v = _cameraHelper.CameraMatrix;
            var u = Matrix4x4.CreateRotationX(Mathf.ToRadian(90));

            var m = u * v;

            _shader.M = m;

            FiguresHelper.Draw3DCross(50f, 1f);

            Figure3DHelper.DrawSphere(15, 20, 20, true, Colors.Yellow);
            Gl.LineWidth(1);
            Figure3DHelper.DrawSphere(15, 20, 20, false, Colors.Red);

            _satelite.Draw();
        }
Example #9
0
        /// <summary>
        /// Allocate GL resources or GL states.
        /// </summary>
        /// <param name="sender">
        /// The <see cref="object"/> that has rasied the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="GlControlEventArgs"/> that specifies the event arguments.
        /// </param>
        private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            GlControl glControl = (GlControl)sender;

            // Allocate resources and/or setup GL states
            switch (Gl.CurrentVersion.Api)
            {
            case KhronosVersion.ApiGl:
                if (Gl.CurrentVersion >= Gl.Version_320)
                {
                    RenderControl_CreateGL320();
                }
                else
                {
                    RenderControl_CreateGL100();
                }
                break;

            case KhronosVersion.ApiGles2:
                RenderControl_CreateGLES2();
                break;
            }

            // Uses multisampling, if available
            if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0)
            {
                Gl.Enable(EnableCap.Multisample);
            }
        }
Example #10
0
        private void GLCanvas_ContextCreated(object sender, GlControlEventArgs e)
        {
            // Here you can allocate resources Or initialize state
            Gl.MatrixMode(MatrixMode.Projection);
            Gl.LoadIdentity();
            Gl.Ortho(0.0, 1.0F, 0.0, 1.0, 0.0, 1.0);

            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();

            Gl.Enable(EnableCap.DepthTest);

            Console.WriteLine(MESSAGE_GL_CONTEXT_CREATED);

            ShadersManager.Instance.ReloadShaders();

            cube1       = new Cube();
            cube1.Name  = "CUBE1";
            cube1.Scale = new XNA.Vector3(1.5f, 1.5f, 1.5f);

            Scene.CurrentScene.AddSceneObject(cube1);

            ResetCamera();

            AddDefaultLights();
        }
Example #11
0
        private void GlControlOnRender(object?sender, GlControlEventArgs e)
        {
            var senderControl = sender as GlControl;

            int vpx = 0;
            int vpy = 0;
            int vpw = senderControl?.ClientSize.Width ?? 1;
            int vph = senderControl?.ClientSize.Height ?? 1;

            Gl.Viewport(vpx, vpy, vpw, vph);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            var projectionMatrix = _openGLCamera.ProjectionMatrix(vpw, vph);
            var viewMatrix       = _openGLCamera.ViewMatrix;

            Gl.UseProgram(_program);

            var u = Uniforms.Get(_program);

            foreach (var meshEntry in _meshes.Where(m => m.Enabled))
            {
                var modelMatrix = meshEntry.GLMesh.ModelMatrix;
                Gl.UniformMatrix4f(u.M, 1, true, modelMatrix);
                Gl.UniformMatrix4f(u.P, 1, true, projectionMatrix);
                Gl.UniformMatrix4f(u.V, 1, true, viewMatrix);
                Gl.Uniform3f(u.LightPosition, 1, CameraLight?.Position ?? new Vector3(-50, 200, 50));
                Gl.Uniform1f(u.LightPower, 1, _settingsViewModel.LightStrength);
                Gl.Uniform1f(u.LightPower, 1, _settingsViewModel.LightStrength);
                Gl.Uniform1f(u.Ambient, 1, _settingsViewModel.Ambient);
                Gl.Uniform1f(u.SpecularStrength, 1, _settingsViewModel.SpecularMapStrength);

                meshEntry.GLMesh.Render(u);
            }
        }
Example #12
0
        private void Render(object sender, GlControlEventArgs e)
        {
            if (_shader == null)
            {
                return;
            }

            var v = _cameraHelper.CameraMatrix;

            _shader.M = v;

            _shader.ShadingLevel = 0;
            FiguresHelper.Draw3DCross(4, 1);
            _shader.ShadingLevel = 1;

            _shader.LightPos = new Vector3(1f, 1f, 1f);

            var r1     = Matrix4x4.CreateRotationY(Mathf.ToRadian(_phi));
            var t      = Matrix4x4.CreateTranslation(new Vector3(_radius, 2f, 0f));
            var r2     = Matrix4x4.CreateRotationX(Mathf.ToRadian(90)) * Matrix4x4.CreateRotationY(Mathf.ToRadian(90)) * Matrix4x4.CreateRotationZ(Mathf.ToRadian(45));
            var scaleM = Matrix4x4.CreateScale(0.2f);
            var r3     = Matrix4x4.CreateRotationY(Mathf.ToRadian(-_phi * 10));
            var r4     = Matrix4x4.CreateRotationZ(Mathf.ToRadian(25));
            var m      = r3 * r2 * t * r1 * scaleM * r4;

            _shader.M = m * v;

            Figure3DHelper.DrawMesh(_boomerang, Colors.Chocolate);

            _phi += _step;
        }
Example #13
0
        private void Render(object sender, GlControlEventArgs glControlEventArgs)
        {
            var center = Vector2.Zero;

            DrawCircle(center, A1, A2, W1, W2, _phi);
            _phi = (_phi + 0.1f) % 360;
        }
Example #14
0
        /// <summary>
        /// Allocate resources for rendering.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            // Wrap GL context with GraphicsContext
            _Context = new GraphicsContext(e.DeviceContext, e.RenderContext);

            // Scene
            _CubeScene = new SceneGraph(SceneGraphFlags.None)
            {
                SceneRoot   = new SceneObjectGeometry(),
                CurrentView = new SceneObjectCamera()
            };

            // Root object
            // _CubeScene.SceneRoot.ObjectState.DefineState(new DepthTestState(DepthFunction.Less));

            // Camera object
            _CubeScene.SceneRoot.Link(_CubeScene.CurrentView);

            // Horizontal plane
            _CubeScene.SceneRoot.Link(CreatePlane());

            // Create scene resource
            _CubeScene.Create(_Context);

            Gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);

            Gl.Enable(EnableCap.Multisample);
        }
Example #15
0
        /// <summary>
        /// Allocate GL resources or GL states.
        /// </summary>
        /// <param name="sender">
        /// The <see cref="object"/> that has rasied the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="GlControlEventArgs"/> that specifies the event arguments.
        /// </param>
        private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            GlControl glControl = (GlControl)sender;

            // GL Debugging
            if (Gl.CurrentExtensions != null && Gl.CurrentExtensions.DebugOutput_ARB)
            {
                Gl.DebugMessageCallback(GLDebugProc, IntPtr.Zero);
                Gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, null, true);
            }

            _renderer = _rendererFactory.Create(Gl.CurrentVersion);

            _renderer.Create();

            ContextCreated?.Invoke(sender, e);

            Gl.ClearColor(0.0f, 0.4f, 0.6f, 1.0f);

            // Uses multisampling, if available
            if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0)
            {
                Gl.Enable(EnableCap.Multisample);
            }
        }
Example #16
0
        private void GlControl_Render(object sender, GlControlEventArgs e)
        {
            Renderer.Prepare();

            var glsender = sender as GlControl;

            Renderer.AdjustDisplay(glsender.ClientSize.Width, glsender.ClientSize.Height);


            var path    = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var bmp     = new Bitmap(System.IO.Path.Combine(path, "map.png"));
            var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                       System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                       System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            uint textId = Gl.GenTexture();

            Gl.BindTexture(TextureTarget.Texture2d, textId);
            Gl.TexImage2D(TextureTarget.Texture2d, 0,
                          InternalFormat.Rgb8, bmp.Width, bmp.Height, 0, OpenGL.PixelFormat.Bgr, PixelType.UnsignedByte, bmpData.Scan0);
            Gl.Enable(EnableCap.Texture2d);
            Gl.Enable(EnableCap.TextureGenS);
            Gl.Enable(EnableCap.TextureGenT);

            bmp.UnlockBits(bmpData);


            Renderer.Render(Model);
        }
Example #17
0
        private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            GlControl glControl = (GlControl)sender;

            if (Gl.CurrentVersion.Api == KhronosVersion.ApiGles2)
            {
                RenderControl_ContextCreated_ES(sender, e);
            }
            else
            {
                // Here you can allocate resources or initialize state
                Gl.MatrixMode(MatrixMode.Projection);
                Gl.LoadIdentity();
                Gl.Ortho(0.0, 1.0f, 0.0, 1.0, 0.0, 1.0);

                Gl.MatrixMode(MatrixMode.Modelview);
                Gl.LoadIdentity();

                // Uses multisampling, if available
                if (glControl.MultisampleBits > 0)
                {
                    Gl.Enable(EnableCap.Multisample);
                }
            }
        }
Example #18
0
        private void glControl_Render(object sender, GlControlEventArgs e)
        {
            Control senderControl = (Control)sender;

            Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            _currentScene.Render(senderControl.ClientSize.Width, senderControl.ClientSize.Height, _light, _figureShaderProgram);
        }
Example #19
0
 private void OnDestroying_GlControl(object sender, GlControlEventArgs e)
 {
     this.displayManager.CloseDisplay();
     this.loader.CleanUp();
     this.renderer.CleanUp();
     this.guiRenderer.CleanUp();
     this.waterFrameBuffers.CleanUp();
 }
Example #20
0
 private void OnRender(object sender, GlControlEventArgs e)
 {
     Time.RestartMeasure();
     UpdateTimeValue.Text = $"{Time.DeltaTime}ms";
     Input.HandleInput();
     m_Game.OnUpdate();
     m_Game.RenderScene();
 }
Example #21
0
        private void GlControlOnContextCreated(object?sender, GlControlEventArgs e)
        {
            CreateShaders();

            Gl.Enable(EnableCap.DepthTest);
            Gl.DepthFunc(DepthFunction.Less);

            Gl.Enable(EnableCap.Multisample);
        }
Example #22
0
        private void OnCreated_GlControl(object sender, GlControlEventArgs e)
        {
            GlControl glControl = (GlControl)sender;

            this.displayManager.CreateDisplay(glControl);

            bool result = WrapSOIL.Initialize();

            if (result == false)
            {
                MessageBox.Show("SOIL: Failed initialize : " + WrapSOIL.GetSoilLastError());
                return;
            }

            this.loader = new Loader();
            //Camera
            this.camera = new Camera(new Vertex3f(0, 10, 0), 20f);

            //Light - Sun
            this.lgihtList = new List <Light>();
            this.sun       = new DirectionalLight(new Vertex3f(-0.5f, -1.5f, 0.5f), new Vertex3f(150, 250, -150), new Vertex3f(0.4f, 0.4f, 0.4f), new Vertex3f(1, 0, 0));
            this.lgihtList.Add(sun);

            //Renderer
            this.renderer    = new MasterRenderer(this.camera, this.loader, this.sun, glControl.ClientSize.Width, glControl.ClientSize.Height);
            this.guiRenderer = new GUIRenderer(this.loader);
            this.inputManager.OnEventMouseWheel += this.camera.OnEventWheel;

            //Water
            this.waterTileList = new List <WaterTile>();
            this.waterTileList.Add(new WaterTile(75, -75, WATER_HEIGHT));

            //Water
            this.waterFrameBuffers = new WaterFrameBuffers();
            this.waterShader       = new WaterShader();
            this.waterRenderer     = new WaterRenderer(loader, waterShader, this.renderer.ProjectionMatrix, this.waterFrameBuffers);


            //Load Resources
            this.entities = new List <Entity>();
            this.terrain  = LoadTerrain(this.loader);
            LoadEntities(this.terrain, this.entities, this.loader);
            LoadPlayer(this.loader, this.entities);

            //Light - Point

            this.lgihtList.Add(new Light(GetHeightPosition(this.terrain, 185, 12.7f, -293), new Vertex3f(2, 0, 0), new Vertex3f(1, 0.01f, 0.002f)));
            this.lgihtList.Add(new Light(GetHeightPosition(this.terrain, 370, 12.7f, -300), new Vertex3f(0, 2, 2), new Vertex3f(1, 0.01f, 0.002f)));
            this.lgihtList.Add(new Light(GetHeightPosition(this.terrain, 293, 12.7f, -305), new Vertex3f(2, 2, 0), new Vertex3f(1, 0.01f, 0.002f)));
            //LoadGUI(this.loader);
            //LoadGUI_Texture(this.loader, this.waterFrameBuffers.RefractionTexture);
            LoadGUI_Texture(this.loader, renderer.DepthMap);

            //MousePicker
            this.mousePicker = new MousePicker(this.camera, this.renderer.ProjectionMatrix, this.terrain);
        }
Example #23
0
        private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            // Here you can allocate resources or initialize state
            Gl.MatrixMode(MatrixMode.Projection);
            Gl.LoadIdentity();
            Gl.Ortho(0.0, 1.0f, 0.0, 1.0, 0.0, 1.0);

            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();
        }
 private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
 {
     lock (_drawLock)
     {
         _textureId = Gl.GenTexture();
         Gl.BindTexture(TextureTarget.Texture2d, _textureId);
         Gl.TextureParameterEXT(_textureId, TextureTarget.Texture2d, TextureParameterName.TextureMagFilter, Gl.NEAREST);
         Gl.TextureParameterEXT(_textureId, TextureTarget.Texture2d, TextureParameterName.TextureMinFilter, Gl.NEAREST);
     }
 }
Example #25
0
 private void RenderControl_Render(object sender, GlControlEventArgs e)
 {
     if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGles2)
     {
         RenderControl_Render_ES(sender, e);
     }
     else
     {
         RenderControl_Render_GL(sender, e);
     }
 }
Example #26
0
        /// <summary>
        /// Allocate resources for rendering.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ObjectsControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            // Wrap GL context with GraphicsContext
            _Context = new GraphicsContext(e.DeviceContext, e.RenderContext);
            // Create resources
            CreateResources(_Context);

            Gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);

            Gl.Enable(EnableCap.Multisample);
        }
Example #27
0
        private void Render(object sender, GlControlEventArgs e)
        {
            if (_shader == null)
            {
                return;
            }
            _shader.M = Matrix4x4.Identity;
            _shader.P = _cameraHelper.CameraMatrix;

            Quader.Draw(1, 1, 1, true);
        }
Example #28
0
        private void RenderControl_ContextCreated(object sender, GlControlEventArgs e)
        {
            // Update Form caption
            Text = String.Format("Hello triangle with ANGLE (Version: {0})", Gl.GetString(StringName.Version));

            // Create resources
            StringBuilder infolog = new StringBuilder(1024);
            int           infologLength;
            int           compiled;

            infolog.EnsureCapacity(1024);

            // Vertex shader
            uint vertexShader = Gl.CreateShader(ShaderType.VertexShader);

            Gl.ShaderSource(vertexShader, _Es2_ShaderVertexSource);
            Gl.CompileShader(vertexShader);
            Gl.GetShader(vertexShader, ShaderParameterName.CompileStatus, out compiled);
            if (compiled == 0)
            {
                Gl.GetShaderInfoLog(vertexShader, 1024, out infologLength, infolog);
            }

            // Fragment shader
            uint fragmentShader = Gl.CreateShader(ShaderType.FragmentShader);

            Gl.ShaderSource(fragmentShader, _Es2_ShaderFragmentSource);
            Gl.CompileShader(fragmentShader);
            Gl.GetShader(fragmentShader, ShaderParameterName.CompileStatus, out compiled);
            if (compiled == 0)
            {
                Gl.GetShaderInfoLog(fragmentShader, 1024, out infologLength, infolog);
            }

            // Program
            _Es2_Program = Gl.CreateProgram();
            Gl.AttachShader(_Es2_Program, vertexShader);
            Gl.AttachShader(_Es2_Program, fragmentShader);
            Gl.LinkProgram(_Es2_Program);

            int linked;

            Gl.GetProgram(_Es2_Program, ProgramProperty.LinkStatus, out linked);

            if (linked == 0)
            {
                Gl.GetProgramInfoLog(_Es2_Program, 1024, out infologLength, infolog);
            }

            _Es2_Program_Location_uMVP      = Gl.GetUniformLocation(_Es2_Program, "uMVP");
            _Es2_Program_Location_aPosition = Gl.GetAttribLocation(_Es2_Program, "aPosition");
            _Es2_Program_Location_aColor    = Gl.GetAttribLocation(_Es2_Program, "aColor");
        }
Example #29
0
        private void Render(object sender, GlControlEventArgs e)
        {
            if (_shader == null)
            {
                return;
            }
            _shader.M = Matrix4x4.Identity;

            var m = Matrix4x4.CreateTranslation(new Vector3(_pos, 0));

            Gl.LineWidth(1);
        }
        private void GlControl_OnContextCreated(object sender, GlControlEventArgs e)
        {
            var control = (GlControl)sender;

            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();

            Gl.ClearColor(_bgColorVec.X, _bgColorVec.Y, _bgColorVec.Z, _bgColorVec.W);

            Shader = new ShaderHelper();
            AdjustOrtho(new Size(control.Height, control.Width));
        }