コード例 #1
0
        private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext ctx         = e.Context;
            GraphicsSurface framebuffer = e.Framebuffer;

#if DEBUG
            _GeometryClipmapObject = new GeometryClipmapObject(6, 7, _BlockUnit);
#else
            _GeometryClipmapObject = new GeometryClipmapObject(9, 11, _BlockUnit);
#endif

            string workingDir = Directory.GetCurrentDirectory();

            _GeometryClipmapObject.SetTerrainElevationFactory(Path.Combine(workingDir, @"..\..\..\Data\Terrain.vrt"), 45.5, 10.5);

            _GeometryClipmapScene = new SceneGraph();
            _GeometryClipmapScene.AddChild(new SceneGraphCameraObject());
            _GeometryClipmapScene.AddChild(_GeometryClipmapObject);
            _GeometryClipmapScene.Create(ctx);

            // Set projection
            _GeometryClipmapScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(
                _ViewFov / 16.0f * 9.0f,
                (float)ClientSize.Width / (float)ClientSize.Height,
                1.0f, _ViewDepth
                );;

            // Clear color
            framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f));
        }
コード例 #2
0
ファイル: SampleForm.cs プロジェクト: stjeong/OpenGL.Net
        /// <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);
        }
コード例 #3
0
ファイル: MainActivity.cs プロジェクト: owenxuwei/OpenGL.Net
        private void GlSurface_ContextCreated(object sender, GLSurfaceViewEventArgs e)
        {
            // Wrap GL context with GraphicsContext
            _Context = new GraphicsContext(e.DeviceContext, e.RenderContext);

            _CubeScene           = new SceneGraph(SceneGraphFlags.None);
            _CubeScene.SceneRoot = new SceneObjectGeometry();
            _CubeScene.SceneRoot.ObjectState.DefineState(new DepthTestState(DepthFunction.Less));

            _CubeScene.CurrentView = new SceneObjectCamera();
            _CubeScene.SceneRoot.Link(_CubeScene.CurrentView);

            SceneObjectGeometry geometry = new SceneObjectGeometry();

            geometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard");
            geometry.AddGeometry(VertexArrays.CreateSphere(3.0f, 8, 8));

            _CubeScene.SceneRoot.Link(geometry);

            _CubeScene.Create(_Context);

            Gl.ClearColor(1.0f, 0.1f, 0.1f, 1.0f);
        }
コード例 #4
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();
            _CubeScene.Link(new SceneObjectCamera());

            // Global lighting
            SceneObjectLightZone globalLightZone = new SceneObjectLightZone();

            _GlobalLightObject           = new SceneObjectLightDirectional();
            _GlobalLightObject.Direction = (-Vertex3f.UnitX + Vertex3f.UnitY - Vertex3f.UnitZ).Normalized;
            globalLightZone.Link(_GlobalLightObject);

            SceneObjectLightPoint localLightObject = new SceneObjectLightPoint();

            localLightObject.LocalModel.Translate(0.0, -5.0f, 0.0);
            localLightObject.AttenuationFactors.Y = 0.1f;
            //globalLightZone.AddChild(localLightObject);

            _CubeScene.Link(globalLightZone);

            // Cube
            float       Size       = (float)Math.Sqrt(0);
            const float Multiplier = 10.0f;

            int materialIndex = 0;

            for (float x = -Size / 2.0f * Multiplier; x < Size / 2.0f * Multiplier; x += Multiplier)
            {
                for (float y = -Size / 2.0f * Multiplier; y < Size / 2.0f * Multiplier; y += Multiplier, materialIndex++)
                {
                    SceneObjectGeometry cubeInstance = CreateCubeGeometry();

                    cubeInstance.LocalModel.Translate(x, 0.0f, y);
                    cubeInstance.LocalModel.Scale(0.25f);

                    // Enable/Disable blending
                    if ((materialIndex % 2) == 0)
                    {
                        cubeInstance.ObjectState.DefineState(new BlendState(BlendEquationModeEXT.FuncAdd, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha));
                    }

                    // Enable/Disable blending
                    switch (materialIndex % 1)
                    {
                    case 0:
                        cubeInstance.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex", new ShaderCompilerContext("GLO_COLOR_PER_VERTEX"));
                        break;

                    case 1:
                        cubeInstance.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+Color");
                        break;

                    case 2:
                        cubeInstance.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment");
                        break;
                    }

                    globalLightZone.Link(cubeInstance);
                }
            }

            //SceneObjectGeometry cubeLambert = CreateCubeGeometry();
            //cubeLambert.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex", new ShaderCompilerContext("GLO_COLOR_PER_VERTEX"));
            //globalLightZone.Link(cubeLambert);

            //SceneObjectGeometry cubeBlinn = CreateCubeGeometry();
            //cubeBlinn.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment", new ShaderCompilerContext("GLO_COLOR_PER_VERTEX"));
            //cubeBlinn.LocalModel.Translate(0.0f, 10.0f, 0.0f);
            //globalLightZone.Link(cubeBlinn);

            //SceneObjectGeometry cubeColored = CreateCubeGeometry();
            //cubeColored.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+Color");
            //cubeColored.LocalModel.Translate(0.0f, 5.0f, 0.0f);
            //globalLightZone.Link(cubeColored);

            globalLightZone.Link(CreateBumbleBeeVH());
            globalLightZone.Link(CreateBumbleBeeRB());
            globalLightZone.Link(CreateSphere("squarebricks"));

            // Skybox
            //if ((sceneObject = CreateSkyBoxObject()) != null)
            //	_CubeScene.AddChild(sceneObject);

            _CubeScene.Create(_Context);

            Gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
        }
