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


C# OpenGL.DepthFunc方法代码示例

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


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

示例1: SetAttributes

 /// <summary>
 /// Sets the attributes.
 /// </summary>
 /// <param name="gl">The OpenGL instance.</param>
 public override void SetAttributes(OpenGL gl)
 {
     if (enableDepthTest.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_TEST, enableDepthTest.Value);
     if (depthFunction.HasValue) gl.DepthFunc(depthFunction.Value);
     if (depthClearValue.HasValue) gl.ClearDepth(depthClearValue.Value);
     if (enableDepthWritemask.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_WRITEMASK, enableDepthWritemask.Value);
 }
开发者ID:cvanherk,项目名称:3d-engine,代码行数:11,代码来源:DepthBufferAttributes.cs

示例2: CreateDisplayList

        /// <summary>
        /// Creates the display list. This function draws the
        /// geometry as well as compiling it.
        /// </summary>
        private void CreateDisplayList(OpenGL gl)
        {
            //  Create the display list. 
            displayList = new DisplayList();

            //  Generate the display list and 
            displayList.Generate(gl);
            displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);

            //  Push all attributes, disable lighting and depth testing.
            gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
                OpenGL.GL_LINE_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
            gl.Disable(OpenGL.GL_LIGHTING);
            gl.Disable(OpenGL.GL_TEXTURE_2D);
            gl.DepthFunc(OpenGL.GL_ALWAYS);

            //  Set a nice fat line width.
            gl.LineWidth(1.50f);

            //  Draw the axies.
            gl.Begin(OpenGL.GL_LINES);
            gl.Color(1f, 0f, 0f, 1f);
            gl.Vertex(0, 0, 0);
            gl.Vertex(3, 0, 0);
            gl.Color(0f, 1f, 0f, 1f);
            gl.Vertex(0, 0, 0);
            gl.Vertex(0, 3, 0);
            gl.Color(0f, 0f, 1f, 1f);
            gl.Vertex(0, 0, 0);
            gl.Vertex(0, 0, 3);
            gl.End();

            //  Restore attributes.
            gl.PopAttrib();

            //  End the display list.
            displayList.End(gl);
        }
开发者ID:cvanherk,项目名称:3d-engine,代码行数:42,代码来源:Axies.cs

示例3: 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

示例4: Draw

		/// <summary>
		/// Use this to draw the vertex grid.
		/// </summary>
		/// <param name="gl">OpenGL object.</param>
		/// <param name="points">Draw each individual vertex (with selection names).</param>
		/// <param name="lines">Draw the lines connecting the points.</param>
		public virtual void Draw(OpenGL gl, bool points, bool lines)
		{
			//	Save the attributes.
            gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
            gl.Disable(OpenGL.GL_LIGHTING);
			gl.Color(1, 0, 0, 1);

			if(points)
			{
                int name = 0;

				gl.PointSize(5);

				//	Add a new name (the vertex name).
				gl.PushName(0);

				foreach(Vertex v in vertices)
				{
					//	Set the name, draw the vertex.
					gl.LoadName((uint)name++);
					//todo draw vertex
                    //((IInteractable)v).DrawPick(gl);
				}

				//	Pop the name.
				gl.PopName();
			}

			if(lines)
			{
				//	Draw lines along each row, then along each column.
                gl.DepthFunc(OpenGL.GL_ALWAYS);

				gl.LineWidth(1);
                gl.Disable(OpenGL.GL_LINE_SMOOTH);

				for(int col=0; col < y; col++)
				{
					for(int row=0; row < x; row++)
					{
						//	Create vertex indicies.
						int nTopLeft = (col * x) + row;
						int nBottomLeft = ((col + 1) * x) + row;

                        gl.Begin(OpenGL.GL_LINES);
						if(row < (x-1))
						{
							gl.Vertex(vertices[nTopLeft]);
							gl.Vertex(vertices[nTopLeft + 1]);
						}
						if(col < (y-1))
						{
							gl.Vertex(vertices[nTopLeft]);
							gl.Vertex(vertices[nBottomLeft]);
						}
						gl.End();
					}
				}
                gl.DepthFunc(OpenGL.GL_LESS);
			}

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

示例5: 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


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