Esempio n. 1
0
 //maybe indices is useful
 public static void AddRect(float x, float y, float width, float height, Color4 color, bool filled = true)
 {
     //draw command
     DrawCommandList.Enqueue(DrawCommand.Rectangle);
     //triangle 1
     DataBuffer.Enqueue(x);
     DataBuffer.Enqueue(y);
     DataBuffer.Enqueue(width);
     DataBuffer.Enqueue(height);
     DataBuffer.Enqueue(color);
     DataBuffer.Enqueue(filled);
 }
Esempio n. 2
0
        public static void Render()
        {
            if (!needRender)
            {
                return;
            }

            while (DrawCommandList.Count != 0)
            {
                var cmd = DrawCommandList.Dequeue();
                DrawByCommand(cmd);
            }
            DataBuffer.Clear();
            needRender = false;
        }
Esempio n. 3
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);
			}
		}