Beispiel #1
0
 /// <summary>
 /// Method for raising <see cref="GraphicsContextDestroyed"/>
 /// </summary>
 /// <param name="args">
 /// The <see cref="GraphicsControlEventArgs"/> that specify the event arguments.
 /// </param>
 protected void RaiseGraphicsContextDestroyed(GraphicsControlEventArgs args)
 {
     if (GraphicsContextDestroyed != null)
     {
         GraphicsContextDestroyed(this, args);
     }
 }
Beispiel #2
0
        private void GraphicsControl_GraphicsContextCreated(object sender, OpenGL.GraphicsControlEventArgs e)
        {
            // Program
            _Program = ShadersLibrary.Instance.CreateProgram("OpenGL.Standard+Color");
            _Program.Create(e.Context);

            // Position array buffer
            ArrayBufferObject <Vertex2f> _ArrayPosition = new ArrayBufferObject <Vertex2f>(BufferObjectHint.StaticCpuDraw);

            _ArrayPosition.Create(e.Context, new Vertex2f[] {
                new Vertex2f(0.0f, 0.0f),
                new Vertex2f(0.5f, 1.0f),
                new Vertex2f(1.0f, 0.0f)
            });

            // Color array buffer
            ArrayBufferObject <ColorRGBF> _ArrayColor = new ArrayBufferObject <ColorRGBF>(BufferObjectHint.StaticCpuDraw);

            _ArrayColor.Create(e.Context, new ColorRGBF[] {
                new ColorRGBF(1.0f, 0.0f, 0.0f),
                new ColorRGBF(0.0f, 1.0f, 0.0f),
                new ColorRGBF(0.0f, 0.0f, 1.0f)
            });

            // Vertex array
            _VertexArray = new VertexArrayObject();
            _VertexArray.SetArray(_ArrayPosition, VertexArraySemantic.Position);
            _VertexArray.SetArray(_ArrayColor, VertexArraySemantic.Color);
            _VertexArray.SetElementArray(PrimitiveType.Triangles, 0, 3);
            _VertexArray.Create(e.Context);
        }
Beispiel #3
0
 /// <summary>
 /// Method for raising <see cref="Render"/>
 /// </summary>
 /// <param name="args">
 /// The <see cref="GraphicsControlEventArgs"/> that specify the event arguments.
 /// </param>
 protected void RaiseRenderEvent(GraphicsControlEventArgs args)
 {
     if (Render != null)
     {
         try {
             Render(this, args);
         } catch (Exception exception) {
             sLog.Error("RenderControl.Render exception caught", exception);
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// Method for raising <see cref="GraphicsContextCreated"/>
 /// </summary>
 /// <param name="args">
 /// The <see cref="GraphicsControlEventArgs"/> that specify the event arguments.
 /// </param>
 protected void RaiseGraphicsContextCreated(GraphicsControlEventArgs args)
 {
     if (GraphicsContextCreated != null)
     {
         try {
             GraphicsContextCreated(this, args);
         } catch (Exception exception) {
             sLog.Error("Unable to create resources.", exception);
         }
     }
 }
Beispiel #5
0
		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));
		}
Beispiel #6
0
		private void SampleGraphicsControl_Render(object sender, GraphicsControlEventArgs e)
		{
			GraphicsContext ctx = e.Context;
			GraphicsSurface framebuffer = e.Framebuffer;

			if (_AnimationBegin == DateTime.MinValue)
				_AnimationBegin = DateTime.UtcNow;

			PerspectiveProjectionMatrix matrixProjection = new PerspectiveProjectionMatrix();
			Matrix4x4 matrixView;

			// Set projection
			matrixProjection.SetPerspective(60.0f, (float)ClientSize.Width / (float)ClientSize.Height, 1.0f, 1000.0f);
			// Set view
			ModelMatrix matrixViewModel = new ModelMatrix();
			matrixViewModel.RotateX(_ViewElevation);
			matrixViewModel.RotateY(_ViewAzimuth);
			matrixViewModel.Translate(0.0f, 0.0f, _ViewDistance);
			matrixView = matrixViewModel.GetInverseMatrix();

			_NewtonProgram.Bind(ctx);
			_NewtonProgram.SetUniform(ctx, "hal_ModelViewProjection", matrixProjection * matrixView);
			_NewtonProgram.SetUniform(ctx, "hal_FrameTimeInterval", (float)(DateTime.UtcNow - _AnimationBegin).TotalSeconds);

			_NewtonVertexArray.Draw(ctx, _NewtonProgram);

			SwapNewtonVertexArrays();

			// Issue another rendering
			SampleGraphicsControl.Invalidate();
		}
		/// <summary>
		/// Method for raising <see cref="Render"/>
		/// </summary>
		/// <param name="args">
		/// The <see cref="GraphicsControlEventArgs"/> that specify the event arguments.
		/// </param>
		protected void RaiseRenderEvent(GraphicsControlEventArgs args)
		{
			if (Render != null) {
				try {
					Render(this, args);
				} catch (Exception exception) {
					sLog.Error("RenderControl.Render exception caught", exception);
				}
			}
				
		}
		/// <summary>
		/// Method for raising <see cref="GraphicsContextDestroyed"/>
		/// </summary>
		/// <param name="args">
		/// The <see cref="GraphicsControlEventArgs"/> that specify the event arguments.
		/// </param>
		protected void RaiseGraphicsContextDestroyed(GraphicsControlEventArgs args)
		{
			if (GraphicsContextDestroyed != null)
				GraphicsContextDestroyed(this, args);
		}
		/// <summary>
		/// Method for raising <see cref="GraphicsContextCreated"/>
		/// </summary>
		/// <param name="args">
		/// The <see cref="GraphicsControlEventArgs"/> that specify the event arguments.
		/// </param>
		protected void RaiseGraphicsContextCreated(GraphicsControlEventArgs args)
		{
			if (GraphicsContextCreated != null) {
				try {
					GraphicsContextCreated(this, args);
				} catch (Exception exception) {
					sLog.Error("Unable to create resources.", exception);
				}
			}
		}