mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 08:35:39 +00:00
Fixed code formatting.
This commit is contained in:
parent
9516b56eb4
commit
546decd579
|
@ -43,7 +43,7 @@ using OpenTK.Graphics.OpenGL;
|
|||
|
||||
namespace Examples.Tutorial
|
||||
{
|
||||
[Example("Display Lists", ExampleCategory.OpenGL, "1.x", 2, Documentation="DisplayLists")]
|
||||
[Example("Display Lists", ExampleCategory.OpenGL, "1.x", 2, Documentation = "DisplayLists")]
|
||||
public class T07_Display_Lists_Flower : GameWindow
|
||||
{
|
||||
#region --- Fields ---
|
||||
|
@ -122,8 +122,8 @@ namespace Examples.Tutorial
|
|||
|
||||
float aspect = this.ClientSize.Width / (float)this.ClientSize.Height;
|
||||
|
||||
Matrix4 projection_matrix;
|
||||
Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, aspect, 1, 64, out projection_matrix);
|
||||
Matrix4 projection_matrix;
|
||||
Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, aspect, 1, 64, out projection_matrix);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Projection);
|
||||
GL.LoadMatrix(ref projection_matrix);
|
||||
|
|
|
@ -17,7 +17,7 @@ using OpenTK.Graphics.OpenGL;
|
|||
|
||||
namespace Examples.Tutorial
|
||||
{
|
||||
[Example("Framebuffer Objects", ExampleCategory.OpenGL, "1.x", Documentation="FramebufferObject")]
|
||||
[Example("Framebuffer Objects", ExampleCategory.OpenGL, "1.x", Documentation = "FramebufferObject")]
|
||||
public class SimpleFBO : GameWindow
|
||||
{
|
||||
public SimpleFBO()
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Demonstrates immediate mode rendering.
|
||||
/// </summary>
|
||||
[Example("Immediate mode", ExampleCategory.OpenGL, "1.x", 1, Documentation="ImmediateMode")]
|
||||
[Example("Immediate mode", ExampleCategory.OpenGL, "1.x", 1, Documentation = "ImmediateMode")]
|
||||
public class T03_Immediate_Mode_Cube : GameWindow
|
||||
{
|
||||
#region --- Fields ---
|
||||
|
@ -37,10 +37,11 @@ namespace Examples.Tutorial
|
|||
|
||||
#region --- Constructor ---
|
||||
|
||||
public T03_Immediate_Mode_Cube() : base(800, 600, new GraphicsMode(16, 16))
|
||||
{ }
|
||||
public T03_Immediate_Mode_Cube()
|
||||
: base(800, 600, new GraphicsMode(16, 16))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region OnLoad
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Examples.Tutorial
|
|||
{
|
||||
|
||||
[Example("Stencil CSG", ExampleCategory.OpenGL, "1.x", Documentation = "StencilCSG")]
|
||||
partial class StencilCSG: GameWindow
|
||||
partial class StencilCSG : GameWindow
|
||||
{
|
||||
#region Model Related
|
||||
DrawableShape OperandB;
|
||||
|
@ -31,11 +31,11 @@ namespace Examples.Tutorial
|
|||
float CameraZoom;
|
||||
float CameraRotX;
|
||||
float CameraRotY;
|
||||
Vector3 EyePosition = new Vector3( 0f, 0f, 15f );
|
||||
Vector3 EyePosition = new Vector3(0f, 0f, 15f);
|
||||
|
||||
#region Window
|
||||
public StencilCSG()
|
||||
: base( 800, 600, new GraphicsMode( new ColorFormat( 8, 8, 8, 8 ), 24, 8 ) ) // request 8-bit stencil buffer
|
||||
: base(800, 600, new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8)) // request 8-bit stencil buffer
|
||||
{
|
||||
base.VSync = VSyncMode.Off;
|
||||
Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
|
||||
|
@ -48,10 +48,10 @@ namespace Examples.Tutorial
|
|||
};
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e )
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
GL.Viewport( 0, 0, Width, Height );
|
||||
GL.MatrixMode( MatrixMode.Projection );
|
||||
GL.Viewport(0, 0, Width, Height);
|
||||
GL.MatrixMode(MatrixMode.Projection);
|
||||
Matrix4 p = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Width / (float)Height, 0.1f, 64.0f);
|
||||
GL.LoadMatrix(ref p);
|
||||
}
|
||||
|
@ -160,15 +160,15 @@ namespace Examples.Tutorial
|
|||
|
||||
protected override void OnUnload(EventArgs e)
|
||||
{
|
||||
GL.DeleteTextures( 1, ref Texture );
|
||||
GL.DeleteTextures(1, ref Texture);
|
||||
|
||||
OperandA.Dispose();
|
||||
OperandB.Dispose();
|
||||
|
||||
base.OnUnload( e );
|
||||
base.OnUnload(e);
|
||||
}
|
||||
|
||||
protected override void OnUpdateFrame( FrameEventArgs e )
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
#region Magic numbers for camera
|
||||
CameraRotX = -Mouse.X * .5f;
|
||||
|
@ -180,117 +180,117 @@ namespace Examples.Tutorial
|
|||
public void DrawOperandB()
|
||||
{
|
||||
GL.PushMatrix();
|
||||
GL.Translate( Math.Cos(MySphereXOffset), -1f, Math.Cos(MySphereZOffset) );
|
||||
GL.Translate(Math.Cos(MySphereXOffset), -1f, Math.Cos(MySphereZOffset));
|
||||
OperandB.Draw();
|
||||
GL.PopMatrix();
|
||||
}
|
||||
|
||||
public void DrawOperandA()
|
||||
{
|
||||
GL.Enable( EnableCap.Texture2D );
|
||||
GL.Enable(EnableCap.Texture2D);
|
||||
OperandA.Draw();
|
||||
GL.Disable( EnableCap.Texture2D );
|
||||
GL.Disable(EnableCap.Texture2D);
|
||||
}
|
||||
|
||||
public void RenderCsg()
|
||||
{
|
||||
// first pass
|
||||
GL.Disable( EnableCap.StencilTest );
|
||||
GL.Disable(EnableCap.StencilTest);
|
||||
|
||||
GL.ColorMask( false, false, false, false );
|
||||
GL.CullFace( CullFaceMode.Front );
|
||||
GL.ColorMask(false, false, false, false);
|
||||
GL.CullFace(CullFaceMode.Front);
|
||||
DrawOperandB();// draw front-faces into depth buffer
|
||||
|
||||
// use stencil plane to find parts of b in a
|
||||
GL.DepthMask( false );
|
||||
GL.Enable( EnableCap.StencilTest );
|
||||
GL.StencilFunc( StencilFunction.Always, 0, 0 );
|
||||
GL.DepthMask(false);
|
||||
GL.Enable(EnableCap.StencilTest);
|
||||
GL.StencilFunc(StencilFunction.Always, 0, 0);
|
||||
|
||||
GL.StencilOp( StencilOp.Keep, StencilOp.Keep, StencilOp.Incr );
|
||||
GL.CullFace( CullFaceMode.Back );
|
||||
GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Incr);
|
||||
GL.CullFace(CullFaceMode.Back);
|
||||
DrawOperandA(); // increment the stencil where the front face of a is drawn
|
||||
|
||||
GL.StencilOp( StencilOp.Keep, StencilOp.Keep, StencilOp.Decr );
|
||||
GL.CullFace( CullFaceMode.Front );
|
||||
GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Decr);
|
||||
GL.CullFace(CullFaceMode.Front);
|
||||
DrawOperandA(); // decrement the stencil buffer where the back face of a is drawn
|
||||
|
||||
GL.DepthMask( true );
|
||||
GL.Disable( EnableCap.DepthTest );
|
||||
GL.DepthMask(true);
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
|
||||
GL.ColorMask( true, true, true, true );
|
||||
GL.StencilFunc( StencilFunction.Notequal, 0, 1 );
|
||||
GL.ColorMask(true, true, true, true);
|
||||
GL.StencilFunc(StencilFunction.Notequal, 0, 1);
|
||||
DrawOperandB(); // draw the part of b that's in a
|
||||
|
||||
// fix depth
|
||||
GL.ColorMask( false, false, false, false );
|
||||
GL.Enable( EnableCap.DepthTest );
|
||||
GL.Disable( EnableCap.StencilTest );
|
||||
GL.DepthFunc( DepthFunction.Always );
|
||||
GL.ColorMask(false, false, false, false);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
GL.Disable(EnableCap.StencilTest);
|
||||
GL.DepthFunc(DepthFunction.Always);
|
||||
DrawOperandA();
|
||||
GL.DepthFunc( DepthFunction.Less );
|
||||
GL.DepthFunc(DepthFunction.Less);
|
||||
|
||||
// second pass
|
||||
GL.CullFace( CullFaceMode.Back );
|
||||
GL.CullFace(CullFaceMode.Back);
|
||||
DrawOperandA();
|
||||
|
||||
GL.DepthMask( false );
|
||||
GL.Enable( EnableCap.StencilTest );
|
||||
GL.DepthMask(false);
|
||||
GL.Enable(EnableCap.StencilTest);
|
||||
|
||||
GL.StencilFunc( StencilFunction.Always, 0, 0 );
|
||||
GL.StencilOp( StencilOp.Keep, StencilOp.Keep, StencilOp.Incr );
|
||||
GL.StencilFunc(StencilFunction.Always, 0, 0);
|
||||
GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Incr);
|
||||
DrawOperandB(); // increment the stencil where the front face of b is drawn
|
||||
|
||||
GL.StencilOp( StencilOp.Keep, StencilOp.Keep, StencilOp.Decr );
|
||||
GL.CullFace( CullFaceMode.Front );
|
||||
GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Decr);
|
||||
GL.CullFace(CullFaceMode.Front);
|
||||
DrawOperandB(); // decrement the stencil buffer where the back face of b is drawn
|
||||
|
||||
GL.DepthMask( true );
|
||||
GL.Disable( EnableCap.DepthTest );
|
||||
GL.DepthMask(true);
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
|
||||
GL.ColorMask( true, true, true, true );
|
||||
GL.StencilFunc( StencilFunction.Equal, 0, 1 );
|
||||
GL.CullFace( CullFaceMode.Back );
|
||||
GL.ColorMask(true, true, true, true);
|
||||
GL.StencilFunc(StencilFunction.Equal, 0, 1);
|
||||
GL.CullFace(CullFaceMode.Back);
|
||||
DrawOperandA(); // draw the part of a that's in b
|
||||
|
||||
GL.Enable( EnableCap.DepthTest );
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
}
|
||||
|
||||
protected override void OnRenderFrame( FrameEventArgs e )
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
this.Title = WindowTitle + " FPS: " + ( 1f / e.Time ).ToString("0.");
|
||||
this.Title = WindowTitle + " FPS: " + (1f / e.Time).ToString("0.");
|
||||
|
||||
MySphereZOffset += (float)( e.Time * 3.1 );
|
||||
MySphereXOffset += (float)( e.Time * 4.2 );
|
||||
MySphereZOffset += (float)(e.Time * 3.1);
|
||||
MySphereXOffset += (float)(e.Time * 4.2);
|
||||
|
||||
#region Transform setup
|
||||
GL.Clear( ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit );
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
|
||||
|
||||
// Camera
|
||||
GL.MatrixMode( MatrixMode.Modelview );
|
||||
Matrix4 mv = Matrix4.LookAt( EyePosition, Vector3.Zero, Vector3.UnitY );
|
||||
GL.MatrixMode(MatrixMode.Modelview);
|
||||
Matrix4 mv = Matrix4.LookAt(EyePosition, Vector3.Zero, Vector3.UnitY);
|
||||
GL.LoadMatrix(ref mv);
|
||||
|
||||
GL.Translate( 0f, 0f, CameraZoom );
|
||||
GL.Rotate( CameraRotX, Vector3.UnitY );
|
||||
GL.Rotate( CameraRotY, Vector3.UnitX );
|
||||
GL.Translate(0f, 0f, CameraZoom);
|
||||
GL.Rotate(CameraRotX, Vector3.UnitY);
|
||||
GL.Rotate(CameraRotY, Vector3.UnitX);
|
||||
#endregion Transform setup
|
||||
|
||||
RenderCsg();
|
||||
|
||||
// ---------------------------------
|
||||
|
||||
if ( ShowDebugWireFrame )
|
||||
if (ShowDebugWireFrame)
|
||||
{
|
||||
GL.Color3(System.Drawing.Color.LightGray);
|
||||
GL.Disable( EnableCap.StencilTest );
|
||||
GL.Disable( EnableCap.Lighting );
|
||||
GL.Disable(EnableCap.StencilTest);
|
||||
GL.Disable(EnableCap.Lighting);
|
||||
//GL.Disable( EnableCap.DepthTest );
|
||||
GL.PolygonMode( MaterialFace.Front, PolygonMode.Line );
|
||||
GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
|
||||
DrawOperandB();
|
||||
GL.PolygonMode( MaterialFace.Front, PolygonMode.Fill );
|
||||
GL.Enable( EnableCap.DepthTest );
|
||||
GL.Enable( EnableCap.Lighting );
|
||||
GL.Enable( EnableCap.StencilTest );
|
||||
GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
GL.Enable(EnableCap.Lighting);
|
||||
GL.Enable(EnableCap.StencilTest);
|
||||
}
|
||||
this.SwapBuffers();
|
||||
}
|
||||
|
@ -298,12 +298,11 @@ namespace Examples.Tutorial
|
|||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
using ( StencilCSG example = new StencilCSG() )
|
||||
using (StencilCSG example = new StencilCSG())
|
||||
{
|
||||
Utilities.SetWindowTitle(example);
|
||||
example.Run( 30.0, 0.0 );
|
||||
example.Run(30.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace Examples.Tutorial
|
|||
ClearBufferMask.DepthBufferBit);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Texture);
|
||||
GL.Translate(e.Time/2, -e.Time, 0f);
|
||||
GL.Translate(e.Time / 2, -e.Time, 0f);
|
||||
|
||||
Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
|
||||
GL.MatrixMode(MatrixMode.Modelview);
|
||||
|
@ -136,9 +136,9 @@ namespace Examples.Tutorial
|
|||
|
||||
Bitmap bitmap = new Bitmap(filename);
|
||||
BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
||||
GL.TexImage2D(Target, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
|
||||
GL.Finish();
|
||||
bitmap.UnlockBits(data);
|
||||
GL.TexImage2D(Target, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
|
||||
GL.Finish();
|
||||
bitmap.UnlockBits(data);
|
||||
|
||||
if (GL.GetError() != ErrorCode.NoError)
|
||||
throw new Exception("Error loading texture " + filename);
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Examples.Tutorial
|
|||
/// <summary>
|
||||
/// Demonstrates simple OpenGL Texturing.
|
||||
/// </summary>
|
||||
[Example("Texture mapping", ExampleCategory.OpenGL, "1.x", 5, Documentation="Textures")]
|
||||
[Example("Texture mapping", ExampleCategory.OpenGL, "1.x", 5, Documentation = "Textures")]
|
||||
public class Textures : GameWindow
|
||||
{
|
||||
Bitmap bitmap = new Bitmap("Data/Textures/logo.jpg");
|
||||
|
|
|
@ -9,11 +9,11 @@ namespace Examples.Tutorial
|
|||
{
|
||||
|
||||
[Example("VBO Dynamic", ExampleCategory.OpenGL, "1.x", 4, Documentation = "VBODynamic")]
|
||||
class T09_VBO_Dynamic: GameWindow
|
||||
class T09_VBO_Dynamic : GameWindow
|
||||
{
|
||||
/// <summary>Creates a 800x600 window with the specified title.</summary>
|
||||
public T09_VBO_Dynamic( )
|
||||
: base( 800, 600 )
|
||||
public T09_VBO_Dynamic()
|
||||
: base(800, 600)
|
||||
{
|
||||
this.VSync = VSyncMode.Off;
|
||||
}
|
||||
|
@ -46,44 +46,44 @@ namespace Examples.Tutorial
|
|||
|
||||
/// <summary>Load resources here.</summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected override void OnLoad( EventArgs e )
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
GL.ClearColor( .1f, 0f, .1f, 0f );
|
||||
GL.Enable( EnableCap.DepthTest );
|
||||
GL.ClearColor(.1f, 0f, .1f, 0f);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
|
||||
// Setup parameters for Points
|
||||
GL.PointSize( 5f );
|
||||
GL.Enable( EnableCap.PointSmooth );
|
||||
GL.Hint( HintTarget.PointSmoothHint, HintMode.Nicest );
|
||||
GL.PointSize(5f);
|
||||
GL.Enable(EnableCap.PointSmooth);
|
||||
GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
|
||||
|
||||
// Setup VBO state
|
||||
GL.EnableClientState( EnableCap.ColorArray );
|
||||
GL.EnableClientState( EnableCap.VertexArray );
|
||||
GL.EnableClientState(EnableCap.ColorArray);
|
||||
GL.EnableClientState(EnableCap.VertexArray);
|
||||
|
||||
GL.GenBuffers( 1, out VBOHandle );
|
||||
GL.GenBuffers(1, out VBOHandle);
|
||||
|
||||
// Since there's only 1 VBO in the app, might aswell setup here.
|
||||
GL.BindBuffer( BufferTarget.ArrayBuffer, VBOHandle );
|
||||
GL.ColorPointer( 4, ColorPointerType.UnsignedByte, VertexC4ubV3f.SizeInBytes, (IntPtr) 0 );
|
||||
GL.VertexPointer( 3, VertexPointerType.Float, VertexC4ubV3f.SizeInBytes, (IntPtr) (4*sizeof(byte)) );
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VBOHandle);
|
||||
GL.ColorPointer(4, ColorPointerType.UnsignedByte, VertexC4ubV3f.SizeInBytes, (IntPtr)0);
|
||||
GL.VertexPointer(3, VertexPointerType.Float, VertexC4ubV3f.SizeInBytes, (IntPtr)(4 * sizeof(byte)));
|
||||
|
||||
Random rnd = new Random( );
|
||||
Random rnd = new Random();
|
||||
Vector3 temp = Vector3.Zero;
|
||||
|
||||
// generate some random stuff for the particle system
|
||||
for ( uint i = 0 ; i < MaxParticleCount ; i++ )
|
||||
for (uint i = 0; i < MaxParticleCount; i++)
|
||||
{
|
||||
VBO[i].R = (byte) rnd.Next( 0, 256 );
|
||||
VBO[i].G = (byte) rnd.Next( 0, 256 );
|
||||
VBO[i].B = (byte) rnd.Next( 0, 256 );
|
||||
VBO[i].A = (byte) rnd.Next( 0, 256 ); // isn't actually used
|
||||
VBO[i].R = (byte)rnd.Next(0, 256);
|
||||
VBO[i].G = (byte)rnd.Next(0, 256);
|
||||
VBO[i].B = (byte)rnd.Next(0, 256);
|
||||
VBO[i].A = (byte)rnd.Next(0, 256); // isn't actually used
|
||||
VBO[i].Position = Vector3.Zero; // all particles are born at the origin
|
||||
|
||||
// generate direction vector in the range [-0.25f...+0.25f]
|
||||
// that's slow enough so you can see particles 'disappear' when they are respawned
|
||||
temp.X = (float) ( ( rnd.NextDouble( ) - 0.5 ) * 0.5f );
|
||||
temp.Y = (float) ( ( rnd.NextDouble( ) - 0.5 ) * 0.5f );
|
||||
temp.Z = (float) ( ( rnd.NextDouble( ) - 0.5 ) * 0.5f );
|
||||
temp.X = (float)((rnd.NextDouble() - 0.5) * 0.5f);
|
||||
temp.Y = (float)((rnd.NextDouble() - 0.5) * 0.5f);
|
||||
temp.Z = (float)((rnd.NextDouble() - 0.5) * 0.5f);
|
||||
ParticleAttributes[i].Direction = temp; // copy
|
||||
ParticleAttributes[i].Age = 0;
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ namespace Examples.Tutorial
|
|||
|
||||
protected override void OnUnload(EventArgs e)
|
||||
{
|
||||
GL.DeleteBuffers( 1, ref VBOHandle );
|
||||
GL.DeleteBuffers(1, ref VBOHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -120,32 +120,33 @@ namespace Examples.Tutorial
|
|||
/// Called when it is time to setup the next frame. Add you game logic here.
|
||||
/// </summary>
|
||||
/// <param name="e">Contains timing information for framerate independent logic.</param>
|
||||
protected override void OnUpdateFrame( FrameEventArgs e )
|
||||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
if ( Keyboard[Key.Escape] )
|
||||
if (Keyboard[Key.Escape])
|
||||
{
|
||||
Exit( );
|
||||
Exit();
|
||||
}
|
||||
|
||||
// will update particles here. When using a Physics SDK, it's update rate is much higher than
|
||||
// the framerate and it would be a waste of cycles copying to the VBO more often than drawing it.
|
||||
if ( VisibleParticleCount < MaxParticleCount )
|
||||
if (VisibleParticleCount < MaxParticleCount)
|
||||
VisibleParticleCount++;
|
||||
|
||||
Vector3 temp;
|
||||
|
||||
for ( int i = MaxParticleCount - VisibleParticleCount ; i < MaxParticleCount ; i++ )
|
||||
for (int i = MaxParticleCount - VisibleParticleCount; i < MaxParticleCount; i++)
|
||||
{
|
||||
if (ParticleAttributes[i].Age >= MaxParticleCount)
|
||||
{
|
||||
// reset particle
|
||||
ParticleAttributes[i].Age = 0;
|
||||
VBO[i].Position = Vector3.Zero;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
ParticleAttributes[i].Age += (uint)Math.Max(ParticleAttributes[i].Direction.LengthFast * 10, 1);
|
||||
Vector3.Multiply( ref ParticleAttributes[i].Direction, (float) e.Time, out temp );
|
||||
Vector3.Add( ref VBO[i].Position, ref temp, out VBO[i].Position );
|
||||
Vector3.Multiply(ref ParticleAttributes[i].Direction, (float)e.Time, out temp);
|
||||
Vector3.Add(ref VBO[i].Position, ref temp, out VBO[i].Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,27 +155,27 @@ namespace Examples.Tutorial
|
|||
/// Called when it is time to render the next frame. Add your rendering code here.
|
||||
/// </summary>
|
||||
/// <param name="e">Contains timing information.</param>
|
||||
protected override void OnRenderFrame( FrameEventArgs e )
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
this.Title = VisibleParticleCount + " Points. FPS: " + string.Format( "{0:F}", 1.0 / e.Time );
|
||||
this.Title = VisibleParticleCount + " Points. FPS: " + string.Format("{0:F}", 1.0 / e.Time);
|
||||
|
||||
GL.Clear( ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit );
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
GL.PushMatrix( );
|
||||
GL.PushMatrix();
|
||||
|
||||
GL.Translate( 0f, 0f, -5f );
|
||||
GL.Translate(0f, 0f, -5f);
|
||||
|
||||
// Tell OpenGL to discard old VBO when done drawing it and reserve memory _now_ for a new buffer.
|
||||
// without this, GL would wait until draw operations on old VBO are complete before writing to it
|
||||
GL.BufferData( BufferTarget.ArrayBuffer, (IntPtr) ( VertexC4ubV3f.SizeInBytes * MaxParticleCount ), IntPtr.Zero, BufferUsageHint.StreamDraw );
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(VertexC4ubV3f.SizeInBytes * MaxParticleCount), IntPtr.Zero, BufferUsageHint.StreamDraw);
|
||||
// Fill newly allocated buffer
|
||||
GL.BufferData( BufferTarget.ArrayBuffer, (IntPtr) ( VertexC4ubV3f.SizeInBytes * MaxParticleCount ), VBO, BufferUsageHint.StreamDraw );
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(VertexC4ubV3f.SizeInBytes * MaxParticleCount), VBO, BufferUsageHint.StreamDraw);
|
||||
// Only draw particles that are alive
|
||||
GL.DrawArrays( BeginMode.Points, MaxParticleCount - VisibleParticleCount, VisibleParticleCount );
|
||||
GL.DrawArrays(BeginMode.Points, MaxParticleCount - VisibleParticleCount, VisibleParticleCount);
|
||||
|
||||
GL.PopMatrix( );
|
||||
GL.PopMatrix();
|
||||
|
||||
SwapBuffers( );
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -22,7 +22,7 @@ using System.Drawing;
|
|||
|
||||
namespace Examples.Tutorial
|
||||
{
|
||||
[Example("VBO Static", ExampleCategory.OpenGL, "1.x", 3, Documentation="VBOStatic")]
|
||||
[Example("VBO Static", ExampleCategory.OpenGL, "1.x", 3, Documentation = "VBOStatic")]
|
||||
public class T08_VBO : GameWindow
|
||||
{
|
||||
const float rotation_speed = 180.0f;
|
||||
|
|
Loading…
Reference in a new issue