コード例 #1
0
ファイル: SampleForm.cs プロジェクト: vazgriz/OpenGL.Net
        private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e)
        {
            GraphicsContext ctx         = e.Context;
            GraphicsSurface framebuffer = e.Framebuffer;

            // Create Newton program
            _NewtonProgram = ShadersLibrary.Instance.CreateProgram("Newton");
            _NewtonProgram.AddFeedbackVarying("hal_VertexPosition");
            _NewtonProgram.AddFeedbackVarying("hal_VertexSpeed");
            _NewtonProgram.AddFeedbackVarying("hal_VertexAcceleration");
            _NewtonProgram.AddFeedbackVarying("hal_VertexMass");
            _NewtonProgram.Create(ctx);

            // Initialize first vertex array
            NewtonVertex[] newtonArray = new NewtonVertex[VertexCount];
            Random         random      = new Random();

            for (int i = 0; i < newtonArray.Length; i++)
            {
                NewtonVertex newtonVertex = new NewtonVertex();

                newtonVertex.Position     = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized());
                newtonVertex.Speed        = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized());
                newtonVertex.Acceleration = new Vertex3f();
                newtonVertex.Mass         = RandomNormalized();

                newtonArray[i] = newtonVertex;
            }

            // Create vertex arrays
            ArrayBufferObjectBase newtonVertexArrayBuffer1, newtonVertexArrayBuffer2;

            _NewtonVertexArray1 = CreateVertexArray(newtonArray, out newtonVertexArrayBuffer1);
            _NewtonVertexArray2 = CreateVertexArray(null, out newtonVertexArrayBuffer2);

            _NewtonVertexArray1.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer2));
            _NewtonVertexArray2.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer1));

            _NewtonVertexArray1.Create(ctx);
            _NewtonVertexArray2.Create(ctx);

            // Starts from initialized buffer
            _NewtonVertexArray = _NewtonVertexArray1;

            // Clear color
            framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f));
        }
コード例 #2
0
ファイル: SampleForm.cs プロジェクト: rhynodegreat/OpenGL.Net
		private void SampleGraphicsControl_GraphicsContextCreated(object sender, GraphicsControlEventArgs e)
		{
			GraphicsContext ctx = e.Context;
			GraphicsSurface framebuffer = e.Framebuffer;

			// Create Newton program
			_NewtonProgram = ShadersLibrary.Instance.CreateProgram("Newton");
			_NewtonProgram.AddFeedbackVarying("hal_VertexPosition");
			_NewtonProgram.AddFeedbackVarying("hal_VertexSpeed");
			_NewtonProgram.AddFeedbackVarying("hal_VertexAcceleration");
			_NewtonProgram.AddFeedbackVarying("hal_VertexMass");
			_NewtonProgram.Create(ctx);

			// Initialize first vertex array
			NewtonVertex[] newtonArray = new NewtonVertex[VertexCount];
			Random random = new Random();

			for (int i = 0; i < newtonArray.Length; i++) {
				NewtonVertex newtonVertex = new NewtonVertex();

				newtonVertex.Position = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized());
				newtonVertex.Speed = new Vertex3f(RandomNormalized(), RandomNormalized(), RandomNormalized());
				newtonVertex.Acceleration = new Vertex3f();
				newtonVertex.Mass = RandomNormalized();

				newtonArray[i] = newtonVertex;
			}

			// Create vertex arrays
			ArrayBufferObjectBase newtonVertexArrayBuffer1, newtonVertexArrayBuffer2;

			_NewtonVertexArray1 = CreateVertexArray(newtonArray, out newtonVertexArrayBuffer1);
			_NewtonVertexArray2 = CreateVertexArray(null, out newtonVertexArrayBuffer2);

			_NewtonVertexArray1.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer2));
			_NewtonVertexArray2.SetTransformFeedback(CreateFeedbackBuffer(newtonVertexArrayBuffer1));

			_NewtonVertexArray1.Create(ctx);
			_NewtonVertexArray2.Create(ctx);

			// Starts from initialized buffer
			_NewtonVertexArray = _NewtonVertexArray1;

			// Clear color
			framebuffer.SetClearColor(new ColorRGBAF(0.0f, 0.0f, 0.0f));
		}
コード例 #3
0
ファイル: SampleForm.cs プロジェクト: rhynodegreat/OpenGL.Net
		private VertexArrayObject CreateVertexArray(NewtonVertex[] array, out ArrayBufferObjectBase interleavedArrayBuffer)
		{
			VertexArrayObject newtonVertexArray = new VertexArrayObject();
			ArrayBufferObjectInterleaved newtonVertexArrayBuffer = new ArrayBufferObjectInterleaved(typeof(NewtonVertex), BufferObjectHint.DynamicGpuDraw);

			if (array != null)
				newtonVertexArrayBuffer.Create(array);
			else
				newtonVertexArrayBuffer.Create(VertexCount);
			newtonVertexArray.SetArray(newtonVertexArrayBuffer, 0, VertexArraySemantic.Position);
			newtonVertexArray.SetArray(newtonVertexArrayBuffer, 1, VertexArraySemantic.Speed);
			newtonVertexArray.SetArray(newtonVertexArrayBuffer, 2, VertexArraySemantic.Acceleration);
			newtonVertexArray.SetArray(newtonVertexArrayBuffer, 3, VertexArraySemantic.Mass);
			newtonVertexArray.SetElementArray(PrimitiveType.Points);

			interleavedArrayBuffer = newtonVertexArrayBuffer;

			return (newtonVertexArray);
		}