本文整理匯總了C#中SharpGL.OpenGL.BlendFunc方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.BlendFunc方法的具體用法?C# OpenGL.BlendFunc怎麽用?C# OpenGL.BlendFunc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.BlendFunc方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: openGLControl_OpenGLDraw
/// <summary>
/// Handles the OpenGLDraw event of the openGLControl control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RenderEventArgs"/> instance containing the event data.</param>
public void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
{
// Get the OpenGL object.
gl = openGLControl.OpenGL;
// Clear the color and depth buffer.
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
// Load the identity matrix.
gl.LoadIdentity();
// Rotate around the Y axis.
//gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
cord = ComInput.Coordinates.Instance;
this.ModelRotater(gl);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
// Draw a coloured parallelepiped.
gl.Begin(OpenGL.GL_QUADS);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, -1.0f);
//-------------------------------------
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, -1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, 1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, 1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, -1.0f);
//-------------------------------------
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, 1.0f);
//-------------------------------------
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, 1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, -1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, -1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, 1.0f);
//-------------------------------------
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(-2.0f, 0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(2.0f, 0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(2.0f, 0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(-2.0f, 0.25f, 1.0f);
//--------------------------------------
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(-2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(2.0f, -0.25f, 1.0f);
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(-2.0f, -0.25f, 1.0f);
gl.End();
//.........這裏部分代碼省略.........
示例2: InitShader
void IRenderable.Render(OpenGL gl, RenderMode renderMode)
{
if (positionBuffer != null && colorBuffer != null && radiusBuffer != null)
{
if (this.shaderProgram == null)
{
this.shaderProgram = InitShader(gl, renderMode);
}
if (this.vertexArrayObject == null)
{
CreateVertexArrayObject(gl, renderMode);
}
BeforeRendering(gl, renderMode);
if (this.RenderGrid && this.vertexArrayObject != null)
{
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(this.vertexArrayObject[0]);
gl.DrawArrays(OpenGL.GL_POINTS, 0, count);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
}
AfterRendering(gl, renderMode);
}
}
示例3: OnLoad
public override void OnLoad(OpenGL gl)
{
gl.Enable(OpenGL.GL_CULL_FACE);
gl.Enable(OpenGL.GL_DEPTH_TEST);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
_camera = new OrthographicCamera();
_camera.View *= Mat4.RotateY(Angle.FromDegrees(15));
_shader = new BasicShader(gl);
_modelUniform = gl.GetUniformLocation(_shader.Handle, "Model");
_viewUniform = gl.GetUniformLocation(_shader.Handle, "View");
_projectionUniform = gl.GetUniformLocation(_shader.Handle, "Projection");
_graph = new OpenGLSceneGraph();
_graph.Nodes.Add(new CoordinateSystemLeaf(gl, _shader, _model.Features.OfType<CoordinateSystem>()));
_graph.Nodes.Add(new DatumPlaneLeaf(gl, _shader, _model.Features.OfType<DatumPlane>()));
_graph.Nodes.Add(new GeometryLeaf(gl, _shader));
}
示例4: 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);
}
示例5: 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);
}
}
示例6: InitEngine
public void InitEngine(OpenGL gl)
{
try
{
DebugTools.LogToConsole("Prepareing GL");
//setup open gl and activate modes
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_REPEAT);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_REPEAT);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_NEAREST);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_NEAREST);
gl.Enable(OpenGL.GL_BLEND);
gl.Enable(OpenGL.GL_TEXTURE_2D);
gl.Enable(OpenGL.GL_DEPTH_TEST);
//fffgl.Enable(OpenGL.GL_LIGHTING);
gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
gl.ShadeModel(OpenGL.GL_SMOOTH);
//Darw the first frame with a load test
Draw(gl);
DebugTools.LogToConsole("Loading Resources");
//Loading the resources and bind to gl
resourceManager = new ResourceManager();
DebugTools.LogToConsole("Applying Textures");
resourceManager.InitTextures(gl);
DebugTools.LogToConsole("Loading Level");
//Loading level
//_level = new MasterMindGame.MasterMind();
//_level.Build(this);
_level = new MasterMindGame.MasterMind();
_level.Build(this);
GameObjects.Sort(
delegate(GameObject p1, GameObject p2)
{
return p1.Z_Index.CompareTo(p2.Z_Index);
}
);
//Startup is complete
StartupComplete = true;
}
catch (Exception error)
{
DebugTools.LogError(error);
}
}
示例7: StartRendering
/// <summary>
/// Create device and renderbuffer, initialize NV_DX_interop and start rendering.
/// </summary>
private void StartRendering()
{
_gl = new OpenGL();
_hwnd = new HwndSource(0, 0, 0, 0, 0, "test", IntPtr.Zero).Handle;
_gl.Create(SharpGL.Version.OpenGLVersion.OpenGL2_1, RenderContextType.HiddenWindow, 1, 1, 32, _hwnd);
// Set the most basic OpenGL styles.
_gl.ShadeModel(OpenGL.GL_SMOOTH);
_gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
_gl.ClearDepth(1.0f);
_gl.Enable(OpenGL.GL_BLEND);
_gl.Disable(OpenGL.GL_DEPTH_TEST);
_gl.Enable(OpenGL.GL_TEXTURE_2D);
_gl.TexEnv(OpenGL.GL_TEXTURE_ENV, OpenGL.GL_TEXTURE_ENV_MODE, OpenGL.GL_REPLACE);
_gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
//_gl.Enable(OpenGL.GL_MULTISAMPLE);
//_gl.Enable(OpenGL.GL_MULTISAMPLE_ARB);
_gl.Hint(0x8534, OpenGL.GL_FASTEST);
ResizeRendering();
// leverage the Rendering event of WPF's composition target to
// update the custom D3D scene
CompositionTarget.Rendering += OnRenderOpenGL;
if (GLInitialize != null)
GLInitialize(this, new EventArgs());
}
示例8: foreach
/// <summary>
/// This is called when a face is interactable, so highlight it.
/// </summary>
void IInteractable.DrawPick(OpenGL gl)
{
// Save all the attributes.
gl.PushAttrib(OpenGL.ALL_ATTRIB_BITS);
// Disable lighting, set colour to red etc.
gl.Disable(OpenGL.LIGHTING);
gl.DepthFunc(OpenGL.LEQUAL);
// Now draw it with a faint red.
gl.Enable(OpenGL.BLEND);
gl.BlendFunc(OpenGL.SRC_ALPHA, OpenGL.ONE_MINUS_SRC_ALPHA);
gl.Color(1, 0, 0, 0.2f);
// Draw the face.
gl.Begin(OpenGL.POLYGON);
foreach(Index index in indices)
gl.Vertex(parentpoly.Vertices[index.Vertex]);
gl.End();
gl.Disable(OpenGL.BLEND);
// Draw the face.
gl.Begin(OpenGL.LINE_LOOP);
for(int i = 0; i < indices.Count - 1; i++)
gl.Vertex(parentpoly.Vertices[indices[i].Vertex]);
gl.End();
gl.PopAttrib();
}
示例9: 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);
}
}
示例10: OnLoad
public override void OnLoad(OpenGL gl)
{
gl.Enable(OpenGL.GL_CULL_FACE);
gl.Enable(OpenGL.GL_DEPTH_TEST);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha);
_camera = new OrthographicCamera();
_camera.View *= Mat4.RotateY(Angle.FromDegrees(15));
_shader = new BasicShader(gl);
_modelUniform = gl.GetUniformLocation(_shader.Handle, "Model");
_viewUniform = gl.GetUniformLocation(_shader.Handle, "View");
_projectionUniform = gl.GetUniformLocation(_shader.Handle, "Projection");
_graph = new SceneGraph();
_graph.Nodes.Add(new CoordinateSystemLeaf(gl, _shader, _model.Features.OfType<CoordinateSystem>()));
_graph.Nodes.Add(new DatumPlaneLeaf(gl, _shader, _model.Features.OfType<DatumPlane>()));
const double s = 5.0;
var v0 = new Vertex("v0", new Vect3(0, 0, 0));
var v1 = new Vertex("v1", new Vect3(0, 0, s));
var v2 = new Vertex("v2", new Vect3(s, 0, s));
var v3 = new Vertex("v3", new Vect3(s, 0, 0));
var v4 = new Vertex("v4", new Vect3(0, s, 0));
var v5 = new Vertex("v5", new Vect3(0, s, s));
var v6 = new Vertex("v6", new Vect3(s, s, s));
var v7 = new Vertex("v7", new Vect3(s, s, 0));
var f0 = new Face("f0");
var f1 = new Face("f1");
var f2 = new Face("f2");
var f3 = new Face("f3");
var f4 = new Face("f4");
var f5 = new Face("f5");
LineHalfEdge e0a = null;
LineHalfEdge e0b = null;
LineHalfEdge e1a = null;
LineHalfEdge e1b = null;
LineHalfEdge e2a = null;
LineHalfEdge e2b = null;
LineHalfEdge e3a = null;
LineHalfEdge e3b = null;
LineHalfEdge e4a = null;
LineHalfEdge e4b = null;
LineHalfEdge e5a = null;
LineHalfEdge e5b = null;
LineHalfEdge e6a = null;
LineHalfEdge e6b = null;
LineHalfEdge e7a = null;
LineHalfEdge e7b = null;
LineHalfEdge e8a = null;
LineHalfEdge e8b = null;
LineHalfEdge e9a = null;
LineHalfEdge e9b = null;
LineHalfEdge e10a = null;
LineHalfEdge e10b = null;
LineHalfEdge e11a = null;
LineHalfEdge e11b = null;
e0a = new LineHalfEdge("e0a", v1, new Lazy<IHalfEdge>(() => e0b), f0);
e1a = new LineHalfEdge("e1a", v2, new Lazy<IHalfEdge>(() => e1b), f0);
e2a = new LineHalfEdge("e2a", v3, new Lazy<IHalfEdge>(() => e2b), f0);
e3a = new LineHalfEdge("e3a", v0, new Lazy<IHalfEdge>(() => e3b), f0);
f0.Loops.Add(new EdgeLoop(e0a, e1a, e2a, e3a));
e0b = new LineHalfEdge("e0b", v0, new Lazy<IHalfEdge>(() => e0a), f1);
e7a = new LineHalfEdge("e7a", v4, new Lazy<IHalfEdge>(() => e7b), f1);
e8a = new LineHalfEdge("e8a", v5, new Lazy<IHalfEdge>(() => e8b), f1);
e4a = new LineHalfEdge("e4a", v1, new Lazy<IHalfEdge>(() => e4b), f1);
f1.Loops.Add(new EdgeLoop(e0b, e7a, e8a, e4a));
e1b = new LineHalfEdge("e1b", v1, new Lazy<IHalfEdge>(() => e1a), f2);
e4b = new LineHalfEdge("e4b", v5, new Lazy<IHalfEdge>(() => e4a), f2);
e9a = new LineHalfEdge("e9a", v6, new Lazy<IHalfEdge>(() => e9b), f2);
e5a = new LineHalfEdge("e5a", v2, new Lazy<IHalfEdge>(() => e5b), f2);
f2.Loops.Add(new EdgeLoop(e1b, e4b, e9a, e5a));
e2b = new LineHalfEdge("e2b", v2, new Lazy<IHalfEdge>(() => e2a), f3);
e5b = new LineHalfEdge("e5b", v6, new Lazy<IHalfEdge>(() => e5a), f3);
e10a = new LineHalfEdge("e10a", v7, new Lazy<IHalfEdge>(() => e10b), f3);
e6a = new LineHalfEdge("e6a", v3, new Lazy<IHalfEdge>(() => e6b), f3);
f3.Loops.Add(new EdgeLoop(e2b, e5b, e10a, e6a));
e3b = new LineHalfEdge("e3b", v3, new Lazy<IHalfEdge>(() => e3a), f4);
e6b = new LineHalfEdge("e6b", v7, new Lazy<IHalfEdge>(() => e6a), f4);
e11a = new LineHalfEdge("e11a", v4, new Lazy<IHalfEdge>(() => e11b), f4);
e7b = new LineHalfEdge("e7b", v0, new Lazy<IHalfEdge>(() => e7a), f4);
f4.Loops.Add(new EdgeLoop(e3b, e6b, e11a, e7b));
e8b = new LineHalfEdge("e8b", v4, new Lazy<IHalfEdge>(() => e8a), f5);
e11b = new LineHalfEdge("e11b", v7, new Lazy<IHalfEdge>(() => e11a), f5);
e10b = new LineHalfEdge("e10b", v6, new Lazy<IHalfEdge>(() => e10a), f5);
e9b = new LineHalfEdge("e9b", v5, new Lazy<IHalfEdge>(() => e9b), f5);
f5.Loops.Add(new EdgeLoop(e8b, e11b, e10b, e9b));
var shell = new Shell(f0,f1,f2,f3,f4,f5);
var data = new List<Vert>();
//.........這裏部分代碼省略.........