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


C# OpenGL.Enable方法代码示例

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


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

示例1: Set

        /// <summary>
        /// This function sets all of the lights parameters into OpenGL.
        /// </summary>
        public virtual void Set(OpenGL gl)
        {
            if(on)
            {
                //	Enable this light.
                gl.Enable(glCode);

                //	The light is on, so set it's properties.
                gl.Light(glCode, OpenGL.AMBIENT, ambient);
                gl.Light(glCode, OpenGL.DIFFUSE, diffuse);
                gl.Light(glCode, OpenGL.SPECULAR, specular);
                gl.Light(glCode, OpenGL.POSITION, new float[] {translate.X, translate.Y, translate.Z, 1.0f});
                gl.Light(glCode, OpenGL.SPOT_CUTOFF, spotCutoff);

                Vertex vector = Translate - direction;
                gl.Light(glCode, OpenGL.SPOT_DIRECTION, vector);
            }
            else
                gl.Disable(glCode);
        }
开发者ID:nromik,项目名称:sharpgl,代码行数:23,代码来源:Light.cs

示例2: InitialiseHighQuality

 /// <summary>
 /// Initialises the supplied OpenGL instance for high quality rendering.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public static void InitialiseHighQuality(OpenGL gl)
 {
     //	Set parameters that give us some high quality settings.
     gl.Enable(OpenGL.GL_DEPTH_TEST);
     gl.Enable(OpenGL.GL_NORMALIZE);
     gl.Enable(OpenGL.GL_LIGHTING);
     gl.Enable(OpenGL.GL_TEXTURE_2D);
     gl.ShadeModel(OpenGL.GL_SMOOTH);
     gl.LightModel(OpenGL.GL_LIGHT_MODEL_TWO_SIDE, OpenGL.GL_TRUE);
     gl.Enable(OpenGL.GL_BLEND);
     gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
 }
开发者ID:chantsunman,项目名称:sharpgl,代码行数:16,代码来源:OpenGLHelper.cs

示例3: Render

        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public override void Render(OpenGL gl, RenderMode renderMode)
        {
            //	Create the evaluator.
            gl.Map1(OpenGL.GL_MAP1_VERTEX_3,//	Use and produce 3D points.
                0,								//	Low order value of 'u'.
                1,								//	High order value of 'u'.
                3,								//	Size (bytes) of a control point.
                ControlPoints.Width,			//	Order (i.e degree plus one).
                ControlPoints.ToFloatArray());	//	The control points.

            //	Enable the type of evaluator we wish to use.
            gl.Enable(OpenGL.GL_MAP1_VERTEX_3);

            //	Beging drawing a line strip.
            gl.Begin(OpenGL.GL_LINE_STRIP);

            //	Now draw it.
            for (int i = 0; i <= segments; i++)
                gl.EvalCoord1((float)i / segments);

            gl.End();

            //	Draw the control points.
            ControlPoints.Draw(gl, DrawControlPoints, DrawControlGrid);
        }
开发者ID:hhool,项目名称:sharpgl,代码行数:30,代码来源:Evaluator1D.cs

示例4: Bind

        /// <summary>
        /// This function sets all of the lights parameters into OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
		public virtual void Bind(OpenGL gl)
		{
			if(on)
			{
				//	Enable this light.
                gl.Enable(OpenGL.GL_LIGHTING);
				gl.Enable(glCode);

				//	The light is on, so set it's properties.
                gl.Light(glCode, OpenGL.GL_AMBIENT, ambient);
                gl.Light(glCode, OpenGL.GL_DIFFUSE, diffuse);
                gl.Light(glCode, OpenGL.GL_SPECULAR, specular);
                gl.Light(glCode, OpenGL.GL_POSITION, new float[] { position.X, position.Y, position.Z, 1.0f });

                //  180 degree cutoff gives an omnidirectional light.
                gl.Light(GLCode, OpenGL.GL_SPOT_CUTOFF, 180.0f);
            }
			else
				gl.Disable(glCode);
		}
开发者ID:mind0n,项目名称:hive,代码行数:24,代码来源:Light.cs

