本文整理汇总了C#中OpenTK.MakeCurrent方法的典型用法代码示例。如果您正苦于以下问题:C# OpenTK.MakeCurrent方法的具体用法?C# OpenTK.MakeCurrent怎么用?C# OpenTK.MakeCurrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenTK
的用法示例。
在下文中一共展示了OpenTK.MakeCurrent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public void Render( int width, int height, OpenTK.GLControl glControl, float renderingStep )
{
angle += 0.5;
Stopwatch sw = new Stopwatch();
sw.Start();
glControl.MakeCurrent();
#region Projection Setup
GL.Enable( EnableCap.DepthTest );
GL.MatrixMode( MatrixMode.Projection );
GL.LoadIdentity();
//double c1 = 2.00;
//if ( width <= height )
// GL.Ortho( -c1, c1, -c1 * height / width, c1 * height / width, -c1, c1 );
//else
// GL.Ortho( -c1 * width / height, c1 * width / height, -c1, c1, -c1, c1 );
GL.Ortho( -10, 10, -10, 10, -25, 25 ); // Bottom-left corner pixel has coordinate (0, 0)
GL.Viewport( 0, 0, width, height ); // Use all of the glControl painting area
#endregion Projection Setup
#region Render Setup
GL.MatrixMode( MatrixMode.Modelview );
GL.Clear( ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit );
GL.LoadIdentity();
GL.Translate( -0.5, -0.5, +10.5 );
GL.Rotate( +45, 1, 0, 0 );
GL.Rotate( angle, 0, 1, 0 );
#endregion Render Setup
Random rand = new Random();
double k1 = 200, k2 = 200;
double[,] meshGrid = new double[(int) k1, (int) k2];
k1 /= 8;
k2 /= 8;
for ( int i = 0; i < meshGrid.GetLength( 0 ); i++ )
for ( int j = 0; j < meshGrid.GetLength( 1 ); j++ )
{
double r = Math.Sqrt( ( i / k1 ) * ( i / k1 ) + ( j / k2 ) * ( j / k2 ) );
meshGrid[i, j] = 0.8 * Math.Sin( 10 * r ) * Math.Sin( 2 * r ) * 10*Math.Exp( -0.8 * Math.Sqrt( r * r ) );
}
GL.Enable( EnableCap.PointSmooth );
GL.Begin( BeginMode.Lines );
aa = 1;
bb = 0.5;
cc = 0.2;
for ( int i = 0; i < meshGrid.GetLength( 0 ) - 1; i++ )
for ( int j = 0; j < meshGrid.GetLength( 1 ) - 1; j++ )
{
aa = rand.NextDouble();
bb = rand.NextDouble();
cc = rand.NextDouble();
GL.Color3( new double[] { meshGrid[i, j] + 0.1, meshGrid[i, j] + 0.1, 0.8 } );
GL.Vertex3( ( i + 0 ) / k1, meshGrid[i + 0, j + 0], ( j + 0 ) / k2 );
GL.Vertex3( ( i + 0 ) / k1, meshGrid[i + 0, j + 1], ( j + 1 ) / k2 );
GL.Vertex3( ( i + 1 ) / k1, meshGrid[i + 1, j + 1], ( j + 1 ) / k2 );
aa = rand.NextDouble();
bb = rand.NextDouble();
cc = rand.NextDouble();
//GL.Color3( new double[] { i / k1, i / k1, 0 } );
GL.Vertex3( ( i + 0 ) / k1, meshGrid[i + 0, j + 0], ( j + 0 ) / k2 );
GL.Vertex3( ( i + 1 ) / k1, meshGrid[i + 1, j + 1], ( j + 1 ) / k2 );
GL.Vertex3( ( i + 1 ) / k1, meshGrid[i + 1, j + 0], ( j + 0 ) / k2 );
}
GL.End();
}
示例2: DrawTiles
/// <summary>
/// Paint a control
/// </summary>
/// <param name="control">Control to paint</param>
/// <param name="tileid">Id of the tile to draw</param>
private void DrawTiles(OpenTK.GLControl control, int tileid)
{
control.MakeCurrent();
Display.ClearBuffers();
SpriteBatch.Begin();
// Background texture
Rectangle dst = new Rectangle(Point.Empty, control.Size);
SpriteBatch.Draw(CheckerBoard, dst, dst, Color.White);
// Tile to draw
if (TileSet != null)
{
Tile tile = TileSet.GetTile(tileid);
if (tile != null)
{
Point location = new Point((control.Width - tile.Size.Width) / 2, (control.Height - tile.Size.Height) / 2);
location.Offset(tile.Pivot);
SpriteBatch.DrawTile(TileSet, tileid, location);
}
}
SpriteBatch.End();
control.SwapBuffers();
}