本文整理匯總了C#中SharpGL.OpenGL.DrawArrays方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.DrawArrays方法的具體用法?C# OpenGL.DrawArrays怎麽用?C# OpenGL.DrawArrays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.DrawArrays方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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);
}
}
示例2: RenderVertices_VertexArray
private void RenderVertices_VertexArray(OpenGL gl)
{
gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
gl.VertexPointer(3, 0, vertexArrayValues);
gl.DrawArrays(OpenGL.GL_POINTS, 0, 2);//vertices.Length);
gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
}
示例3: Draw
/// <summary>
/// Draws the scene.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void Draw(OpenGL gl)
{
// Clear the scene.
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);
// Bind the shader, set the matrices.
shaderProgram.Bind(gl);
shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
shaderProgram.SetUniformMatrix4(gl, "modelMatrix", modelMatrix.to_array());
// Bind the out vertex array.
vertexBufferArray.Bind(gl);
// Draw the square.
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 6);
// Unbind our vertex array and shader.
vertexBufferArray.Unbind(gl);
shaderProgram.Unbind(gl);
}
示例4: Draw
public override void Draw(OpenGL gl)
{
this.vertexBufferArray.Bind(gl);
gl.DrawArrays(OpenGL.GL_LINES, 0, this.lineCount*2);
this.vertexBufferArray.Unbind(gl);
}
示例5: RenderRetainedMode
/// <summary>
/// Renders the scene in retained mode.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void RenderRetainedMode(OpenGL gl)
{
// Use the shader program.
shaderPerPixel.Bind(gl);
// Set the light position.
shaderPerPixel.SetUniform3(gl, "LightPosition", 0.25f, 0.25f, 10f);
// Set the matrices.
shaderPerPixel.SetUniformMatrix4(gl, "Projection", projectionMatrix.to_array());
shaderPerPixel.SetUniformMatrix4(gl, "Modelview", modelviewMatrix.to_array());
shaderPerPixel.SetUniformMatrix3(gl, "NormalMatrix", normalMatrix.to_array());
// Go through each mesh and render the vertex buffer array.
foreach(var mesh in meshes)
{
// Set the variables for the shader program.
shaderPerPixel.SetUniform3(gl, "DiffuseMaterial", mesh.material.Diffuse.r, mesh.material.Diffuse.g, mesh.material.Diffuse.b);
shaderPerPixel.SetUniform3(gl, "AmbientMaterial", mesh.material.Ambient.r, mesh.material.Ambient.g, mesh.material.Ambient.b);
shaderPerPixel.SetUniform3(gl, "SpecularMaterial", mesh.material.Specular.r, mesh.material.Specular.g, mesh.material.Specular.b);
shaderPerPixel.SetUniform1(gl, "Shininess", mesh.material.Shininess);
var vertexBufferArray = meshVertexBufferArrays[mesh];
vertexBufferArray.Bind(gl);
// IMPORTANT: This is interesting. If you use OpenGL 2.1, you can use quads. If you move to 3.0 or onwards,
// you can only draw the triangle types - cause 3.0 onwards deprecates other types.
// see: http://stackoverflow.com/questions/8041361/simple-opengl-clarification
// this shows that the OpenGL mode selection works - if I choose 2.1 I can draw quads, otherwise I can't.
// There's a good article on tesselating quads to triangles here:
// http://prideout.net/blog/?p=49
// This should be a sample!
uint mode = OpenGL.GL_TRIANGLES;
if (mesh.indicesPerFace == 4)
mode = OpenGL.GL_QUADS;
else if (mesh.indicesPerFace > 4)
mode = OpenGL.GL_POLYGON;
gl.DrawArrays(mode, 0, mesh.vertices.Length);
}
// Unbind the shader.
shaderPerPixel.Unbind(gl);
}
示例6: runGlThread
private void runGlThread(object args)
{
var inputs = (Tuple<CancellationToken>) args;
var cancelToken = inputs.Item1;
var gl = new OpenGL();
int localRenderWidth = 1;
int localRenderHeight = 1;
if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
{
//TODO better error handling here
Console.WriteLine("*** Unable to create OpenGL Render Context");
return;
}
uint activeVaoHandle;
uint activeGlProgramHandle;
initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);
ActiveProgramValues localActiveProgramValues = null;
while (!cancelToken.IsCancellationRequested)
{
bool resizeRenderContext;
lock (this)
{
if (!ReferenceEquals(localActiveProgramValues, activeProgramValues))
{
localActiveProgramValues = activeProgramValues;
if (localActiveProgramValues.Valid)
{
linkProgram(gl, localActiveProgramValues, activeGlProgramHandle);
} else
{
// Leave the old program running. This prevents the user from seeing
// a black screen while they are in the process of modifying a shader.
}
}
resizeRenderContext = localRenderWidth != renderWidth || localRenderHeight != renderHeight;
localRenderWidth = renderWidth;
localRenderHeight = renderHeight;
}
if (resizeRenderContext)
{
localActiveProgramValues = null;
deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
{
//TODO better error handling here
Console.WriteLine("*** Unable to resize OpenGL Render Context");
return;
}
initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);
}
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT);
gl.BindVertexArray(activeVaoHandle);
gl.UseProgram(activeGlProgramHandle);
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
// do some other stuff while the image is rendering, to give it a chance to finish
ShaderCompiler.ValidateShaders(gl);
var provider = gl.RenderContextProvider as FBORenderContextProvider;
Debug.Assert(provider != null, "Render context provider is not an FBO renderer");
//TODO this call to blit will probably block. Find a better way to copy the image to CPU memory.
gl.Blit(IntPtr.Zero);
var hBitmap = provider.InternalDIBSection.HBitmap;
if (hBitmap != IntPtr.Zero)
{
var bitmap = GetFormattedBitmapSource(hBitmap);
// the bitmap needs to be frozen in order to share it between threads
bitmap.Freeze();
ImageRendered(bitmap);
}
}
deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
}
示例7: CreateAndPlotData
void CreateAndPlotData(OpenGL GL, float[] raw_data, int figureID)
{
if (_dataTail[figureID] + raw_data.Length >= C_SAMPLES_PER_FRAME)
{
_dataTail[figureID] = 0; // Clear the buffer
}
AddVerticesToFigure(figureID, raw_data, _dataTail[figureID]);
// Create the vertex array object.
vertexBufferArray = new VertexBufferArray();
vertexBufferArray.Create(GL);
vertexBufferArray.Bind(GL);
// Create a vertex buffer for the vertex data.
var vertexDataBuffer = new VertexBuffer();
vertexDataBuffer.Create(GL);
vertexDataBuffer.Bind(GL);
vertexDataBuffer.SetData(GL, attribute_vpos, _data[figureID], false, 3);
// Now do the same for the colour data.
var colourDataBuffer = new VertexBuffer();
colourDataBuffer.Create(GL);
colourDataBuffer.Bind(GL);
colourDataBuffer.SetData(GL, attribute_vcol, _dataColor[figureID], false, 3);
// Unbind the vertex array, we've finished specifying data for it.
vertexBufferArray.Unbind(GL);
// Bind the shader, set the matrices.
shaderProgram.Bind(GL);
//shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
//shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
shaderProgram.SetUniformMatrix4(GL, "modelMatrix", mviewdata.to_array());
// Bind the out vertex array.
vertexBufferArray.Bind(GL);
// Draw the square.
GL.DrawArrays(OpenGL.GL_LINE_STRIP, 0, _dataTail[figureID]);
// Unbind our vertex array and shader.
vertexBufferArray.Unbind(GL);
shaderProgram.Unbind(GL);
}
示例8: CreateAndDrawGrid
void CreateAndDrawGrid(OpenGL GL)
{
// Debug.WriteLine("Painting Begins..");
// Create vertices for 4 lines that will split the figure into 3 equal sections
xgrid = new vec3[(C_NUM_Y_DIV + 1) * 2];
for (int i = 0; i < (C_NUM_Y_DIV + 1) * 2; i = i + 2)
{
xgrid[i].x = -1f; xgrid[i + 1].x = 1f;
xgrid[i].y = C_X_MARGIN_MIN + C_Y_STEP * i / 2; xgrid[i + 1].y = C_X_MARGIN_MIN + C_Y_STEP * i / 2;
xgrid[i].z = 0f; xgrid[i + 1].z = 0f;
}
coldata = new vec3[] {
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White),
GL.Color(DR.Color.White)
};
mviewdata = new mat4(1.0f);
// --------------- Implementation WITH VERTEX ARRAY OBJECTS --------------------
//// Create the vertex array object.
vertexBufferArray = new VertexBufferArray();
vertexBufferArray.Create(GL);
vertexBufferArray.Bind(GL);
// Create a vertex buffer for the vertex data.
var vertexDataBuffer = new VertexBuffer();
vertexDataBuffer.Create(GL);
vertexDataBuffer.Bind(GL);
vertexDataBuffer.SetData(GL, attribute_vpos, xgrid, false, 3);
// Now do the same for the colour data.
var colourDataBuffer = new VertexBuffer();
colourDataBuffer.Create(GL);
colourDataBuffer.Bind(GL);
colourDataBuffer.SetData(GL, attribute_vcol, coldata, false, 3);
// Unbind the vertex array, we've finished specifying data for it.
vertexBufferArray.Unbind(GL);
// Bind the shader, set the matrices.
shaderProgram.Bind(GL);
//shaderProgram.SetUniformMatrix4(gl, "projectionMatrix", projectionMatrix.to_array());
//shaderProgram.SetUniformMatrix4(gl, "viewMatrix", viewMatrix.to_array());
shaderProgram.SetUniformMatrix4(GL, "modelview", mviewdata.to_array());
// Bind the out vertex array.
vertexBufferArray.Bind(GL);
GL.DrawArrays(OpenGL.GL_LINES, 0, 8);
// Unbind our vertex array and shader.
vertexBufferArray.Unbind(GL);
shaderProgram.Unbind(GL);
// --------------- Implementation WITH VERTEX ARRAY OBJECTS END --------------------
}
示例9: Draw
public override void Draw(OpenGL gl)
{
this.vertexBufferArray.Bind(gl);
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.cells.Count * 6); //cells.Count * 4);
this.vertexBufferArray.Unbind(gl);
}
示例10: 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);
}
}
示例11: 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);
}
}
示例12: 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.BindVAO(gl);
gl.LineWidth(group.LineWidth);
// Use draw elements if an index buffer is defined. Else use draw arrays.
if (group.IndicesCount > 0)
gl.DrawElements(OpenGL.GL_LINES, group.IndicesCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
else
gl.DrawArrays(OpenGL.GL_LINES, 0, group.VerticesCount);
}
});
}
示例13: drawModel
/// <summary>
/// Function to draw the model
/// </summary>
private void drawModel(OpenGL gl)
{
if(l_vboId != null)
{
gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
gl.EnableClientState(OpenGL.GL_COLOR_ARRAY);
// itering over each list of points
for(int k = 0; k < l_vboId.Count; k++)
{
gl.PushMatrix();
//transformations
gl.Scale(1.0f / f_scale, 1.0f / f_scale, 1.0f / f_scale);
gl.Translate(-v_center.X, -v_center.Y, -v_center.Z);
//vertexes
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][0]);
gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
//color
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, l_vboId[k][1]);
gl.ColorPointer(3, OpenGL.GL_FLOAT, 0, BUFFER_OFFSET_ZERO);
//draw l_sizes[k] points
gl.DrawArrays(OpenGL.GL_POINTS, 0, l_sizes[k]);
gl.PopMatrix();
}
gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
gl.DisableClientState(OpenGL.GL_COLOR_ARRAY);
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);
}
}