本文整理匯總了C#中SharpGL.OpenGL.DrawElements方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.DrawElements方法的具體用法?C# OpenGL.DrawElements怎麽用?C# OpenGL.DrawElements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.DrawElements方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: draw
public void draw(OpenGL gl)
{
if (net)
gl.CullFace(OpenGL.GL_FRONT);
else
gl.CullFace(OpenGL.GL_BACK);
if (vertices != null)
{
gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, vertices);
}
if (normals != null)
{
gl.EnableClientState(OpenGL.GL_NORMAL_ARRAY);
gl.NormalPointer(OpenGL.GL_FLOAT, 0, normals);
}
if (colors != null)
{
gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
gl.ColorPointer(3, OpenGL.GL_UNSIGNED_BYTE, 0, colors);
}
if (textCoords != null)
{
gl.EnableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);
gl.TexCoordPointer(2, OpenGL.GL_FLOAT, 0, textCoords);
}
gl.FrontFace(OpenGL.GL_CCW);
if (lengths != null && strips != null)
for (int i = 0; i < strips.Count; i++)
{
gl.DrawElements(OpenGL.GL_TRIANGLE_STRIP, lengths[i], OpenGL.GL_UNSIGNED_INT, strips[i]);
}
if (doubleSurface)
{
if (doubleNormals != null)
{
gl.NormalPointer(OpenGL.GL_FLOAT, 0, doubleNormals);
}
gl.FrontFace(OpenGL.GL_CW);
for (int i = 0; i < strips.Count; i++)
{
gl.DrawElements(OpenGL.GL_TRIANGLE_STRIP, lengths[i], OpenGL.GL_UNSIGNED_INT, strips[i]);
}
}
gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
gl.DisableClientState(OpenGL.GL_NORMAL_ARRAY);
gl.DisableClientState(OpenGL.GL_TEXTURE_COORD_ARRAY);
}
示例3: BindAll
public void BindAll(OpenGL gl)
{
UseProgram(gl, () =>
{
// Update uniforms.
foreach (var action in ChangedUniforms)
{
action.Invoke(gl);
}
ChangedUniforms.Clear();
foreach (var group in BufferGroups)
{
group.BindVAO(gl);
gl.DrawElements(OpenGL.GL_TRIANGLES, group.IndicesCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.BindVertexArray(0);
}
});
}
示例4: DrawTrefoilCelShaded
private void DrawTrefoilCelShaded(OpenGL gl)
{
// Use the shader program.
gl.UseProgram(shaderProgram.ProgramObject);
// Set the variables for the shader program.
gl.Uniform3(toonUniforms.DiffuseMaterial, 0f, 0.75f, 0.75f);
gl.Uniform3(toonUniforms.AmbientMaterial, 0.04f, 0.04f, 0.04f);
gl.Uniform3(toonUniforms.SpecularMaterial, 0.5f, 0.5f, 0.5f);
gl.Uniform1(toonUniforms.Shininess, 50f);
// Set the light position.
gl.Uniform3(toonUniforms.LightPosition, 1, new float[4] { 0.25f, 0.25f, 1f, 0f });
// Set the matrices.
gl.UniformMatrix4(toonUniforms.Projection, 1, false, projection.AsColumnMajorArrayFloat);
gl.UniformMatrix4(toonUniforms.Modelview, 1, false, modelView.AsColumnMajorArrayFloat);
gl.UniformMatrix3(toonUniforms.NormalMatrix, 1, false, normalMatrix.AsColumnMajorArrayFloat);
// Bind the vertex and index buffer.
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBuffer);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.EnableVertexAttribArray(attrPosition);
gl.EnableVertexAttribArray(attrNormal);
// Draw the geometry, straight from the vertex buffer.
gl.VertexAttribPointer(attrPosition, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Zero);
int normalOffset = Marshal.SizeOf(typeof(Vertex));
gl.VertexAttribPointer(attrNormal, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Add(new IntPtr(0), normalOffset));
gl.DrawElements(OpenGL.GL_TRIANGLES, (int)trefoilKnot.IndexCount, OpenGL.GL_UNSIGNED_SHORT, IntPtr.Zero);
}
示例5: DrawTrefoilBuffers
private void DrawTrefoilBuffers(OpenGL gl)
{
// Bind the vertex and index buffer.
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBuffer);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.EnableVertexAttribArray(attrPosition);
gl.EnableVertexAttribArray(attrNormal);
// Draw the geometry, straight from the vertex buffer.
gl.VertexAttribPointer(attrPosition, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Zero);
int normalOffset = Marshal.SizeOf(typeof(Vertex));
gl.VertexAttribPointer(attrNormal, 3, OpenGL.GL_FLOAT, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Add(new IntPtr(0), normalOffset));
gl.DrawElements(OpenGL.GL_LINES, (int)trefoilKnot.IndexCount, OpenGL.GL_UNSIGNED_SHORT, IntPtr.Zero);
}
示例6: BindAll
public void BindAll(OpenGL gl)
{
//return;
UseProgram(gl, () =>
{
// Update uniforms.
foreach (var action in ChangedUniforms)
{
action.Invoke(gl);
}
ChangedUniforms.Clear();
foreach (var group in BufferGroups)
{
group.BindHTVAO(gl);
// Use draw elements if an index buffer is defined. Else use draw arrays.
if (group.IndicesCount > 0)
gl.DrawElements(OpenGL.GL_TRIANGLES, group.IndicesCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
}
});
}
示例7: 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);
}
}
示例8: RenderRetainedMode
/// <summary>
/// Renders the scene in retained mode.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
/// <param name="useToonShader">if set to <c>true</c> use the toon shader, otherwise use a per-pixel shader.</param>
public void RenderRetainedMode(OpenGL gl, bool useToonShader)
{
// Get a reference to the appropriate shader.
var shader = useToonShader ? shaderToon : shaderPerPixel;
// Use the shader program.
shader.Bind(gl);
// Set the variables for the shader program.
shader.SetUniform3(gl, "DiffuseMaterial", 0f, 0.75f, 0.75f);
shader.SetUniform3(gl, "AmbientMaterial", 0.04f, 0.04f, 0.04f);
shader.SetUniform3(gl, "SpecularMaterial", 0.5f, 0.5f, 0.5f);
shader.SetUniform1(gl, "Shininess", 50f);
// Set the light position.
shader.SetUniform3(gl, "LightPosition", 0.25f, 0.25f, 1f);
// Set the matrices.
shader.SetUniformMatrix4(gl, "Projection", projectionMatrix.to_array());
shader.SetUniformMatrix4(gl, "Modelview", modelviewMatrix.to_array());
shader.SetUniformMatrix3(gl, "NormalMatrix", normalMatrix.to_array());
// Bind the vertex buffer array.
trefoilKnot.VertexBufferArray.Bind(gl);
// Draw the elements.
gl.DrawElements(OpenGL.GL_TRIANGLES, trefoilKnot.Indices.Length, OpenGL.GL_UNSIGNED_SHORT, IntPtr.Zero);
// Unbind the shader.
shader.Unbind(gl);
}