本文整理汇总了C#中OpenGL.PushAttrib方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.PushAttrib方法的具体用法?C# OpenGL.PushAttrib怎么用?C# OpenGL.PushAttrib使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenGL
的用法示例。
在下文中一共展示了OpenGL.PushAttrib方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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);
}
示例3: 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 lighting and texture attributes.
gl.PushAttrib(Enumerations.AttributeMask.Lighting | Enumerations.AttributeMask.Texture);
// Bind the material.
Bind(gl);
}
示例4: 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 lighting attributes.
gl.PushAttrib(Enumerations.AttributeMask.Lighting);
// Bind the light.
Bind(gl);
}
示例5: Push
/// <summary>
/// Pushes the effect onto the specified parent element.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
/// <param name="parentElement">The parent element.</param>
public override void Push(OpenGL gl, SceneElement parentElement)
{
// Create a combined mask.
AttributeMask attributeFlags = AttributeMask.None;
attributeFlags &= accumBufferAttributes.AreAnyAttributesSet() ? accumBufferAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= colorBufferAttributes.AreAnyAttributesSet() ? colorBufferAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= currentAttributes.AreAnyAttributesSet() ? currentAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= depthBufferAttributes.AreAnyAttributesSet() ? depthBufferAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= enableAttributes.AreAnyAttributesSet() ? enableAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= fogAttributes.AreAnyAttributesSet() ? fogAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= lightingAttributes.AreAnyAttributesSet() ? lightingAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= lineAttributes.AreAnyAttributesSet() ? lineAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= pointAttributes.AreAnyAttributesSet() ? pointAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= polygonAttributes.AreAnyAttributesSet() ? polygonAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= evalAttributes.AreAnyAttributesSet() ? evalAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= hintAttributes.AreAnyAttributesSet() ? hintAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= listAttributes.AreAnyAttributesSet() ? listAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= pixelModeAttributes.AreAnyAttributesSet() ? pixelModeAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= polygonStippleAttributes.AreAnyAttributesSet() ? polygonStippleAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= scissorAttributes.AreAnyAttributesSet() ? scissorAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= stencilBufferAttributes.AreAnyAttributesSet() ? stencilBufferAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= textureAttributes.AreAnyAttributesSet() ? textureAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= transformAttributes.AreAnyAttributesSet() ? transformAttributes.AttributeFlags : AttributeMask.None;
attributeFlags &= viewportAttributes.AreAnyAttributesSet() ? viewportAttributes.AttributeFlags : AttributeMask.None;
// Push the attribute stack.
gl.PushAttrib((uint)attributeFlags);
// Set the attributes.
accumBufferAttributes.SetAttributes(gl);
colorBufferAttributes.SetAttributes(gl);
currentAttributes.SetAttributes(gl);
depthBufferAttributes.SetAttributes(gl);
enableAttributes.SetAttributes(gl);
fogAttributes.SetAttributes(gl);
lightingAttributes.SetAttributes(gl);
lineAttributes.SetAttributes(gl);
pointAttributes.SetAttributes(gl);
polygonAttributes.SetAttributes(gl);
evalAttributes.SetAttributes(gl);
hintAttributes.SetAttributes(gl);
listAttributes.SetAttributes(gl);
pixelModeAttributes.SetAttributes(gl);
polygonStippleAttributes.SetAttributes(gl);
scissorAttributes.SetAttributes(gl);
stencilBufferAttributes.SetAttributes(gl);
textureAttributes.SetAttributes(gl);
transformAttributes.SetAttributes(gl);
viewportAttributes.SetAttributes(gl);
}
示例6: 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 all attributes, disable lighting and depth testing.
gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
OpenGL.GL_LINE_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.Disable(OpenGL.GL_LIGHTING);
gl.Disable(OpenGL.GL_TEXTURE_2D);
gl.DepthFunc(OpenGL.GL_ALWAYS);
// Set a nice fat line width.
gl.LineWidth(1.50f);
// Draw the axies.
gl.Begin(OpenGL.GL_LINES);
gl.Color(1f, 0f, 0f, 1f);
gl.Vertex(0, 0, 0);
gl.Vertex(3, 0, 0);
gl.Color(0f, 1f, 0f, 1f);
gl.Vertex(0, 0, 0);
gl.Vertex(0, 3, 0);
gl.Color(0f, 0f, 1f, 1f);
gl.Vertex(0, 0, 0);
gl.Vertex(0, 0, 3);
gl.End();
// Restore attributes.
gl.PopAttrib();
// End the display list.
displayList.End(gl);
}
示例7: 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 void Render(OpenGL gl, RenderMode renderMode)
{
// Push attributes, disable lighting.
gl.PushAttrib(OpenGL.GL_CURRENT_BIT | OpenGL.GL_ENABLE_BIT |
OpenGL.GL_LINE_BIT | OpenGL.GL_POLYGON_BIT);
gl.Disable(OpenGL.GL_LIGHTING);
gl.Disable(OpenGL.GL_TEXTURE_2D);
gl.LineWidth(1.0f);
gl.Color(1f, 0.2f, 0.2f, 0.6f);
gl.PolygonMode(OpenGL.GL_FRONT_AND_BACK,
renderMode == RenderMode.HitTest ? (uint)PolygonMode.Filled : (uint)PolygonMode.Lines);
gl.Begin(OpenGL.GL_QUADS); // Draw The Cube Using quads
gl.Vertex(hhl); // Top Right Of The Quad (Top)
gl.Vertex(lhl); // Top Left Of The Quad (Top)
gl.Vertex(lhh); // Bottom Left Of The Quad (Top)
gl.Vertex(hhh); // Bottom Right Of The Quad (Top)
gl.Vertex(hlh); // Top Right Of The Quad (Bottom)
gl.Vertex(llh); // Top Left Of The Quad (Bottom)
gl.Vertex(lll); // Bottom Left Of The Quad (Bottom)
gl.Vertex(hll); // Bottom Right Of The Quad (Bottom)
gl.Vertex(hhh); // Top Right Of The Quad (Front)
gl.Vertex(lhh); // Top Left Of The Quad (Front)
gl.Vertex(llh); // Bottom Left Of The Quad (Front)
gl.Vertex(hlh); // Bottom Right Of The Quad (Front)
gl.Vertex(hll); // Top Right Of The Quad (Back)
gl.Vertex(lll); // Top Left Of The Quad (Back)
gl.Vertex(lhl); // Bottom Left Of The Quad (Back)
gl.Vertex(hhl); // Bottom Right Of The Quad (Back)
gl.Vertex(lhh); // Top Right Of The Quad (Left)
gl.Vertex(lhl); // Top Left Of The Quad (Left)
gl.Vertex(lll); // Bottom Left Of The Quad (Left)
gl.Vertex(llh); // Bottom Right Of The Quad (Left)
gl.Vertex(hhl); // Top Right Of The Quad (Right)
gl.Vertex(hhh); // Top Left Of The Quad (Right)
gl.Vertex(hlh); // Bottom Left Of The Quad (Right)
gl.Vertex(hll); // Bottom Right Of The Quad (Right)
gl.End(); // End Drawing The Cube
// Pop attributes.
gl.PopAttrib();
}
示例8: CastShadow
/// <summary>
/// Casts a real time 3D shadow.
/// </summary>
/// <param name="gl">The OpenGL object.</param>
/// <param name="lights">The lights.</param>
private void CastShadow(OpenGL gl)
{
// Set the connectivity, (calculate the neighbours of each face).
SetConnectivity();
// Get the lights in the scene.
var lights = TraverseToRootElement().Traverse<Light>(l => l.IsEnabled && l.On && l.CastShadow);
// Get some useful references.
var faces = ParentPolygon.Faces;
// Go through every light in the scene.
foreach(var light in lights)
{
// Every face will have a visibility setting.
bool[] facesVisible = new bool[faces.Count];
// Get the light position relative to the polygon.
Vertex lightPos = light.Position;
lightPos = lightPos - ParentPolygon.Transformation.TranslationVertex;
// Go through every face, finding out whether it's visible to the light.
for(int nFace = 0; nFace < faces.Count; nFace++)
{
// Get a reference to the face.
Face face = faces[nFace];
// Is this face facing the light?
float[] planeEquation = face.GetPlaneEquation(ParentPolygon);
float side = planeEquation[0] * lightPos.X +
planeEquation[1] * lightPos.Y +
planeEquation[2] * lightPos.Z + planeEquation[3];
facesVisible[nFace] = (side > 0) ? true : false;
}
// Save all the attributes.
gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
// Turn off lighting.
gl.Disable(OpenGL.GL_LIGHTING);
// Turn off writing to the depth mask.
gl.DepthMask(0);
gl.DepthFunc(OpenGL.GL_LEQUAL);
// Turn on stencil buffer testing.
gl.Enable(OpenGL.GL_STENCIL_TEST);
// Translate our shadow volumes.
ParentPolygon.PushObjectSpace(gl);
// Don't draw to the color buffer.
gl.ColorMask(0, 0, 0, 0);
gl.StencilFunc(OpenGL.GL_ALWAYS, 1, 0xFFFFFFFF);
gl.Enable(OpenGL.GL_CULL_FACE);
// First Pass. Increase Stencil Value In The Shadow
gl.FrontFace(OpenGL.GL_CCW);
gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_INCR);
DoShadowPass(gl, lightPos, facesVisible);
// Second Pass. Decrease Stencil Value In The Shadow
gl.FrontFace(OpenGL.GL_CW);
gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_DECR);
DoShadowPass(gl, lightPos, facesVisible);
gl.FrontFace(OpenGL.GL_CCW);
ParentPolygon.PopObjectSpace(gl);
// Enable writing to the color buffer.
gl.ColorMask(1, 1, 1, 1);
// Draw A Shadowing Rectangle Covering The Entire Screen
gl.Color(light.ShadowColor);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
gl.StencilFunc(OpenGL.GL_NOTEQUAL, 0, 0xFFFFFFF);
gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_KEEP);
Quadrics.Sphere shadow = new Quadrics.Sphere();
shadow.Transformation.ScaleX = shadowSize;
shadow.Transformation.ScaleY = shadowSize;
shadow.Transformation.ScaleZ = shadowSize;
shadow.Render(gl, RenderMode.Design);
gl.PopAttrib();
}
}
示例9: Set
public override void Set(OpenGL gl)
{
base.Set(gl);
// Save the current attributes.
gl.PushAttrib(AttributeBit);
gl.LineWidth(width);
gl.EnableIf(OpenGL.LINE_SMOOTH, smooth);
}
示例10: Draw
/// <summary>
/// Use this to draw the vertex grid.
/// </summary>
/// <param name="gl">OpenGL object.</param>
/// <param name="points">Draw each individual vertex (with selection names).</param>
/// <param name="lines">Draw the lines connecting the points.</param>
public virtual void Draw(OpenGL gl, bool points, bool lines)
{
// Save the attributes.
gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
gl.Disable(OpenGL.GL_LIGHTING);
gl.Color(1, 0, 0, 1);
if(points)
{
int name = 0;
gl.PointSize(5);
// Add a new name (the vertex name).
gl.PushName(0);
foreach(Vertex v in vertices)
{
// Set the name, draw the vertex.
gl.LoadName((uint)name++);
//todo draw vertex
//((IInteractable)v).DrawPick(gl);
}
// Pop the name.
gl.PopName();
}
if(lines)
{
// Draw lines along each row, then along each column.
gl.DepthFunc(OpenGL.GL_ALWAYS);
gl.LineWidth(1);
gl.Disable(OpenGL.GL_LINE_SMOOTH);
for(int col=0; col < y; col++)
{
for(int row=0; row < x; row++)
{
// Create vertex indicies.
int nTopLeft = (col * x) + row;
int nBottomLeft = ((col + 1) * x) + row;
gl.Begin(OpenGL.GL_LINES);
if(row < (x-1))
{
gl.Vertex(vertices[nTopLeft]);
gl.Vertex(vertices[nTopLeft + 1]);
}
if(col < (y-1))
{
gl.Vertex(vertices[nTopLeft]);
gl.Vertex(vertices[nBottomLeft]);
}
gl.End();
}
}
gl.DepthFunc(OpenGL.GL_LESS);
}
gl.PopAttrib();
}
示例11: Draw
/// <summary>
/// This function draws the polygon.
/// </summary>
/// <param name="gl">OpenGL.</param>
public override void Draw(OpenGL gl)
{
if(DoPreDraw(gl))
{
polyAttributes.Set(gl);
foreach(Face face in faces)
{
// Begin drawing a polygon.
if(face.Indices.Count == 2)
gl.Begin(OpenGL.LINES);
else
gl.Begin(OpenGL.POLYGON);
foreach(Index index in face.Indices)
{
// Set a texture coord (if any).
if(index.UV != -1)
gl.TexCoord(uvs[index.UV]);
// Set a normal, or generate one.
if(index.Normal != -1)
gl.Normal(normals[index.Normal]);
else
{
// Do we have enough vertices for a normal?
if(face.Indices.Count >= 3)
{
// Create a normal.
Vertex vNormal = face.GetSurfaceNormal(this);
vNormal.UnitLength();
// Add it to the normals, setting the index for next time.
index.Normal = normals.Add(new Normal(vNormal));
gl.Normal(vNormal);
}
}
// Set the vertex.
gl.Vertex(vertices[index.Vertex]);
}
gl.End();
}
// If the current context is edit vertices, draw the vertices.
if(currentContext == Context.EditVertices)
{
// Push all the attributes.
gl.PushAttrib(OpenGL.ALL_ATTRIB_BITS);
// Set the colour to red, large points, no lighting.
gl.Color(1, 0, 0, 1);
gl.PointSize(5);
gl.Disable(OpenGL.LIGHTING);
// Draw the control points.
for(int point = 0; point < vertices.Count; point++)
{
// Name the point, then draw it.
gl.PushName((uint)point);
gl.Begin(OpenGL.POINTS);
gl.Vertex(vertices[point]);
gl.End();
gl.PopName();
}
// Restore the attributes.
gl.PopAttrib();
}
// If the current context is edit normals, draw the normals.
if(currentContext == Context.EditNormals)
{
// We're going to disable lighting.
Attributes.Lighting lighting = new Attributes.Lighting();
lighting.Enable = false;
lighting.Set(gl);
gl.Color(1, 0, 0);
gl.Begin(OpenGL.LINES);
// Draw the normals points.
foreach(Face face in faces)
{
foreach(Index index in face.Indices)
{
if(index.Normal == -1)
continue;
// Translate to that vertex.
Vertex v = vertices[index.Vertex];
gl.PushName((uint)index.Normal);
gl.Vertex(v);
gl.Vertex(v + normals[index.Normal]);
//.........这里部分代码省略.........
示例12: DrawCircle3D
public virtual void DrawCircle3D(OpenGL gl)
{
gl.PushAttrib(OpenGL.ENABLE_BIT);
gl.Disable(OpenGL.LIGHTING);
// Draw three circles.
gl.PushMatrix();
DrawCircle(gl);
gl.Rotate(90, 1, 0, 0);
DrawCircle(gl);
gl.Rotate(90, 0, 0, 1);
DrawCircle(gl);
gl.PopMatrix();
gl.PopAttrib();
}
示例13: Push
/// <summary>
/// Pushes the attributes onto the specified OpenGL attribute stack.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void Push(OpenGL gl)
{
gl.PushAttrib((uint)AttributeFlags);
}
示例14: RenderImmediateMode
/// <summary>
/// Renders the scene in immediate mode.
/// </summary>
/// <param name="gl">The OpenGL instance.</param>
public void RenderImmediateMode(OpenGL gl)
{
// Setup the modelview matrix.
gl.MatrixMode(OpenGL.GL_MODELVIEW);
gl.LoadIdentity();
gl.MultMatrix(modelviewMatrix.to_array());
// Push the polygon attributes and set line mode.
gl.PushAttrib(OpenGL.GL_POLYGON_BIT);
gl.PolygonMode(FaceMode.FrontAndBack, PolygonMode.Lines);
// Render the trefoil.
var vertices = trefoilKnot.Vertices;
gl.Begin(BeginMode.Triangles);
foreach (var index in trefoilKnot.Indices)
gl.Vertex(vertices[index].x, vertices[index].y, vertices[index].z);
gl.End();
// Pop the attributes, restoring all polygon state.
gl.PopAttrib();
}
示例15: Create
/// <summary>
/// This function creates the internal display lists.
/// </summary>
/// <param name="gl">OpenGL object.</param>
public virtual void Create(OpenGL gl)
{
// Create the arrow.
arrow.Generate(gl);
arrow.New(gl, DisplayList.DisplayListMode.Compile);
// Draw the 'line' of the arrow.
gl.Begin(OpenGL.LINES);
gl.Vertex(0, 0, 0);
gl.Vertex(0, 0, 1);
gl.End();
// Draw the arrowhead.
gl.Begin(OpenGL.TRIANGLE_FAN);
gl.Vertex(0, 0, 1);
gl.Vertex(0.2f, 0.8f, 0.2f);
gl.Vertex(0.2f, 0.8f, -0.2f);
gl.Vertex(-0.2f, 0.8f, -0.2f);
gl.Vertex(-0.2f, 0.8f, 0.2f);
gl.End();
// End the arrow list.
arrow.End(gl);
// Create the grid.
grid.Generate(gl);
grid.New(gl, DisplayList.DisplayListMode.Compile);
gl.PushAttrib(OpenGL.LIGHTING_BIT);
gl.Disable(OpenGL.LIGHTING);
gl.Color(1, 1, 1);
gl.Begin(OpenGL.LINES);
for(int i = -10; i <= 10; i++)
{
gl.Vertex(i, 0, -10);
gl.Vertex(i, 0, 10);
gl.Vertex(-10, 0, i);
gl.Vertex(10, 0, i);
}
gl.End();
gl.PopAttrib();
grid.End(gl);
// Create the axies.
axies.Generate(gl);
axies.New(gl, DisplayList.DisplayListMode.Compile);
gl.PushAttrib(OpenGL.ALL_ATTRIB_BITS);
gl.Disable(OpenGL.LIGHTING);
gl.Disable(OpenGL.DEPTH_TEST);
gl.LineWidth(2.0f);
gl.Begin(OpenGL.LINES);
gl.Color(1, 0, 0, 1);
gl.Vertex(0, 0, 0);
gl.Vertex(3, 0, 0);
gl.Color(0, 1, 0, 1);
gl.Vertex(0, 0, 0);
gl.Vertex(0, 3, 0);
gl.Color(0, 0, 1, 1);
gl.Vertex(0, 0, 0);
gl.Vertex(0, 0, 3);
gl.End();
gl.PopAttrib();
axies.End(gl);
camera.Generate(gl);
camera.New(gl, DisplayList.DisplayListMode.Compile);
Polygon poly = new Polygon();
poly.CreateCube();
poly.Scale.Set(.2f ,0.2f, 0.2f);
poly.Draw(gl);
// poly.Dispose();
camera.End(gl);
}