From 148578b1eb73030b265b4e793d3254009572a169 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sat, 9 Oct 2010 19:59:06 +0000 Subject: [PATCH] Fixed code formatting. --- Source/Examples/OpenGL/1.x/DisplayLists.cs | 6 +- .../Examples/OpenGL/1.x/FramebufferObject.cs | 10 +- Source/Examples/OpenGL/1.x/ImmediateMode.cs | 11 +- Source/Examples/OpenGL/1.x/StencilCSG.cs | 131 +++++++++--------- Source/Examples/OpenGL/1.x/TextureMatrix.cs | 10 +- Source/Examples/OpenGL/1.x/Textures.cs | 6 +- Source/Examples/OpenGL/1.x/VBODynamic.cs | 93 +++++++------ Source/Examples/OpenGL/1.x/VBOStatic.cs | 6 +- 8 files changed, 137 insertions(+), 136 deletions(-) diff --git a/Source/Examples/OpenGL/1.x/DisplayLists.cs b/Source/Examples/OpenGL/1.x/DisplayLists.cs index 43c76ea4..c030c6a2 100644 --- a/Source/Examples/OpenGL/1.x/DisplayLists.cs +++ b/Source/Examples/OpenGL/1.x/DisplayLists.cs @@ -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); diff --git a/Source/Examples/OpenGL/1.x/FramebufferObject.cs b/Source/Examples/OpenGL/1.x/FramebufferObject.cs index af5ed352..69fd28da 100644 --- a/Source/Examples/OpenGL/1.x/FramebufferObject.cs +++ b/Source/Examples/OpenGL/1.x/FramebufferObject.cs @@ -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() @@ -26,7 +26,7 @@ namespace Examples.Tutorial } Font sans = new Font(System.Drawing.FontFamily.GenericSansSerif, 16.0f); - + uint ColorTexture; uint DepthTexture; uint FBOHandle; @@ -62,7 +62,7 @@ namespace Examples.Tutorial System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); Exit(); } - + GL.Enable(EnableCap.DepthTest); GL.ClearDepth(1.0f); GL.DepthFunc(DepthFunction.Lequal); @@ -217,7 +217,7 @@ namespace Examples.Tutorial protected override void OnResize(EventArgs e) { GL.Viewport(0, 0, Width, Height); - + double aspect_ratio = Width / (double)Height; OpenTK.Matrix4 perspective = OpenTK.Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)aspect_ratio, 1, 64); @@ -242,7 +242,7 @@ namespace Examples.Tutorial protected override void OnRenderFrame(FrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - + GL.PushMatrix(); { // Draw the Color Texture diff --git a/Source/Examples/OpenGL/1.x/ImmediateMode.cs b/Source/Examples/OpenGL/1.x/ImmediateMode.cs index 1f25bc76..45029830 100644 --- a/Source/Examples/OpenGL/1.x/ImmediateMode.cs +++ b/Source/Examples/OpenGL/1.x/ImmediateMode.cs @@ -25,7 +25,7 @@ namespace Examples.Tutorial /// /// Demonstrates immediate mode rendering. /// - [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 @@ -114,7 +115,7 @@ namespace Examples.Tutorial Matrix4 lookat = Matrix4.LookAt(0, 5, 5, 0, 0, 0, 0, 1, 0); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref lookat); - + angle += rotation_speed * (float)e.Time; GL.Rotate(angle, 0.0f, 1.0f, 0.0f); diff --git a/Source/Examples/OpenGL/1.x/StencilCSG.cs b/Source/Examples/OpenGL/1.x/StencilCSG.cs index 1c6f6f1a..90221af8 100644 --- a/Source/Examples/OpenGL/1.x/StencilCSG.cs +++ b/Source/Examples/OpenGL/1.x/StencilCSG.cs @@ -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.ColorMask( false, false, false, false ); - GL.CullFace( CullFaceMode.Front ); + GL.Disable(EnableCap.StencilTest); + + 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); } } - } } diff --git a/Source/Examples/OpenGL/1.x/TextureMatrix.cs b/Source/Examples/OpenGL/1.x/TextureMatrix.cs index b7f66f03..180de30a 100644 --- a/Source/Examples/OpenGL/1.x/TextureMatrix.cs +++ b/Source/Examples/OpenGL/1.x/TextureMatrix.cs @@ -11,7 +11,7 @@ namespace Examples.Tutorial { [Example("Texture Matrix Wormhole", ExampleCategory.OpenGL, "1.x", Documentation = "TextureMatrix")] - + class TextureMatrix : GameWindow { @@ -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); diff --git a/Source/Examples/OpenGL/1.x/Textures.cs b/Source/Examples/OpenGL/1.x/Textures.cs index 8918e1a8..dd43f36b 100644 --- a/Source/Examples/OpenGL/1.x/Textures.cs +++ b/Source/Examples/OpenGL/1.x/Textures.cs @@ -22,7 +22,7 @@ namespace Examples.Tutorial /// /// Demonstrates simple OpenGL Texturing. /// - [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"); @@ -42,7 +42,7 @@ namespace Examples.Tutorial GL.Enable(EnableCap.Texture2D); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); - + GL.GenTextures(1, out texture); GL.BindTexture(TextureTarget.Texture2D, texture); @@ -51,7 +51,7 @@ namespace Examples.Tutorial GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); - + bitmap.UnlockBits(data); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); diff --git a/Source/Examples/OpenGL/1.x/VBODynamic.cs b/Source/Examples/OpenGL/1.x/VBODynamic.cs index 3aede568..72d6bacc 100644 --- a/Source/Examples/OpenGL/1.x/VBODynamic.cs +++ b/Source/Examples/OpenGL/1.x/VBODynamic.cs @@ -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 { /// Creates a 800x600 window with the specified title. - public T09_VBO_Dynamic( ) - : base( 800, 600 ) + public T09_VBO_Dynamic() + : base(800, 600) { this.VSync = VSyncMode.Off; } @@ -42,48 +42,48 @@ namespace Examples.Tutorial } uint VBOHandle; - #endregion Particles + #endregion Particles /// Load resources here. /// Not used. - 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); } /// @@ -120,32 +120,33 @@ namespace Examples.Tutorial /// Called when it is time to setup the next frame. Add you game logic here. /// /// Contains timing information for framerate independent logic. - 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. /// /// Contains timing information. - 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(); } /// diff --git a/Source/Examples/OpenGL/1.x/VBOStatic.cs b/Source/Examples/OpenGL/1.x/VBOStatic.cs index 58037487..f6298a65 100644 --- a/Source/Examples/OpenGL/1.x/VBOStatic.cs +++ b/Source/Examples/OpenGL/1.x/VBOStatic.cs @@ -22,15 +22,15 @@ 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; float angle; - + struct Vbo { public int VboID, EboID, NumElements; } Vbo[] vbo = new Vbo[2]; - + VertexPositionColor[] CubeVertices = new VertexPositionColor[] { new VertexPositionColor(-1.0f, -1.0f, 1.0f, Color.DarkRed),