本文整理匯總了C#中SharpGL.OpenGL.PolygonMode方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.PolygonMode方法的具體用法?C# OpenGL.PolygonMode怎麽用?C# OpenGL.PolygonMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.PolygonMode方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: InitShader
void IRenderable.Render(OpenGL gl, RenderMode renderMode)
{
if (positionBuffer == null || colorBuffer == null) { return; }
if (this.shaderProgram == null)
{
this.shaderProgram = InitShader(gl, renderMode);
}
if (this.vertexArrayObject == null)
{
CreateVertexArrayObject(gl, renderMode);
}
BeforeRendering(gl, renderMode);
if (this.RenderGridWireframe && this.vertexArrayObject != null)
{
//if (wireframeIndexBuffer != null)
if (positionBuffer != null && colorBuffer != null && indexBuffer != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);// shader一律上白色。
gl.Disable(OpenGL.GL_LINE_STIPPLE);
gl.Disable(OpenGL.GL_POLYGON_STIPPLE);
gl.Enable(OpenGL.GL_LINE_SMOOTH);
gl.Enable(OpenGL.GL_POLYGON_SMOOTH);
gl.ShadeModel(SharpGL.Enumerations.ShadeModel.Smooth);
gl.Hint(SharpGL.Enumerations.HintTarget.LineSmooth, SharpGL.Enumerations.HintMode.Nicest);
gl.Hint(SharpGL.Enumerations.HintTarget.PolygonSmooth, SharpGL.Enumerations.HintMode.Nicest);
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(this.vertexArrayObject[0]);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer[0]);
gl.DrawElements(OpenGL.GL_QUAD_STRIP, this.indexBufferLength, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
gl.Disable(OpenGL.GL_POLYGON_SMOOTH);
}
}
if (this.RenderGrid && this.vertexArrayObject != null)
{
if (positionBuffer != null && colorBuffer != null && indexBuffer != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);// shader根據uv buffer來上色。
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(this.vertexArrayObject[0]);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer[0]);
gl.DrawElements(OpenGL.GL_QUAD_STRIP, this.indexBufferLength, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
}
}
AfterRendering(gl, renderMode);
}
示例2: triangle
//以下是二維平麵的處理
private void triangle(OpenGL gl, double x1, double y1, double x2, double y2, double x3, double y3)
{
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_LINE);
gl.Begin(OpenGL.GL_TRIANGLES);
gl.Color(0f, 0f, 0f);
gl.Vertex(x1, y1, 0);
gl.Vertex(x2, y2, 0);
gl.Vertex(x3, y3, 0);
gl.End();
}
示例3: quadrangle
private void quadrangle(OpenGL gl, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_LINE);
gl.Begin(OpenGL.GL_QUADS);
gl.Color(0f, 0f, 0f);
gl.Vertex(x1, y1, 0);
gl.Vertex(x2, y2, 0);
gl.Vertex(x3, y3, 0);
gl.Vertex(x4, y4, 0);
gl.End();
}
示例4: DrawMesh
/// <summary>
/// Draw a mesh.
/// </summary>
/// <param name="gl">OpenGL handler.</param>
/// <param name="buildingObj">The mesh.</param>BuildingObjectLib3DS _object,
private void DrawMesh(OpenGL gl, Lib3dsMesh thisMesh, Hashtable textures, List<Lib3dsMaterial> matrials, DrawType type)
{
if (thisMesh == null || thisMesh.nfaces == 0)
return;
// Draw all the faces in this mesh.
for (int j = 0; j < thisMesh.faces.Count; j++)
{
Lib3dsFace thisFace = thisMesh.faces[j];
float transparency = matrials[thisFace.material].transparency;
//float[] fogColor = new float[4] { 0.5f, 0.5f, 0.5f, 1.0f };
//float[] LightAmbient = new float[4] { 0.5f, 0.5f, 0.5f, 1.0f };
//float[] LightDiffuse = new float[4] { 1.0f, 1.0f, 1.0f, 1.0f };
//float[] LightPosition = new float[4] { 0.0f, 0.0f, 2.0f, 1.0f };
switch (type)
{
case DrawType.WireFrame:
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_LINE);
IsDrawTexture = false;
gl.Color(0.5f, 0.5f, 0.5f, 0.5f);
gl.LineWidth(1.5f);
break;
case DrawType.Full:
IsDrawTexture = BindTexture(gl, textures, matrials[thisFace.material].name);
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
break;
case DrawType.Face:
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
IsDrawTexture = false;
break;
case DrawType.Translucent:
IsDrawTexture = BindTexture(gl, textures, matrials[thisFace.material].name);
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(OpenGL.GL_SRC_ALPHA,OpenGL.GL_ONE_MINUS_SRC_ALPHA);
//gl.Enable(OpenGL.GL_TEXTURE_2D); // Enable Texture Mapping
//gl.ShadeModel(OpenGL.GL_SMOOTH); // Enable Smooth Shading
//gl.ClearColor(0.5f,0.5f,0.5f,1.0f); // We'll Clear To The Color Of The Fog
//gl.ClearDepth(1.0f); // Depth Buffer Setup
//gl.Enable(OpenGL.GL_DEPTH_TEST); // Enables Depth Testing
//gl.DepthFunc(OpenGL.GL_LEQUAL); // The Type Of Depth Testing To Do
//gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST); // Really Nice Perspective Calculations
//gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_AMBIENT, LightAmbient); // Setup The Ambient Light
//gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
//gl.Light(OpenGL.GL_LIGHT1, OpenGL.GL_POSITION,LightPosition); // Position The Light
//gl.Enable(OpenGL.GL_LIGHT1);
//gl.Fog(OpenGL.GL_FOG_COLOR, fogColor);//設置霧顏色,f是一個指定顏色的數組float f[4]
//gl.Fog(OpenGL.GL_FOG_DENSITY, 0.85f); // 設置霧的密度
//gl.Hint(OpenGL.GL_FOG_HINT, OpenGL.GL_DONT_CARE); // 設置係統如何計算霧氣
//gl.Fog(OpenGL.GL_FOG_START, 0.01f);//設置霧從多遠開始
//gl.Fog(OpenGL.GL_FOG_END, 100.0f);//設置霧從多遠結束
//gl.Fog(OpenGL.GL_FOG_MODE, OpenGL.GL_LINEAR);//設置使用哪種霧,共有三中霧化模式
//gl.Enable(OpenGL.GL_FOG);//打開霧效果
transparency = 0.2f;
break;
default:
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK, OpenGL.GL_FILL);
IsDrawTexture = false;
break;
}
if (type != DrawType.WireFrame)
{
gl.Color(matrials[thisFace.material].diffuse[0], matrials[thisFace.material].diffuse[1],
matrials[thisFace.material].diffuse[2], matrials[thisFace.material].transparency);
}
gl.Begin(OpenGL.GL_TRIANGLES);
for (int k = 0; k != 3; ++k)
{
int index = thisFace.index[k];
if (IsDrawTexture)
gl.TexCoord(thisMesh.texcos[index].s, thisMesh.texcos[index].t);
gl.Vertex(thisMesh.vertices[index].x / 20, thisMesh.vertices[index].z / 20, -thisMesh.vertices[index].y / 20);
}
gl.End();
if(type == DrawType.Translucent)
gl.Disable(OpenGL.GL_BLEND);
}
}
示例5: DoRenderMatrix
/// <summary>
/// 渲染基質
/// </summary>
/// <param name="gl"></param>
/// <param name="renderMode"></param>
private void DoRenderMatrix(OpenGL gl, RenderMode renderMode)
{
if (this.positionBuffer == null || this.colorBuffer == null) { return; }
if (this.RenderGrid && this.matrixVertexArrayObject != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);
shaderProgram.SetUniform1(gl, "opacity", this.Opacity);
gl.Enable(OpenGL.GL_POLYGON_OFFSET_FILL);
gl.PolygonOffset(1.0f, 1.0f);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(matrixVertexArrayObject[0]);
switch (this.MatrixType)
{
case MatrixFormat.Triangle:
gl.DrawArrays(this.matrixRenderMode, 0, this.MatrixVertexOrIndexCount);
break;
case MatrixFormat.Tetrahedron:
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
case MatrixFormat.TriangularPrism:
// 先渲染三棱柱的上下三角形
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.MatrixVertexOrIndexCount);
// 再渲染三棱柱的三個側麵
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
default:
break;
}
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
gl.Disable(OpenGL.GL_POLYGON_OFFSET_FILL);
}
if (this.RenderGridWireframe && this.matrixVertexArrayObject != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);
shaderProgram.SetUniform1(gl, "opacity", this.Opacity);
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(matrixVertexArrayObject[0]);
switch (this.MatrixType)
{
case MatrixFormat.Triangle:
gl.DrawArrays(this.matrixRenderMode, 0, this.MatrixVertexOrIndexCount);
break;
case MatrixFormat.Tetrahedron:
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
case MatrixFormat.TriangularPrism:
// 先渲染三棱柱的上下三角形
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.MatrixVertexOrIndexCount / 9 * 6);
// 再渲染三棱柱的三個側麵
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
default:
break;
}
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
}
}
示例6: DoRenderFraction
private void DoRenderFraction(OpenGL gl, RenderMode renderMode)
{
if (this.fractionPositionBuffer == null || this.fractionUVBuffer == null) { return; }
if (this.RenderFraction && this.fractionVertexArrayObject != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);
gl.Enable(OpenGL.GL_POLYGON_OFFSET_FILL);
gl.PolygonOffset(1.0f, 1.0f);
gl.BindVertexArray(fractionVertexArrayObject[0]);
switch (this.FractionType)
{
case FractureFormat.Line:
float[] originalWidth = new float[1];
gl.GetFloat(SharpGL.Enumerations.GetTarget.LineWidth, originalWidth);
gl.LineWidth(this.FractionLineWidth);
gl.DrawArrays(OpenGL.GL_LINES, 0, this.FractionVertexCount);
gl.LineWidth(originalWidth[0]);
break;
case FractureFormat.Triange:
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.FractionVertexCount);
break;
case FractureFormat.Quad:
gl.DrawArrays(OpenGL.GL_QUADS, 0, this.FractionVertexCount);
break;
default:
throw new NotImplementedException();
//break;
}
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_POLYGON_OFFSET_FILL);
}
if (this.renderFractionWireframe && this.fractionVertexArrayObject != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);
gl.BindVertexArray(fractionVertexArrayObject[0]);
{
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);
switch (this.FractionType)
{
case FractureFormat.Line:
gl.DrawArrays(OpenGL.GL_LINES, 0, this.FractionVertexCount);
break;
case FractureFormat.Triange:
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.FractionVertexCount);
break;
case FractureFormat.Quad:
gl.DrawArrays(OpenGL.GL_QUADS, 0, this.FractionVertexCount);
break;
default:
break;
}
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
}
gl.BindVertexArray(0);
}
}
示例7: RenderImmediateMode
/// <summary>
/// Renders the scene in immediate mode.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void RenderImmediateMode(OpenGL gl)
{
// Setup the modelview matrix.
gl.MatrixMode(OpenGL.GL_MODELVIEW);
gl.LoadIdentity();
gl.MultMatrix(modelviewMatrix.to_array());
// Push the polygon attributes and set line mode.
gl.PushAttrib(OpenGL.GL_POLYGON_BIT);
gl.PolygonMode(FaceMode.FrontAndBack, PolygonMode.Lines);
// Render the trefoil.
var vertices = trefoilKnot.Vertices;
gl.Begin(BeginMode.Triangles);
foreach (var index in trefoilKnot.Indices)
gl.Vertex(vertices[index].x, vertices[index].y, vertices[index].z);
gl.End();
// Pop the attributes, restoring all polygon state.
gl.PopAttrib();
}