本文整理汇总了C#中OpenGL类的典型用法代码示例。如果您正苦于以下问题:C# OpenGL类的具体用法?C# OpenGL怎么用?C# OpenGL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenGL类属于命名空间,在下文中一共展示了OpenGL类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Push
/// <summary>
/// Pushes this object into the provided OpenGL instance.
/// This will generally push elements of the attribute stack
/// and then set current values.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public virtual void Push(OpenGL gl)
{
// Push texture attributes.
gl.PushAttrib(Enumerations.AttributeMask.Texture);
// Bind the texture.
Bind(gl);
}
开发者ID:hhool,项目名称:sharpgl,代码行数:14,代码来源:Texture.cs
示例2: SetData
public void SetData(OpenGL gl, uint attributeIndex, float[] rawData, bool isNormalised, int stride)
{
// Set the data, specify its shape and assign it to a vertex attribute (so shaders can bind to it).
gl.BufferData(OpenGL.GL_ARRAY_BUFFER, rawData, OpenGL.GL_STATIC_DRAW);
gl.VertexAttribPointer(attributeIndex, stride, OpenGL.GL_FLOAT, isNormalised, 0, IntPtr.Zero);
gl.EnableVertexAttribArray(attributeIndex);
}
开发者ID:hhool,项目名称:sharpgl,代码行数:7,代码来源:VertexBuffer.cs
示例3: SetAttributes
/// <summary>
/// Sets the attributes.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public override void SetAttributes(OpenGL gl)
{
if(enableAlphaTest.HasValue) gl.EnableIf(OpenGL.GL_ALPHA_TEST,enableAlphaTest.Value);
if(enableAutoNormal.HasValue) gl.EnableIf(OpenGL.GL_AUTO_NORMAL,enableAutoNormal.Value);
if(enableBlend.HasValue) gl.EnableIf(OpenGL.GL_BLEND,enableBlend.Value);
if(enableCullFace.HasValue) gl.EnableIf(OpenGL.GL_CULL_FACE,enableCullFace.Value);
if(enableDepthTest.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_TEST,enableDepthTest.Value);
if(enableDither.HasValue) gl.EnableIf(OpenGL.GL_DITHER,enableDither.Value);
if(enableFog.HasValue) gl.EnableIf(OpenGL.GL_FOG,enableFog.Value);
if(enableLighting.HasValue) gl.EnableIf(OpenGL.GL_LIGHTING,enableLighting.Value);
if(enableLineSmooth.HasValue) gl.EnableIf(OpenGL.GL_LINE_SMOOTH,enableLineSmooth.Value);
if(enableLineStipple.HasValue) gl.EnableIf(OpenGL.GL_LINE_STIPPLE,enableLineStipple.Value);
if(enableColorLogicOp.HasValue) gl.EnableIf(OpenGL.GL_COLOR_LOGIC_OP,enableColorLogicOp.Value);
if(enableIndexLogicOp.HasValue) gl.EnableIf(OpenGL.GL_INDEX_LOGIC_OP,enableIndexLogicOp.Value);
if(enableNormalize.HasValue) gl.EnableIf(OpenGL.GL_NORMALIZE,enableNormalize.Value);
if(enablePointSmooth.HasValue) gl.EnableIf(OpenGL.GL_POINT_SMOOTH,enablePointSmooth.Value);
if(enablePolygonOffsetLine.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_OFFSET_LINE,enablePolygonOffsetLine.Value);
if(enablePolygonOffsetFill.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_OFFSET_FILL,enablePolygonOffsetFill.Value);
if(enablePolygonOffsetPoint.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_OFFSET_POINT,enablePolygonOffsetPoint.Value);
if(enablePolygonSmooth.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_SMOOTH,enablePolygonSmooth.Value);
if(enablePolygonStipple.HasValue) gl.EnableIf(OpenGL.GL_POLYGON_STIPPLE,enablePolygonStipple.Value);
if(enableScissorTest.HasValue) gl.EnableIf(OpenGL.GL_SCISSOR_TEST,enableScissorTest.Value);
if(enableStencilTest.HasValue) gl.EnableIf(OpenGL.GL_STENCIL,enableStencilTest.Value);
if(enableTexture1D.HasValue) gl.EnableIf(OpenGL.GL_TEXTURE_1D,enableTexture1D.Value);
if (enableTexture2D.HasValue) gl.EnableIf(OpenGL.GL_TEXTURE_2D, enableTexture2D.Value);
}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:30,代码来源:EnableAttributes.cs
示例4: CreateDisplayList
/// <summary>
/// Creates the display list. This function draws the
/// geometry as well as compiling it.
/// </summary>
private void CreateDisplayList(OpenGL gl)
{
// Create the display list.
displayList = new DisplayList();
// Generate the display list and
displayList.Generate(gl);
displayList.New(gl, DisplayList.DisplayListMode.CompileAndExecute);
// Push attributes, set the color.
gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
OpenGL.GL_LINE_BIT);
gl.Disable(OpenGL.GL_LIGHTING);
gl.Disable(OpenGL.GL_TEXTURE_2D);
gl.LineWidth(1.0f);
// Draw the grid lines.
gl.Begin(OpenGL.GL_LINES);
for (int i = -10; i <= 10; i++)
{
float fcol = ((i % 10) == 0) ? 0.3f : 0.15f;
gl.Color(fcol, fcol, fcol);
gl.Vertex(i, -10, 0);
gl.Vertex(i, 10, 0);
gl.Vertex(-10, i, 0);
gl.Vertex(10, i, 0);
}
gl.End();
// Restore attributes.
gl.PopAttrib();
// End the display list.
displayList.End(gl);
}
开发者ID:chantsunman,项目名称:sharpgl,代码行数:39,代码来源:Grid.cs
示例5: SetAttributes
/// <summary>
/// Sets the attributes.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public override void SetAttributes(OpenGL gl)
{
if (viewportX.HasValue && viewportY.HasValue && viewportWidth.HasValue && viewportHeight.HasValue)
gl.Viewport(viewportX.Value, viewportY.Value, viewportWidth.Value, viewportHeight.Value);
if (depthRangeNear.HasValue && depthRangeFar.HasValue)
gl.DepthRange(depthRangeNear.Value, depthRangeFar.Value);
}
开发者ID:hhool,项目名称:sharpgl,代码行数:11,代码来源:ViewportAttributes.cs
示例6: Render
/// <summary>
/// Render to the provided instance of OpenGL.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
/// <param name="renderMode">The render mode.</param>
public override void Render(OpenGL gl, Core.RenderMode renderMode)
{
base.Render(gl, renderMode);
// Begin drawing a NURBS surface.
gl.BeginSurface(nurbsRenderer);
// Draw the surface.
gl.NurbsSurface(nurbsRenderer, // The internal nurbs object.
sKnots.Length, // Number of s-knots.
sKnots, // The s-knots themselves.
tKnots.Length, // The number of t-knots.
tKnots, // The t-knots themselves.
ControlPoints.Width * 3, // The size of a row of control points.
3, // The size of a control points.
ControlPoints.ToFloatArray(), // The control points.
ControlPoints.Width, // The order, i.e degree + 1.
ControlPoints.Height, // The order, i.e degree + 1.
OpenGL.GL_MAP2_VERTEX_3); // Type of data to generate.
// End the surface.
gl.EndSurface(nurbsRenderer);
// Draw the control points.
ControlPoints.Draw(gl, DrawControlPoints, DrawControlGrid);
}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:31,代码来源:NurbsSurface.cs
示例7: Create
public void Create(OpenGL gl)
{
// Generate the vertex array.
uint[] ids = new uint[1];
gl.GenVertexArrays(1, ids);
vertexArrayObject = ids[0];
}
开发者ID:hhool,项目名称:sharpgl,代码行数:7,代码来源:VertexBufferArray.cs
示例8: UpdateContextVersion
/// <summary>
/// Only valid to be called after the render context is created, this function attempts to
/// move the render context to the OpenGL version originally requested. If this is > 2.1, this
/// means building a new context. If this fails, we'll have to make do with 2.1.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
protected void UpdateContextVersion(OpenGL gl)
{
// If the request version number is anything up to and including 2.1, standard render contexts
// will provide what we need (as long as the graphics card drivers are up to date).
var requestedVersionNumber = VersionAttribute.GetVersionAttribute(requestedOpenGLVersion);
if (requestedVersionNumber.IsAtLeastVersion(3, 0) == false)
{
createdOpenGLVersion = requestedOpenGLVersion;
return;
}
// Now the none-trivial case. We must use the WGL_ARB_create_context extension to
// attempt to create a 3.0+ context.
try
{
int[] attributes =
{
OpenGL.WGL_CONTEXT_MAJOR_VERSION_ARB, requestedVersionNumber.Major,
OpenGL.WGL_CONTEXT_MINOR_VERSION_ARB, requestedVersionNumber.Minor,
OpenGL.WGL_CONTEXT_FLAGS_ARB, OpenGL.WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0
};
var hrc = gl.CreateContextAttribsARB(IntPtr.Zero, attributes);
Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
Win32.wglDeleteContext(renderContextHandle);
Win32.wglMakeCurrent(deviceContextHandle, hrc);
renderContextHandle = hrc;
}
catch(Exception)
{
// TODO: can we actually get the real version?
createdOpenGLVersion = OpenGLVersion.OpenGL2_1;
}
}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:40,代码来源:RenderContextProvider.cs
示例9: Create
/// <summary>
/// Creates the shader program.
/// </summary>
/// <param name="gl">The gl.</param>
/// <param name="vertexShaderSource">The vertex shader source.</param>
/// <param name="fragmentShaderSource">The fragment shader source.</param>
/// <param name="attributeLocations">The attribute locations. This is an optional array of
/// uint attribute locations to their names.</param>
/// <exception cref="ShaderCompilationException"></exception>
public void Create(OpenGL gl, string vertexShaderSource, string fragmentShaderSource,
Dictionary<uint, string> attributeLocations)
{
// Create the shaders.
vertexShader.Create(gl, OpenGL.GL_VERTEX_SHADER, vertexShaderSource);
fragmentShader.Create(gl, OpenGL.GL_FRAGMENT_SHADER, fragmentShaderSource);
// Create the program, attach the shaders.
shaderProgramObject = gl.CreateProgram();
gl.AttachShader(shaderProgramObject, vertexShader.ShaderObject);
gl.AttachShader(shaderProgramObject, fragmentShader.ShaderObject);
// Before we link, bind any vertex attribute locations.
if (attributeLocations != null)
{
foreach (var vertexAttributeLocation in attributeLocations)
gl.BindAttribLocation(shaderProgramObject, vertexAttributeLocation.Key, vertexAttributeLocation.Value);
}
// Now we can link the program.
gl.LinkProgram(shaderProgramObject);
// Now that we've compiled and linked the shader, check it's link status. If it's not linked properly, we're
// going to throw an exception.
if (GetLinkStatus(gl) == false)
{
throw new ShaderCompilationException(string.Format("Failed to link shader program with ID {0}.", shaderProgramObject), GetInfoLog(gl));
}
}
开发者ID:hhool,项目名称:sharpgl,代码行数:38,代码来源:ShaderProgram.cs
示例10: Initialise
/// <summary>
/// Initialises the Scene.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void Initialise(OpenGL gl)
{
// We're going to specify the attribute locations for the position and normal,
// so that we can force both shaders to explicitly have the same locations.
const uint positionAttribute = 0;
const uint normalAttribute = 1;
var attributeLocations = new Dictionary<uint, string>
{
{positionAttribute, "Position"},
{normalAttribute, "Normal"},
};
// Create the per pixel shader.
shaderPerPixel = new ShaderProgram();
shaderPerPixel.Create(gl,
ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.vert"),
ManifestResourceLoader.LoadTextFile(@"Shaders\PerPixel.frag"), attributeLocations);
// Create the toon shader.
shaderToon = new ShaderProgram();
shaderToon.Create(gl,
ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.vert"),
ManifestResourceLoader.LoadTextFile(@"Shaders\Toon.frag"), attributeLocations);
// Generate the geometry and it's buffers.
trefoilKnot.GenerateGeometry(gl, positionAttribute, normalAttribute);
}
开发者ID:chantsunman,项目名称:sharpgl,代码行数:31,代码来源:Scene.cs
示例11: SetAttributes
/// <summary>
/// Sets the attributes.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public override void SetAttributes(OpenGL gl)
{
if (enableDepthTest.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_TEST, enableDepthTest.Value);
if (depthFunction.HasValue) gl.DepthFunc(depthFunction.Value);
if (depthClearValue.HasValue) gl.ClearDepth(depthClearValue.Value);
if (enableDepthWritemask.HasValue) gl.EnableIf(OpenGL.GL_DEPTH_WRITEMASK, enableDepthWritemask.Value);
}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:11,代码来源:DepthBufferAttributes.cs
示例12: SetAttributes
/// <summary>
/// Sets the attributes.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public override void SetAttributes(OpenGL gl)
{
if(enableAlphaTest.HasValue && alphaTestFunction.HasValue && alphaTestReferenceValue.HasValue)
{
gl.EnableIf(OpenGL.GL_ALPHA_TEST, enableAlphaTest.Value);
gl.AlphaFunc(alphaTestFunction.Value, alphaTestReferenceValue.Value);
}
if(enableBlend.HasValue && blendingSourceFactor.HasValue && blendingDestinationFactor.HasValue)
{
gl.EnableIf(OpenGL.GL_BLEND, enableBlend.Value);
gl.BlendFunc(blendingSourceFactor.Value, blendingDestinationFactor.Value);
}
if(enableDither.HasValue) gl.EnableIf(OpenGL.GL_DITHER, enableDither.Value);
if(drawBufferMode.HasValue) gl.DrawBuffer(drawBufferMode.Value);
if(enableLogicOp.HasValue && logicOp.HasValue)
{
gl.EnableIf(OpenGL.GL_COLOR_LOGIC_OP, enableLogicOp.Value);
gl.LogicOp(logicOp.Value);
}
if(colorModeClearColor != null) gl.ClearColor(colorModeClearColor.R, colorModeClearColor.G, colorModeClearColor.B, colorModeClearColor.A);
//todowritemask
}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:29,代码来源:ColorBufferAttributes.cs
示例13: Create
/// <summary>
/// Creates the render context provider. Must also create the OpenGL extensions.
/// </summary>
/// <param name="openGLVersion">The desired OpenGL version.</param>
/// <param name="gl">The OpenGL context.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="bitDepth">The bit depth.</param>
/// <param name="parameter">The extra parameter.</param>
/// <returns></returns>
public override bool Create(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter)
{
// Call the base.
base.Create(openGLVersion, gl, width, height, bitDepth, parameter);
// Get the desktop DC.
IntPtr desktopDC = Win32.GetDC(IntPtr.Zero);
// Create our DC as a compatible DC for the desktop.
deviceContextHandle = Win32.CreateCompatibleDC(desktopDC);
// Release the desktop DC.
Win32.ReleaseDC(IntPtr.Zero, desktopDC);
// Create our dib section.
dibSection.Create(deviceContextHandle, width, height, bitDepth);
// Create the render context.
Win32.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
renderContextHandle = Win32.wglCreateContext(deviceContextHandle);
// Make current.
MakeCurrent();
// Update the context if required.
UpdateContextVersion(gl);
// Return success.
return true;
}
开发者ID:chantsunman,项目名称:sharpgl,代码行数:40,代码来源:DIBSectionRenderContextProvider.cs
示例14: Create
public void Create(OpenGL gl)
{
// Generate the vertex array.
uint[] ids = new uint[1];
gl.GenBuffers(1, ids);
bufferObject = ids[0];
}
开发者ID:hhool,项目名称:sharpgl,代码行数:7,代码来源:IndexBuffer.cs
示例15: Initialise
/// <summary>
/// Initialises the scene.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
/// <param name="width">The width of the screen.</param>
/// <param name="height">The height of the screen.</param>
public void Initialise(OpenGL gl, float width, float height)
{
// Set a blue clear colour.
gl.ClearColor(0.4f, 0.6f, 0.9f, 0.0f);
// Create the shader program.
var vertexShaderSource = ManifestResourceLoader.LoadTextFile("Shader.vert");
var fragmentShaderSource = ManifestResourceLoader.LoadTextFile("Shader.frag");
shaderProgram = new ShaderProgram();
shaderProgram.Create(gl, vertexShaderSource, fragmentShaderSource, null);
shaderProgram.BindAttributeLocation(gl, attributeIndexPosition, "in_Position");
shaderProgram.BindAttributeLocation(gl, attributeIndexColour, "in_Color");
shaderProgram.AssertValid(gl);
// Create a perspective projection matrix.
const float rads = (60.0f / 360.0f) * (float)Math.PI * 2.0f;
projectionMatrix = glm.perspective(rads, width / height, 0.1f, 100.0f);
// Create a view matrix to move us back a bit.
viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));
// Create a model matrix to make the model a little bigger.
modelMatrix = glm.scale(new mat4(1.0f), new vec3(2.5f));
// Now create the geometry for the square.
CreateVerticesForSquare(gl);
}
开发者ID:chantsunman,项目名称:sharpgl,代码行数:33,代码来源:Scene.cs
示例16: SetAttributes
/// <summary>
/// Sets the attributes.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public override void SetAttributes(OpenGL gl)
{
if (enable.HasValue) gl.EnableIf(OpenGL.GL_LIGHTING, enable.Value);
if (ambientLight != null) gl.LightModel(LightModelParameter.Ambient, ambientLight);
if (localViewer.HasValue) gl.LightModel(LightModelParameter.LocalViewer, localViewer.Value == true ? 1 : 0);
if (twoSided.HasValue) gl.LightModel(LightModelParameter.TwoSide, twoSided.Value == true ? 1 : 0);
}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:11,代码来源:LightingAttributes.cs
示例17: DestroyInContext
/// <summary>
/// Destroy in the context of the supplied OpenGL instance.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void DestroyInContext(OpenGL gl)
{
// Delete the shader.
gl.DeleteProgram(ProgramObject);
ProgramObject = 0;
CurrentOpenGLContext = null;
}
开发者ID:cvanherk,项目名称:3d-engine,代码行数:11,代码来源:ShaderProgram.cs
示例18: Render
/// <summary>
/// Render to the provided instance of OpenGL.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
/// <param name="renderMode">The render mode.</param>
public override void Render(OpenGL gl, RenderMode renderMode)
{
// Create the evaluator.
gl.Map1(OpenGL.GL_MAP1_VERTEX_3,// Use and produce 3D points.
0, // Low order value of 'u'.
1, // High order value of 'u'.
3, // Size (bytes) of a control point.
ControlPoints.Width, // Order (i.e degree plus one).
ControlPoints.ToFloatArray()); // The control points.
// Enable the type of evaluator we wish to use.
gl.Enable(OpenGL.GL_MAP1_VERTEX_3);
// Beging drawing a line strip.
gl.Begin(OpenGL.GL_LINE_STRIP);
// Now draw it.
for (int i = 0; i <= segments; i++)
gl.EvalCoord1((float)i / segments);
gl.End();
// Draw the control points.
ControlPoints.Draw(gl, DrawControlPoints, DrawControlGrid);
}
开发者ID:hhool,项目名称:sharpgl,代码行数:30,代码来源:Evaluator1D.cs
示例19: Create
public void Create(OpenGL gl)
{
// Generate the texture object array.
uint[] ids = new uint[1];
gl.GenTextures(1, ids);
textureObject = ids[0];
}
开发者ID:hhool,项目名称:sharpgl,代码行数:7,代码来源:Texture2D.cs
示例20: DestroyInContext
/// <summary>
/// Destroy in the context of the supplied OpenGL instance.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void DestroyInContext(OpenGL gl)
{
// Delete the shader.
gl.DeleteShader(ShaderObject);
ShaderObject = 0;
CurrentOpenGLContext = null;
}
开发者ID:hhool,项目名称:sharpgl,代码行数:11,代码来源:Shader.cs
注:本文中的OpenGL类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论