示例5: Render

        /// <summary>
        /// Render to the provided instance of OpenGL.
        /// </summary>
        /// <param name="gl">The OpenGL instance.</param>
        /// <param name="renderMode">The render mode.</param>
        public override void Render(OpenGL gl, RenderMode renderMode)
		{			
			//	Create the evaluator.
            gl.Map2(OpenGL.GL_MAP2_VERTEX_3,//	Use and produce 3D points.
				0,								//	Low order value of 'u'.
				1,								//	High order value of 'u'.
				3,								//	Size (bytes) of a control point.
				ControlPoints.Width,			//	Order (i.e degree plus one).
				0,								//	Low order value of 'v'.
				1,								//	High order value of 'v'
				ControlPoints.Width * 3,		//	Size in bytes of a 'row' of points.
				ControlPoints.Height,			//	Order (i.e degree plus one).
				ControlPoints.ToFloatArray());	//	The control points.

            gl.Enable(OpenGL.GL_MAP2_VERTEX_3);
            gl.Enable(OpenGL.GL_AUTO_NORMAL);
			gl.MapGrid2(20, 0, 1, 20, 0, 1);
			
			//	Now draw it.
            gl.EvalMesh2(OpenGL.GL_FILL, 0, 20, 0, 20);

			//	Draw the control points.
            ControlPoints.Draw(gl, DrawControlPoints, DrawControlGrid);
		}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:29,代码来源:Evaluator2D.cs

示例6: DrawGrid

        public virtual void DrawGrid(OpenGL gl)
        {
            gl.PushAttrib(OpenGL.LINE_BIT | OpenGL.ENABLE_BIT | OpenGL.COLOR_BUFFER_BIT);

            //  Turn off lighting, set up some nice anti-aliasing for lines.
            gl.Disable(OpenGL.LIGHTING);
            gl.Hint(OpenGL.LINE_SMOOTH_HINT, OpenGL.NICEST);
            gl.Enable(OpenGL.LINE_SMOOTH);
            gl.Enable(OpenGL.BLEND);
            gl.BlendFunc(OpenGL.SRC_ALPHA, OpenGL.ONE_MINUS_SRC_ALPHA);

            //	Create the grid.
            gl.LineWidth(1.5f);

            gl.Begin(OpenGL.LINES);

                for (int i = -10; i <= 10; i++)
                {
                    gl.Color(0.2f, 0.2f, 0.2f, 1f);
                    gl.Vertex(i, 0, -10);
                    gl.Vertex(i, 0, 10);
                    gl.Vertex(-10, 0, i);
                    gl.Vertex(10, 0, i);
                }

            gl.End();

            //  Turn off the depth test for the axies.
            gl.Disable(OpenGL.DEPTH_TEST);
            gl.LineWidth(2.0f);

            //	Create the axies.
            gl.Begin(OpenGL.LINES);

                gl.Color(1f, 0f, 0f, 1f);
                gl.Vertex(0f, 0f, 0f);
                gl.Vertex(3f, 0f, 0f);
                gl.Color(0f, 1f, 0f, 1f);
                gl.Vertex(0f, 0f, 0f);
                gl.Vertex(0f, 3f, 0f);
                gl.Color(0f, 0f, 1f, 1f);
                gl.Vertex(0f, 0f, 0f);
                gl.Vertex(0f, 0f, 3f);

            gl.End();

            gl.PopAttrib();

               //     gl.Flush();
        }
开发者ID:nromik,项目名称:sharpgl,代码行数:50,代码来源:StockDrawing.cs

