本文整理汇总了C#中SharpGL.OpenGL.UseProgram方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.UseProgram方法的具体用法?C# OpenGL.UseProgram怎么用?C# OpenGL.UseProgram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.UseProgram方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: UseProgram
/// <summary>
/// Calls glUseProgram(ShaderProgramId) -> invokes executeInProgram-Action -> unbinds program using glUseProgram(0).
/// </summary>
/// <param name="gl"></param>
/// <param name="executeInProgram">The logic to be executed for this shader program.</param>
public void UseProgram(OpenGL gl, Action executeInProgram)
{
// Bind.
gl.UseProgram(ShaderProgramId);
// Make sure the program unbinds, even if a problem should occur.
try
{
// Invoke logic.
executeInProgram.Invoke();
}
catch (Exception ex)
{
throw ex;
}
finally
{
// Unbind.
gl.UseProgram(0);
ProgramIsBound = false;
}
}