コード例 #5
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.CullingViewFrustum | SceneGraphFlags.StateSorting | SceneGraphFlags.Lighting | SceneGraphFlags.ShadowMaps
                //| SceneGraphFlags.BoundingVolumes
                );
            _CubeScene.SceneRoot = new SceneObjectGeometry();
            _CubeScene.SceneRoot.ObjectState.DefineState(new DepthTestState(DepthFunction.Less));

            _CubeScene.CurrentView = new SceneObjectCamera();
            _CubeScene.SceneRoot.Link(_CubeScene.CurrentView);

            fontTitle = FontFactory.CreateFont(System.Drawing.FontFamily.GenericSerif, 24, System.Drawing.FontStyle.Regular, FontFactory.FontType.Textured, new FontFxShadow());
            fontTitle.Create(_Context);

            fontTitleV = FontFactory.CreateFont(System.Drawing.FontFamily.GenericSerif, 24, System.Drawing.FontStyle.Regular, FontFactory.FontType.Vector, new FontFxShadow());
            fontTitleV.Create(_Context);

            fontPatch = FontFactory.CreateFont(System.Drawing.FontFamily.GenericMonospace, 16, System.Drawing.FontStyle.Regular, FontFactory.FontType.Vector);
            fontPatch.Create(_Context);

            // Global lighting
            SceneObjectLightZone globalLightZone = new SceneObjectLightZone();

            _GlobalLightObject           = new SceneObjectLightDirectional();
            _GlobalLightObject.Direction = (-Vertex3f.UnitX + Vertex3f.UnitY - Vertex3f.UnitZ).Normalized;
            //globalLightZone.Link(_GlobalLightObject);

            spotLight = new SceneObjectLightSpot();
            spotLight.LocalModel.Translate(0.0f, 35.0f, 0.0f);
            spotLight.Direction       = -Vertex3f.UnitY;
            spotLight.FalloffAngle    = 10.5f;
            spotLight.FalloffExponent = 0.0f;
            globalLightZone.Link(spotLight);

            SceneObjectLightPoint localLightObject = new SceneObjectLightPoint();

            localLightObject.LocalModel.Translate(0.0, -5.0f, 0.0);
            localLightObject.AttenuationFactors.Y = 0.1f;
            //globalLightZone.AddChild(localLightObject);

            _CubeScene.SceneRoot.Link(globalLightZone);

            // Horizontal plane
            globalLightZone.Link(CreatePlane());

            // Cube
            float       Size       = (float)Math.Sqrt(1);
            const float Multiplier = 10.0f;

            int materialIndex = 0;

            for (float x = -Size / 2.0f * Multiplier; x < Size / 2.0f * Multiplier; x += Multiplier)
            {
                for (float y = -Size / 2.0f * Multiplier; y < Size / 2.0f * Multiplier; y += Multiplier, materialIndex++)
                {
                    SceneObjectGeometry cubeInstance = CreateCubeGeometry();

                    cubeInstance.LocalModel.Translate(x, 0.0f, y);
                    cubeInstance.LocalModel.Scale(0.25f);

                    // materialIndex = 1;

                    // Enable/Disable blending
                    if ((materialIndex % 2) == 0)
                    {
                        cubeInstance.ObjectState.DefineState(new BlendState(BlendEquationMode.FuncAdd, BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha));
                    }

                    // Enable/Disable blending
                    switch (materialIndex % 3)
                    {
                    case 0:
                        cubeInstance.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+Color");
                        break;

                    case 1:
                        cubeInstance.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex", new ShaderCompilerContext("GLO_COLOR_PER_VERTEX"));
                        break;

                    case 2:
                        cubeInstance.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment");
                        break;
                    }

                    globalLightZone.Link(cubeInstance);
                }
            }

            //SceneObjectGeometry cubeLambert = CreateCubeGeometry();
            //cubeLambert.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex", new ShaderCompilerContext("GLO_COLOR_PER_VERTEX"));
            //globalLightZone.Link(cubeLambert);

            //SceneObjectGeometry cubeBlinn = CreateCubeGeometry();
            //cubeBlinn.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment", new ShaderCompilerContext("GLO_COLOR_PER_VERTEX"));
            //cubeBlinn.LocalModel.Translate(0.0f, 10.0f, 0.0f);
            //globalLightZone.Link(cubeBlinn);

            //SceneObjectGeometry cubeColored = CreateCubeGeometry();
            //cubeColored.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+Color");
            //cubeColored.LocalModel.Translate(0.0f, 5.0f, 0.0f);
            //globalLightZone.Link(cubeColored);

            globalLightZone.Link(CreateBumbleBeeVH());
            globalLightZone.Link(CreateBumbleBeeRB());
            // globalLightZone.Link(CreateSphere("squarebricks"));

            // Skybox
            //if ((sceneObject = CreateSkyBoxObject()) != null)
            //	_CubeScene.AddChild(sceneObject);

            _CubeScene.Create(_Context);

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

            Gl.Enable(EnableCap.Multisample);
        }