コード例 #1
0
		private void WriteCommentWithLine(NxFont font, string comment, QFontAlignment alignment, float xOffset, ref float yOffset)
		{
			//GL.PushMatrix();
				yOffset += 20;
				var offset = new Vector3((int)xOffset, yOffset, 0f);
				var transform = Matrix4.CreateTranslation(offset);
				var mvp = Matrix4.Mult (transform, mOrthographicMatrix);
				font.Print(mvp, comment, alignment);
				var bounds = font.SafeMeasure(ClientRectangle, comment, Width-60, alignment);

//				GL.Disable(EnableCap.Texture2D);
//				GL.Begin(BeginMode.Lines);
//					GL.Color4(1.0f, 0f, 0f, 1f); 
//					GL.Vertex2(0f, 0f);
//					GL.Color4(1.0f, 0f, 0f, 1f); 
//					GL.Vertex2(0f, bounds.Height + 20f);
//				GL.End();

				yOffset += bounds.Height;

		//	GL.PopMatrix();
		}
コード例 #2
0
		private void PrintWithBounds(NxFont font, string text, RectangleF bounds, QFontAlignment alignment, ref float yOffset)
		{
//			GL.Disable(EnableCap.Texture2D);
//			GL.Color4(1.0f, 0f, 0f, 1.0f);

			float maxWidth = bounds.Width;

			float height = font.SafeMeasure(ClientRectangle, text, maxWidth, alignment).Height;

//			GL.Begin(BeginMode.LineLoop);
//				GL.Vertex3(bounds.X, bounds.Y, 0f);
//				GL.Vertex3(bounds.X + bounds.Width, bounds.Y, 0f);
//				GL.Vertex3(bounds.X + bounds.Width, bounds.Y + height, 0f);
//				GL.Vertex3(bounds.X, bounds.Y + height, 0f);
//			GL.End();

			font.PrintAt(ClientRectangle, text, maxWidth, alignment, new Vector2(bounds.X,bounds.Y));

			yOffset += height;

		}
コード例 #3
0
		private void WriteComment(NxFont font, string comment,QFontAlignment alignment, ref float yOffset)
		{
			//GL.PushMatrix();
				yOffset += 20;
				var offset = new Vector3(30f, yOffset, 0f);
				var transform = Matrix4.CreateTranslation(offset);

				var mvp = Matrix4.Mult (transform, mOrthographicMatrix);

				font.SafePrint(mvp, ClientRectangle, comment, Width - 60, alignment);
				yOffset += font.SafeMeasure(ClientRectangle, comment, Width - 60, alignment).Height;
			//GL.PopMatrix();
		}
コード例 #4
0
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			InitialiseKeyDown ();

			// setup settings, load textures, sounds
			this.VSync = VSyncMode.On;
			this.WindowBorder = WindowBorder.Fixed;

			var screenMatrix = Matrix4.CreateOrthographicOffCenter(ClientRectangle.X, Width, Height, ClientRectangle.Y, -1, 1);

			var singleDrawCommand = new DrawCommandList ();

			var fontFileLoader = new NxFontFileLoader ();

			var heading2Config = new NxFontLoaderConfiguration (singleDrawCommand, screenMatrix, true);
			heading2 = fontFileLoader.Load("woodenFont.qfont", Height, 1.0f, heading2Config);

			var builderConfig = new NxFontBuilderConfiguration(singleDrawCommand, screenMatrix, true);
			builderConfig.BlurRadius = 1; //reduce blur radius because font is very small
			builderConfig.TextGenerationRenderHint = TextGenerationRenderHint.ClearTypeGridFit; //best render hint for this font
			mainText = new NxFont("Fonts/times.ttf", 14,  Height, builderConfig);

			var heading1Config = new NxFontBuilderConfiguration(singleDrawCommand, screenMatrix, true);
			heading1Config.Transform = screenMatrix;
			heading1 = new NxFont("Fonts/HappySans.ttf", 72, Height, heading1Config);

			var buildConfig = new NxFontBuilderConfiguration (singleDrawCommand, screenMatrix, true);
			controlsText = new NxFont("Fonts/HappySans.ttf", 32,  Height, buildConfig);

			var noShadowConfig = new NxFontBuilderConfiguration (singleDrawCommand, screenMatrix);
			codeText = new NxFont("Fonts/Comfortaa-Regular.ttf", 12,  Height, FontStyle.Regular, noShadowConfig);

			heading1.Options.Colour = new Color4(0.2f, 0.2f, 0.2f, 1.0f);
			mainText.Options.Colour = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
			mainText.Options.DropShadowActive = false;
			codeText.Options.Colour = new Color4(0.0f, 0.0f, 0.4f, 1.0f);

			//					var config2 = new NxFontBuilderConfiguration(screenMatrix);
			//					config2.SuperSampleLevels = 1;
			//   font = new QFont("Fonts/times.ttf", 16,config2);
			//   font.Options.Colour = new Color4(0.1f, 0.1f, 0.1f, 1.0f);
			//   font.Options.CharacterSpacing = 0.1f;

			monoSpaced = new NxFont("Fonts/Anonymous.ttf", 10, Height, noShadowConfig);
			monoSpaced.Options.Colour = new Color4(0.1f, 0.1f, 0.1f, 1.0f);

			Console.WriteLine(" Monospaced : " + monoSpaced.IsMonospacingActive);

			GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
			GL.Disable(EnableCap.DepthTest);

			mOrthographicMatrix = Matrix4.CreateOrthographicOffCenter (0f, ClientRectangle.Width, ClientRectangle.Height, 0f, -1.0f, 1f);

			GenerateRightArrow ();
			var rightArrowCommands = singleDrawCommand.GetCommands ();
			singleDrawCommand.ClearCommandsOnly ();

			GenerateLeftArrow ();
			var leftArrowCommands = singleDrawCommand.GetCommands ();
			singleDrawCommand.ClearCommandsOnly ();


			var pageCommands = new List<DrawElementsIndirectCommand[]> ();
			for (int i = FIRST_PAGE; i < MAX_PAGES; ++i)
			{
				currentDemoPage = i;
				GenerateText ();
				pageCommands.Add (singleDrawCommand.GetCommands ());
				singleDrawCommand.ClearCommandsOnly ();
			}
			currentDemoPage = FIRST_PAGE;

			mSharedVertexBuffer = singleDrawCommand.AsStaticText ();
			var bufferArray = singleDrawCommand.Blocks.ToArray ();
			mConstantBuffer = new SentanceBlockStorageBuffer (bufferArray, BufferUsageHint.StaticDraw);


			screenPages = new TextOutput[MAX_PAGES];
			for (int i = 0; i < MAX_PAGES; ++i)
			{
				screenPages[i] = new TextOutput (mSharedVertexBuffer, pageCommands[i], mConstantBuffer); 
			}

			leftArrow = new TextOutput (mSharedVertexBuffer, leftArrowCommands, mConstantBuffer);
			rightArrow = new TextOutput (mSharedVertexBuffer, rightArrowCommands, mConstantBuffer);



			CheckGLError ();

			InitialiseUnload ();

			using (var vert = File.OpenRead (@"Shaders/BindlessTex.vert"))
			using (var frag = File.OpenRead (@"Shaders/BindlessTex.frag"))				
			{
				var manager = new ShaderManager ();
				programID = manager.CreateFragmentProgram (vert, frag, "");

				GL.UseProgram (programID);
					mSharedVertexBuffer.BindManually (programID);					
				GL.BindVertexArray (0);
				GL.UseProgram (0);
			}
		}