示例7: CastShadow

        /// <summary>
        /// Casts a real time 3D shadow.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="lights">The lights.</param>
		private void CastShadow(OpenGL gl)
		{
			//	Set the connectivity, (calculate the neighbours of each face).
			SetConnectivity();

            //  Get the lights in the scene.
            var lights = TraverseToRootElement().Traverse<Light>(l => l.IsEnabled && l.On && l.CastShadow);

            //  Get some useful references.
            var faces = ParentPolygon.Faces;

			//	Go through every light in the scene.
			foreach(var light in lights)
			{
				//	Every face will have a visibility setting.
				bool[] facesVisible = new bool[faces.Count];

				//	Get the light position relative to the polygon.
				Vertex lightPos = light.Position;
				lightPos = lightPos - ParentPolygon.Transformation.TranslationVertex;

				//	Go through every face, finding out whether it's visible to the light.
				for(int nFace = 0; nFace < faces.Count; nFace++)
				{
					//	Get a reference to the face.
					Face face = faces[nFace];

					//	Is this face facing the light?
					float[] planeEquation = face.GetPlaneEquation(ParentPolygon);
					float side = planeEquation[0] * lightPos.X + 
						planeEquation[1] * lightPos.Y + 
						planeEquation[2] * lightPos.Z + planeEquation[3];
					facesVisible[nFace] = (side > 0) ? true : false;
				}

				//	Save all the attributes.
                gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
			
				//	Turn off lighting.
                gl.Disable(OpenGL.GL_LIGHTING);

				//	Turn off writing to the depth mask.
				gl.DepthMask(0);
                gl.DepthFunc(OpenGL.GL_LEQUAL);

				//	Turn on stencil buffer testing.
                gl.Enable(OpenGL.GL_STENCIL_TEST);

				//	Translate our shadow volumes.
				ParentPolygon.PushObjectSpace(gl);

				//	Don't draw to the color buffer.
				gl.ColorMask(0, 0, 0, 0);
                gl.StencilFunc(OpenGL.GL_ALWAYS, 1, 0xFFFFFFFF);

                gl.Enable(OpenGL.GL_CULL_FACE);
			
				//	First Pass. Increase Stencil Value In The Shadow
                gl.FrontFace(OpenGL.GL_CCW);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_INCR);
				DoShadowPass(gl, lightPos, facesVisible);

				//	Second Pass. Decrease Stencil Value In The Shadow
                gl.FrontFace(OpenGL.GL_CW);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_DECR);
				DoShadowPass(gl, lightPos, facesVisible);

                gl.FrontFace(OpenGL.GL_CCW);

				ParentPolygon.PopObjectSpace(gl);
			
				//	Enable writing to the color buffer.
				gl.ColorMask(1, 1, 1, 1); 
            
				// Draw A Shadowing Rectangle Covering The Entire Screen
				gl.Color(light.ShadowColor);
                gl.Enable(OpenGL.GL_BLEND);
                gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
                gl.StencilFunc(OpenGL.GL_NOTEQUAL, 0, 0xFFFFFFF);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_KEEP);
				
				Quadrics.Sphere shadow = new Quadrics.Sphere();
                shadow.Transformation.ScaleX = shadowSize;
                shadow.Transformation.ScaleY = shadowSize;
                shadow.Transformation.ScaleZ = shadowSize;
				shadow.Render(gl, RenderMode.Design);
	
				gl.PopAttrib();
			}
		}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:95,代码来源:Shadow.cs

