public void SetParameter(string _FieldName, TextureGPU _Texture) { if(_Texture!=null) shader.Parameters[_FieldName].SetValue(_Texture.texture); else shader.Parameters[_FieldName].SetValue((Texture)null); }
public static void Load() { font = new SpriteFont(@".\content\Arial.png", @".\content\Arial.xml"); handwrittenfont = new SpriteFont(@".\content\Handwritten.png", @".\content\Handwritten.xml"); GenericBrowserElementBackground = new TextureGPU(@".\content\GenericBrowserElementBackground.png"); GenericBrowserHeaderBackground = new TextureGPU(@".\content\GenericBrowserHeaderBackground.png"); Background = new TextureGPU(@".\content\Background.png"); }
public SpriteFont(string _TextureFileName, string _MetricsFileName) { spritefont = new TextureGPU(_TextureFileName); XElement file = XElement.Load(_MetricsFileName); foreach (XElement element in file.Elements("character")) { char charindex = (char)byte.Parse(element.Attribute("key").Value); CharBounds chr = new CharBounds(); int x = int.Parse(((string)element.Element("x").Value).Replace(",", "."), System.Globalization.NumberStyles.AllowDecimalPoint); int y = int.Parse(((string)element.Element("y").Value).Replace(",", "."), System.Globalization.NumberStyles.AllowDecimalPoint); int width = int.Parse(((string)element.Element("width").Value).Replace(",", "."), System.Globalization.NumberStyles.AllowDecimalPoint); int height = int.Parse(((string)element.Element("height").Value).Replace(",", "."), System.Globalization.NumberStyles.AllowDecimalPoint); chr.Pos = new Float2((float)x, (float)y); chr.Pos.X /= (float)spritefont.Size.X; chr.Pos.Y /= (float)spritefont.Size.Y; chr.Size = new Float2((float)width, (float)height); chr.Size.X /= (float)spritefont.Size.X; chr.Size.Y /= (float)spritefont.Size.Y; bounds.Add(charindex, chr); } }
public Form1() { InitializeComponent(); Graphics.Initialize(this.Handle, TargetResolution); ClientResources.Load(); ScreenSaverTarget = new RenderTarget(TargetResolution); ScreenSaverWobbleTarget = new RenderTarget(TargetResolution / 8, RenderTarget.SurfaceFormat.Float4Half); ScreenSaverShader = ShaderCompiler.Compile(System.IO.File.ReadAllText("screensaver.fx")); ScreenSaverBuffer = new TextureGPU(TargetResolution); ScreenSaverDroplet = new TextureGPUResource("./content/droplet.png"); //Root = new GenericBrowser(null); #if true Root = new UIBackground("", null); UIFloor floor4 = new UIFloor("floor4", Root); floor4.Level = 3; UIFloor floor3 = new UIFloor("floor3", Root); floor3.Level = 2; UIFloor floor2 = new UIFloor("floor2", Root); floor2.Level = 1; UIFloor floor1 = new UIFloor("floor1", Root); floor1.Level = 0; Floors.Add(floor1); Floors.Add(floor2); Floors.Add(floor3); Floors.Add(floor4); Control button1 = new UIButton("b1", floor4); button1.Transformation = Float3x3.Scale(0.1f) * Float3x3.Translate(new Float2(1, 1)); Control button2 = new UIAnalog("b2", floor4); button2.Transformation = Float3x3.Scale(0.1f) * Float3x3.Translate(new Float2(0, 0)); UIProgressBar progress = new UIProgressBar("p1", floor4); progress.Transformation = Float3x3.Scale(new Float2(0.3f, 0.1f)) * Float3x3.Translate(new Float2(0, 0.5f)); progress.Value = 50; #else Control button1 = new UIButton("b1", null); button1.Transformation = Float3x3.Translate(new Float2(0.5f, 0.5f)) * Float3x3.Scale(0.1f); Control button2 = new UIAnalog("b2", null); button2.Transformation = Float3x3.Translate(new Float2(0.5f, -0.5f)) * Float3x3.Scale(0.1f); Control button3 = new UIAnalog("b3", null); button3.Transformation = Float3x3.Translate(new Float2(-0.5f, 0.5f)) * Float3x3.Scale(0.1f); Control button4 = new UIAnalog("b4", null); button4.Transformation = Float3x3.Translate(new Float2(-0.5f, -0.5f)) * Float3x3.Scale(0.1f); ((UIButton)button1).Text = "button1"; ((UIAnalog)button2).Text = "button2"; ((UIAnalog)button3).Text = "button3"; ((UIAnalog)button4).Text = "button4"; Root = new UIBackground("", null); Root.AddChild(button1); Root.AddChild(button2); Root.AddChild(button3); Root.AddChild(button4); #endif //Root.Transformation = Float3x3.Scale(new Float2(2, -2)) * Float3x3.Translate(new Float2(-0.5f, -0.5f)); System.Windows.Forms.Application.Idle += new EventHandler(Application_Idle); }
public void Tick() { System.Drawing.Point mouse = PointToClient(MousePosition); Float2 cursorpos = new Float2( (float)mouse.X / (float)ClientRectangle.Width, (float)mouse.Y / (float)ClientRectangle.Height); cursorpos = cursorpos * 2 - new Float2(1, 1); cursorpos.Y = -cursorpos.Y; bool press = MouseButtons == System.Windows.Forms.MouseButtons.Left; if (press && !lastpress) presstime = Environment.TickCount; if ((press && lastpos != cursorpos) || lastpress != press) Root.HandleControllerInput(new UITouchEvent(cursorpos, press != lastpress && press == true, press != lastpress && press == false)); if (press) ScreenSaverStartTimer = Environment.TickCount + 60000; if (!press && lastpress && ScreenSaverEnabled && Environment.TickCount - presstime < 250) ScreenSaverStopTimer = Environment.TickCount + 10000; if (press) { ScreenSaverDropletPos = cursorpos; ScreenSaverCustomDroplet = true; } lastpress = press; Root.Update(); //optionally apply screensaver if (ScreenSaverEnabled) Graphics.SetRenderTarget(ScreenSaverTarget); //rotate scene SceneRotation += 0.005f; foreach (UIFloor f in Floors) { f.Rotation = (float)Math.Cos(SceneRotation) * ((float)Math.PI / 8.0f); } Root.Draw(); if (Environment.TickCount > ScreenSaverStartTimer && ScreenSaverStartTimer != 0) { ScreenSaverEnabled = true; ScreenSaverStartTimer = 0; ScreenSaverStopTimer = 0; frame1 = true; } if (ScreenSaverEnabled) { if (Environment.TickCount > ScreenSaverStopTimer && ScreenSaverStopTimer != 0) { ScreenSaverEnabled = false; ScreenSaverStopTimer = 0; } Graphics.SetRenderTarget(null); TextureGPU screenbuffer = ScreenSaverTarget.Resolve(); Graphics.SetBlendMode(Graphics.BlendMode.None); Graphics.SetRenderTarget(ScreenSaverWobbleTarget); ScreenSaverShader.SetParameter("RenderSize", new Float2(TargetResolution.X, TargetResolution.Y)); ScreenSaverShader.SetTechnique("Wobbler"); ScreenSaverShader.Begin(); Graphics.DrawRectangle( new Float2(-1, 1), new Float2(1, 1), new Float2(-1, -1), new Float2(1, -1), 0.5f); ScreenSaverShader.End(); if (frame1) Graphics.Clear(new Float4(0, 0, 0, 0)); if (ScreenSaverStopTimer == 0 && ScreenSaverDroplet.Get() != null) { if (ScreenSaverCustomDroplet) { Graphics.SetBlendMode(Graphics.BlendMode.Alpha); Graphics.defaultshader.SetParameter("View", new Float3x3(0.1f, 0, 0, 0, 0.1f, 0, ScreenSaverDropletPos.X, ScreenSaverDropletPos.Y, 1)); Graphics.defaultshader.SetParameter("DiffuseMap", (TextureGPU)ScreenSaverDroplet.Get()); Graphics.defaultshader.Begin(); Graphics.DrawRectangle( new Float2(-1, 1), new Float2(1, 1), new Float2(-1, -1), new Float2(1, -1), 0.5f); Graphics.defaultshader.End(); Graphics.SetBlendMode(Graphics.BlendMode.None); ScreenSaverCustomDroplet = false; } if (Environment.TickCount > ScreenSaverDropTimeout) { ScreenSaverDropTimeout = Environment.TickCount + random.Next(2000); Graphics.SetBlendMode(Graphics.BlendMode.Add); Graphics.defaultshader.SetParameter("View", new Float3x3(0.05f, 0, 0, 0, 0.05f, 0, (float)random.NextDouble() * 2 - 1, (float)random.NextDouble() * 2 - 1, 1)); Graphics.defaultshader.SetParameter("DiffuseMap", (TextureGPU)ScreenSaverDroplet.Get()); Graphics.defaultshader.Begin(); Graphics.DrawRectangle( new Float2(-1, 1), new Float2(1, 1), new Float2(-1, -1), new Float2(1, -1), 0.5f); Graphics.defaultshader.End(); Graphics.SetBlendMode(Graphics.BlendMode.None); } } Graphics.SetRenderTarget(null); ScreenSaverBuffer = ScreenSaverWobbleTarget.Resolve(); ScreenSaverShader.SetParameter("WobblerMap", ScreenSaverBuffer); ScreenSaverShader.SetParameter("DiffuseMap", screenbuffer); ScreenSaverShader.SetTechnique("Main"); ScreenSaverShader.Begin(); Graphics.DrawRectangle( new Float2(-1, 1), new Float2(1, 1), new Float2(-1, -1), new Float2(1, -1), 0.5f); ScreenSaverShader.End(); Graphics.SetBlendMode(Graphics.BlendMode.Alpha); } Synergy.Graphics.Present(p_WorkingArea.Handle); ResourceManager.Update(); frame1 = false; }
void Load() { try { #if false//SIMULATE LOADING for (int i = 0; i < 100; i++) { System.Threading.Thread.Sleep(100); LoadingProgress = (float)i / 100.0f; } data = new TextureGPU(ResourceName); #else LoadingProgress = 0; data = new TextureGPU(ResourceName); LoadingProgress = 1; #endif } catch { status = ResourceStatus.Failed; } finally { status = ResourceStatus.Loaded; } }