当前位置: 首页>>代码示例>>C#>>正文


C# VertexBuffer.Render方法代码示例

本文整理汇总了C#中VertexBuffer.Render方法的典型用法代码示例。如果您正苦于以下问题:C# VertexBuffer.Render方法的具体用法?C# VertexBuffer.Render怎么用?C# VertexBuffer.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VertexBuffer的用法示例。


在下文中一共展示了VertexBuffer.Render方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main


//.........这里部分代码省略.........
							game.Exit();
							break;
						case Key.R:
							zoom = 1;
							break;
						case Key.W:
							if (wDown)
								translate += new Vector2(1f, 1f);
							wDown = false;
							break;
						case Key.A:
							if (aDown)
								translate += new Vector2(1f, -1f);
							aDown = false;
							break;
						case Key.S:
							if (sDown)
								translate += new Vector2(-1f, -1f);
							sDown = false;
							break;
						case Key.D:
							if (dDown)
								translate += new Vector2(-1f, 1f);
							dDown = false;
							break;
					}
				};

				double time=0, sin = 0;

				game.UpdateFrame +=
					delegate(object sender, FrameEventArgs e) {
						time += e.Time;
						sin = (Math.Sin(time/4) + 1) / 2;
						game.Title = $"Heart of Gold - {game.RenderFrequency:000.00}fps - {game.UpdateFrequency:000.00}tps";
					};

				var items = new List<BufferElement>(size * size * 12);
				Console.WriteLine("Prepping buffer elements...");
				//First half
				var side = matrix.GetLength(0);
				var half = side / 2;
				for (var i = 0; i < side; i++) {
					Console.Write($"\rCreating row {i,4} of {side}");
					int x = i, y = 0;
					while (x >= 0) {
						var hasleft = y != side - 1;
						var hasright = x != side - 1;
						var left = hasleft ? (double?)matrix[x, y + 1] : -2;
						var right = hasright ? (double?)matrix[x + 1, y] : -2;
						items.AddRange(AddOne(matrix[x, y], x - half, y - half, cmatrix[x--, y++], left, right));
					}
				}
				// Pt 2
				for (var i = 1; i <= side - 1; i++) {
					Console.Write($"\rCreating column {i,4} of {side}");
					int x = side - 1, y = i;
					while (y < side) {
						var hasleft = y != side - 1; var hasright = x != side - 1;
						var left = hasleft ? (double?)matrix[x, y + 1] : -2;
						var right = hasright ? (double?)matrix[x + 1, y] : -2;
						items.AddRange(AddOne(matrix[x, y], x - half, y - half, cmatrix[x--, y++], left, right));
					}
				}
				Console.WriteLine("\rCreating vertex buffer object...           ");
				Action a = delegate {
					GL.EnableClientState(ArrayCap.VertexArray);
					GL.EnableClientState(ArrayCap.ColorArray);
					GL.VertexPointer(3, VertexPointerType.Float, BufferElement.SizeInBytes, new IntPtr(0));
					GL.ColorPointer(3, ColorPointerType.Float, BufferElement.SizeInBytes, new IntPtr(Vector3.SizeInBytes));
				};
				var terrain = new VertexBuffer<BufferElement>(items.ToArray(), a, BufferUsageHint.StaticDraw);
				Console.WriteLine("Done!");
				game.RenderFrame += delegate {
					// render graphics
					GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
					GL.MatrixMode(MatrixMode.Projection);
					GL.LoadIdentity();

					GL.Ortho(size, -size, size, -size, -double.MaxValue, double.MaxValue);

					GL.Scale(1*zoom, (game.Width/(double) game.Height)*zoom, 1*zoom);
					GL.Rotate(90*sin, 1, 0, 0);
					GL.Rotate(45, 0, 0, 1);
					GL.Translate(translate.X, translate.Y, -matrix[(int) -translate.X + half, (int) -translate.Y + half]);

					terrain.Render(PrimitiveType.Quads);

					//GL.Begin(PrimitiveType.LineLoop);

					//DrawOne(matrix[(int) -translate.X + half, (int) -translate.Y + half], (int) -translate.X, (int) -translate.Y,
					//	Color.Black);
					//GL.End();

					game.SwapBuffers();
				};
				game.WindowState = WindowState.Maximized;
				game.Run(60.0, 60);
			}
		}
开发者ID:Sidneys1,项目名称:HeartOfGold,代码行数:101,代码来源:Program.cs


注:本文中的VertexBuffer.Render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。