示例8: CastShadow

        /// <summary>
        /// Casts a real time 3D shadow.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="light">The source light.</param>
        public void CastShadow(OpenGL gl, Collections.LightCollection lights)
        {
            //	Set the connectivity, (calculate the neighbours of each face).
            SetConnectivity();

            //	Go through every light in the scene.
            foreach(Lights.Light light in lights)
            {
                //	Skip null lights.
                if(light == null)
                    continue;

                //	Skip turned off lights and non shadow lights.
                if(light.On == false || light.CastShadow == false)
                    continue;

                //	Every face will have a visibility setting.
                bool[] facesVisible = new bool[faces.Count];

                //	Get the light position relative to the polygon.
                Vertex lightPos = light.Translate;
                lightPos = lightPos - Translate;

                //	Go through every face, finding out whether it's visible to the light.
                for(int nFace = 0; nFace < faces.Count; nFace++)
                {
                    //	Get a reference to the face.
                    Face face = faces[nFace];

                    //	Is this face facing the light?
                    float[] planeEquation = face.GetPlaneEquation(this);
                    float side = planeEquation[0] * lightPos.X +
                        planeEquation[1] * lightPos.Y +
                        planeEquation[2] * lightPos.Z + planeEquation[3];
                    facesVisible[nFace] = (side > 0) ? true : false;
                }

                //	Save all the attributes.
                gl.PushAttrib(OpenGL.ALL_ATTRIB_BITS);

                //	Turn off lighting.
                gl.Disable(OpenGL.LIGHTING);

                //	Turn off writing to the depth mask.
                gl.DepthMask(0);
                gl.DepthFunc(OpenGL.LEQUAL);

                //	Turn on stencil buffer testing.
                gl.Enable(OpenGL.STENCIL_TEST);

                //	Translate our shadow volumes.
                gl.PushMatrix();
                Transform(gl);

                //	Don't draw to the color buffer.
                gl.ColorMask(0, 0, 0, 0);
                gl.StencilFunc(OpenGL.ALWAYS, 1, 0xFFFFFFFF);

                gl.Enable(OpenGL.CULL_FACE);

                //	First Pass. Increase Stencil Value In The Shadow
                gl.FrontFace(OpenGL.CCW);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.INCR);
                DoShadowPass(gl, lightPos, facesVisible);

                //	Second Pass. Decrease Stencil Value In The Shadow
                gl.FrontFace(OpenGL.CW);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.DECR);
                DoShadowPass(gl, lightPos, facesVisible);

                gl.FrontFace(OpenGL.CCW);

                gl.PopMatrix();

                //	Enable writing to the color buffer.
                gl.ColorMask(1, 1, 1, 1);

                // Draw A Shadowing Rectangle Covering The Entire Screen
                gl.Color(light.ShadowColor);
                gl.Enable(OpenGL.BLEND);
                gl.BlendFunc(OpenGL.SRC_ALPHA, OpenGL.ONE_MINUS_SRC_ALPHA);
                gl.StencilFunc(OpenGL.NOTEQUAL, 0, 0xFFFFFFF);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.KEEP);

                Quadrics.Sphere shadow = new Quadrics.Sphere();
                shadow.Scale.Set(shadowSize, shadowSize, shadowSize);
                shadow.Draw(gl);

                gl.PopAttrib();
            }
        }
开发者ID:nromik,项目名称:sharpgl,代码行数:96,代码来源:Polygon.cs

示例9: Draw

        public override void Draw(OpenGL gl)
        {
            if(DoPreDraw(gl))
            {
                //	Set our line settings.
                lineSettings.Set(gl);

                //	Create the evaluator.
                gl.Map2(OpenGL.MAP2_VERTEX_3,//	Use and produce 3D points.
                    0,								//	Low order value of 'u'.
                    1,								//	High order value of 'u'.
                    3,								//	Size (bytes) of a control point.
                    controlPoints.Width,			//	Order (i.e degree plus one).
                    0,								//	Low order value of 'v'.
                    1,								//	High order value of 'v'
                    controlPoints.Width * 3,		//	Size in bytes of a 'row' of points.
                    controlPoints.Height,			//	Order (i.e degree plus one).
                    controlPoints.ToFloatArray());	//	The control points.

                gl.Enable(OpenGL.MAP2_VERTEX_3);
                gl.Enable(OpenGL.AUTO_NORMAL);
                gl.MapGrid2(20, 0, 1, 20, 0, 1);

                //	Now draw it.
                gl.EvalMesh2(OpenGL.FILL, 0, 20, 0, 20);

                //	Draw the control points.
                controlPoints.Draw(gl, drawPoints, drawLines);

                //	Restore the line attributes.
                lineSettings.Restore(gl);

                DoPostDraw(gl);
            }
        }
开发者ID:nromik,项目名称:sharpgl,代码行数:35,代码来源:Evaluators.cs

示例10: Set

        public override void Set(OpenGL gl)
        {
            base.Set(gl);

            gl.PushAttrib(AttributeBit);

            if(enable)
            {
                gl.Enable(OpenGL.LIGHTING);
                gl.LightModel(OpenGL.LIGHT_MODEL_AMBIENT, ambientLight);
                gl.LightModel(OpenGL.LIGHT_MODEL_LOCAL_VIEWER, localViewer == true ? 1 : 0);
                gl.LightModel(OpenGL.LIGHT_MODEL_TWO_SIDE, twoSided == true ? 1 : 0);
            }
            else
                gl.Disable(OpenGL.LIGHTING);
        }
开发者ID:nromik,项目名称:sharpgl,代码行数:16,代码来源:Attributes.cs


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