本文整理汇总了C#中SharpGL.OpenGL.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.Clear方法的具体用法?C# OpenGL.Clear怎么用?C# OpenGL.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.Clear方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: openGLControl_OpenGLDraw
/// <summary>
/// Handles the OpenGLDraw event of the openGLControl control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="RenderEventArgs"/> instance containing the event data.</param>
public void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
{
// Get the OpenGL object.
gl = openGLControl.OpenGL;
// Clear the color and depth buffer.
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
// Load the identity matrix.
gl.LoadIdentity();
// Rotate around the Y axis.
//gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);
cord = ComInput.Coordinates.Instance;
this.ModelRotater(gl);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
// Draw a coloured parallelepiped.
gl.Begin(OpenGL.GL_QUADS);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, -1.0f);
//-------------------------------------
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, -1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, 1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, 1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, -1.0f);
//-------------------------------------
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, -0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 0.0f);
gl.Vertex(-2.0f, 0.25f, 1.0f);
//-------------------------------------
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, 1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, -0.25f, -1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, -1.0f);
gl.Color(1.0f, 0.0f, 0.0f);
gl.Vertex(2.0f, 0.25f, 1.0f);
//-------------------------------------
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(-2.0f, 0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(2.0f, 0.25f, -1.0f);
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(2.0f, 0.25f, 1.0f);
gl.Color(0.0f, 1.0f, 1.0f);
gl.Vertex(-2.0f, 0.25f, 1.0f);
//--------------------------------------
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(-2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(2.0f, -0.25f, -1.0f);
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(2.0f, -0.25f, 1.0f);
gl.Color(0.0f, 0.0f, 1.0f);
gl.Vertex(-2.0f, -0.25f, 1.0f);
gl.End();
//.........这里部分代码省略.........
示例2: DrawGrid
public void DrawGrid(OpenGL gl, int camX,int camY)
{
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.LoadIdentity();
int MapHeight = tileMap.mapHeight;
int MapWidth = tileMap.mapWidth;
float[] darkColor = { 0.2f, 0.2f, 0.2f };
float[] lightColor = { 0.25f, 0.25f, 0.25f };
for (int h = 0; h < MapHeight; h++)
{
if (h % 10 == 0)
{
gl.LineWidth(2.0f);
gl.Color(lightColor);
}
else
{
gl.LineWidth(1.0f);
gl.Color(darkColor);
}
if (h == 0)
{
gl.LineWidth(4.0f);
gl.Color(lightColor);
}
gl.Begin(OpenGL.GL_LINES); // Start Drawing Verticle Cell Borders
gl.Vertex(0 - camX, h * tileSize - camY, 0);// Left Side Of Horizontal Line
gl.Vertex((MapWidth * tileSize) - camX, (h * tileSize) - camY, 0);// Right Side Of Horizontal Line
gl.End();
}
for (int v = 0; v < MapWidth; v++)
{
if (v % 10 == 0)
{
gl.LineWidth(2.0f);
gl.Color(lightColor);
}
else
{
gl.LineWidth(1.0f);
gl.Color(darkColor);
}
if (v == 0)
{
gl.LineWidth(4.0f);
gl.Color(lightColor);
}
gl.Begin(OpenGL.GL_LINES); // Start Drawing Verticle Cell Borders
gl.Vertex(v * tileSize - camX, 0 - camY, 0);// Left Side Of Horizontal Line
gl.Vertex((v * tileSize) - camX, (MapHeight * tileSize) - camY, 0);// Right Side Of Horizontal Line
gl.End();
}
}
示例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: SampleRendering
private void SampleRendering(OpenGL gl, float rX, float rY, float rZ)
{
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
gl.LoadIdentity(); // Reset The View
gl.Translate(-1.5f, 0.0f, -6.0f); // Move Left And Into The Screen
gl.Rotate(rtri, rX, rY, rZ); // Rotate The Pyramid On It's Y Axis
gl.Begin(OpenGL.GL_TRIANGLES); // Start Drawing The Pyramid
gl.Color(1.0f, 0.0f, 0.0f); // Red
gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
gl.Color(0.0f, 1.0f, 0.0f); // Green
gl.Vertex(-1.0f, -1.0f, 1.0f); // Left Of Triangle (Front)
gl.Color(0.0f, 0.0f, 1.0f); // Blue
gl.Vertex(1.0f, -1.0f, 1.0f); // Right Of Triangle (Front)
gl.Color(1.0f, 0.0f, 0.0f); // Red
gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
gl.Color(0.0f, 0.0f, 1.0f); // Blue
gl.Vertex(1.0f, -1.0f, 1.0f); // Left Of Triangle (Right)
gl.Color(0.0f, 1.0f, 0.0f); // Green
gl.Vertex(1.0f, -1.0f, -1.0f); // Right Of Triangle (Right)
gl.Color(1.0f, 0.0f, 0.0f); // Red
gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
gl.Color(0.0f, 1.0f, 0.0f); // Green
gl.Vertex(1.0f, -1.0f, -1.0f); // Left Of Triangle (Back)
gl.Color(0.0f, 0.0f, 1.0f); // Blue
gl.Vertex(-1.0f, -1.0f, -1.0f); // Right Of Triangle (Back)
gl.Color(1.0f, 0.0f, 0.0f); // Red
gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
gl.Color(0.0f, 0.0f, 1.0f); // Blue
gl.Vertex(-1.0f, -1.0f, -1.0f); // Left Of Triangle (Left)
gl.Color(0.0f, 1.0f, 0.0f); // Green
gl.Vertex(-1.0f, -1.0f, 1.0f); // Right Of Triangle (Left)
gl.End(); // Done Drawing The Pyramid
gl.LoadIdentity();
gl.Translate(1.5f, 0.0f, -7.0f); // Move Right And Into The Screen
gl.Rotate(rquad, rX, rY, rZ); // Rotate The Cube On X, Y & Z
gl.Begin(OpenGL.GL_QUADS); // Start Drawing The Cube
gl.Color(0.0f, 1.0f, 0.0f); // Set The Color To Green
gl.Vertex(1.0f, 1.0f, -1.0f); // Top Right Of The Quad (Top)
gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Left Of The Quad (Top)
gl.Vertex(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
gl.Vertex(1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
gl.Color(1.0f, 0.5f, 0.0f); // Set The Color To Orange
gl.Vertex(1.0f, -1.0f, 1.0f); // Top Right Of The Quad (Bottom)
gl.Vertex(-1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Bottom)
gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Bottom)
gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Bottom)
gl.Color(1.0f, 0.0f, 0.0f); // Set The Color To Red
gl.Vertex(1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
gl.Vertex(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Quad (Front)
gl.Vertex(1.0f, -1.0f, 1.0f); // Bottom Right Of The Quad (Front)
gl.Color(1.0f, 1.0f, 0.0f); // Set The Color To Yellow
gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Back)
gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Back)
gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Right Of The Quad (Back)
gl.Vertex(1.0f, 1.0f, -1.0f); // Top Left Of The Quad (Back)
gl.Color(0.0f, 0.0f, 1.0f); // Set The Color To Blue
gl.Vertex(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Left Of The Quad (Left)
gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Left)
gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Quad (Left)
gl.Color(1.0f, 0.0f, 1.0f); // Set The Color To Violet
gl.Vertex(1.0f, 1.0f, -1.0f); // Top Right Of The Quad (Right)
gl.Vertex(1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
gl.Vertex(1.0f, -1.0f, 1.0f); // Bottom Left Of The Quad (Right)
gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Right)
gl.End(); // Done Drawing The Q
gl.Flush();
rtri += 1.0f;// 0.2f; // Increase The Rotation Variable For The Triangle
rquad -= 1.0f;// 0.15f; // Decrease The Rotation Variable For The Quad
}
示例5: 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);
}
示例6: Draw
public override void Draw(ref OpenGL gl)
{
if (!TexturesInitialised)
{
InitializeTexture(ref gl);
}
// Clear the color and depth buffer.
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
// Load the identity matrix.
gl.LoadIdentity();
gl.Enable(OpenGL.GL_TEXTURE_2D);
gl.Enable(OpenGL.GL_LIGHTING);
gl.Enable(OpenGL.GL_LIGHT0);
gl.Enable(OpenGL.GL_DEPTH_TEST);
gl.Enable(OpenGL.GL_NORMALIZE);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, gtexture[0]);
gl.Color(1.0f, 1.0f, 1.0f, 0.1f);
gl.Begin(OpenGL.GL_QUADS);
gl.FrontFace(OpenGL.GL_FRONT_FACE);
gl.TexCoord(1.0f, 1.0f);
gl.Vertex(gImage1.Width, gImage1.Height, 1.0f);
gl.TexCoord(0.0f, 1.0f);
gl.Vertex(0.0f, gImage1.Height, 1.0f);
gl.TexCoord(0.0f, 0.0f);
gl.Vertex(0.0f, 0.0f, 1.0f);
gl.TexCoord(1.0f, 0.0f);
gl.Vertex(gImage1.Width, 0.0f, 1.0f);
gl.End();
gl.Disable(OpenGL.GL_TEXTURE_2D);
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.LoadIdentity();
gl.Ortho(0.0, (double)gImage1.Width, (double)gImage1.Height, 0.0, -1.0, 1.0);
gl.MatrixMode(OpenGL.GL_MODELVIEW);
gl.Disable(OpenGL.GL_DEPTH_TEST);
}
示例7: OnRender
public override void OnRender(OpenGL gl)
{
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.ClearColor(0.137f, 0.121f, 0.125f, 0f);
_graph.Render();
}
示例8: RenderObjects
public void RenderObjects(OpenGL gl, GameObject[] objects)
{
//clears the screen
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
//St matrix mode to PROJECTION so we can move the camera
gl.MatrixMode(OpenGL.GL_PROJECTION);
// Load the identity matrix.
gl.LoadIdentity();
//Move the camera
CamController.SetCam(gl);
//Set matrix mode back to Modelview so we can draw objects
gl.MatrixMode(OpenGL.GL_MODELVIEW);
if (_mode == RenderMode.WireFrame || _mode == RenderMode.Hitboxes)
{
foreach(GameObject obj in objects){
//Draw the object with texture
obj.Draw(gl);
//Unbind texture so we can draw lines
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
if ( _mode == RenderMode.Hitboxes)
{
obj.DrawVelocity(gl);
DrawCircle(gl, obj.GetPosition().x,obj.GetPosition().y, obj.GetPhysSize());
}
else
{
obj.DrawWireFrame(gl);
}
}
}
else
{
foreach ( GameObject obj in objects )
{
//Draw the object with texture
obj.Draw(gl);
}
}
//Unbind texture
gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
}
示例9: openGLControl_OpenGLDraw
private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
{
_gl = openGLControl.OpenGL;
_gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
_gl.LoadIdentity();
_gl.LookAt(0, 0, _w, 0, 0, 0, 0, 1, 0); //-10, 10, _w, 0, 0, 0, 0, 1, 0
_gl.Rotate((float)_rotX, (float)_rotY, (float)_rotZ);
_gl.Translate(_transX, _transY, _transZ);
foreach (Polygon polygon in _polygons)
{
if (!polygon.IsEnabled) continue;
polygon.PushObjectSpace(_gl);
polygon.Render(_gl, SharpGL.SceneGraph.Core.RenderMode.Render);
polygon.PopObjectSpace(_gl);
}
}
示例10: OnRender
public override void OnRender(OpenGL gl)
{
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.ClearColor(0.137f, 0.121f, 0.125f, 0f);
_graph.Render();
gl.Disable(OpenGL.GL_DEPTH_TEST);
using (new Bind(_shader))
{
gl.UniformMatrix4(_modelUniform, 1, false, Mat4.Identity.ToColumnMajorArray());
gl.PointSize(10f);
gl.Begin(BeginMode.Points);
gl.Vertex(6, 0);
gl.End();
}
gl.PointSize(5f);
_points.Render();
gl.Enable(OpenGL.GL_DEPTH_TEST);
}
示例11: OpenGLControl_OpenGLDraw
private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
{
OpenGL gl = new OpenGL();
ballX -= balMovX;
ballY -= balMovY;
if (Convert.ToInt32(ballX) == -gameSizeX)
{
balMovX = -0.08f;
}
else if (Convert.ToInt32(ballX) == gameSizeX)
{
balMovX = 0.08f;
}
if (Convert.ToInt32(ballY) == -gameSizeY)
{
balMovY = -0.03f;
}
else if (Convert.ToInt32(ballY) == gameSizeY)
{
balMovY = 0.03f;
}
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.LoadIdentity();
gl.Translate(gameX, gameY, gameZ);
gameRect(gl);
Ball(gl);
Bed(gl,bed1X, bed1Y, bed1Z, 0.2f, 1.8f);
Bed(gl,bed2X, bed2Y, bed2Z, 0.2f, 1.8f);
gl.Flush();
}