public MiniTriSample() { this.Window.Title = "Samurai Mini Tri Sample"; this.Graphics.ClearColor = Color4.CornflowerBlue; //this.vertexBuffer = new StaticVertexBuffer<Vertex>(this.Graphics, verticies); VertexElement[] elements = new VertexElement[] { new VertexElement(VertexElementType.Float, 3, 0, 12), new VertexElement(VertexElementType.Float, 4, 36, 16) }; using (DataBuffer data = DataBuffer.Create(verticies)) { this.vertexBuffer = new StaticVertexBuffer(this.Graphics, elements, data); } this.shaderProgram = new ShaderProgram(this.Graphics, VertexShader.Compile(this.Graphics, vertexShaderCode), FragmentShader.Compile(this.Graphics, fragmentShaderCode) ); this.Graphics.ShaderProgram = this.shaderProgram; }
public WavingFlagSample() : base() { this.Window.Title = "Samurai Waving Flag Sample"; this.shader = new ShaderProgram( this.Graphics, VertexShader.Compile(this.Graphics, File.ReadAllText("WavingFlagSample.vert")), FragmentShader.Compile(this.Graphics, File.ReadAllText("WavingFlagSample.frag"))); this.Graphics.ShaderProgram = this.shader; this.texture = Texture2D.LoadFromFile(this.Graphics, "Flag.png", TextureParams.Default); int totalChunks = 100; int chunkSize = this.texture.Width / totalChunks; Rectangle destination = new Rectangle( (this.Window.Width - this.texture.Width) / 2, (this.Window.Height - this.texture.Height) / 2, chunkSize, this.texture.Height); Rectangle source = new Rectangle(0, 0, chunkSize, this.texture.Height); Vertex[] vertexData = new Vertex[totalChunks * 4]; for (int i = 0; i < totalChunks * 4; i += 4) { vertexData[i] = new Vertex() { Position = new Vector2(destination.X, destination.Y), UV = new Vector2(source.X / (float)texture.Width, 0) }; vertexData[i + 1] = new Vertex() { Position = new Vector2(destination.X + chunkSize, destination.Y), UV = new Vector2((source.X + chunkSize) / (float)texture.Width, 0) }; vertexData[i + 2] = new Vertex() { Position = new Vector2(destination.X + chunkSize, destination.Y + this.texture.Height), UV = new Vector2((source.X + chunkSize) / (float)texture.Width, 1.0f) }; vertexData[i + 3] = new Vertex() { Position = new Vector2(destination.X, destination.Y + this.texture.Height), UV = new Vector2(source.X / (float)texture.Width, 1.0f) }; destination.X += chunkSize; source.X += chunkSize; } this.vertexBuffer = new StaticVertexBuffer<Vertex>(this.Graphics, vertexData); ushort[] indexData = new ushort[vertexData.Length * 6]; for (ushort i = 0, vertex = 0; i < indexData.Length; i += 6, vertex += 4) { indexData[i] = vertex; indexData[i + 1] = (ushort)(vertex + 1); indexData[i + 2] = (ushort)(vertex + 2); indexData[i + 3] = vertex; indexData[i + 4] = (ushort)(vertex + 2); indexData[i + 5] = (ushort)(vertex + 3); } this.indexBuffer = new StaticIndexBuffer<ushort>(this.Graphics, indexData); }
public FractalSample() { this.Window.Title = "Fractals"; this.shaderProgram = new ShaderProgram( this.Graphics, VertexShader.Compile(this.Graphics, File.ReadAllText("Mandelbrot.vert")), FragmentShader.Compile(this.Graphics, File.ReadAllText("Mandelbrot.frag"))); this.Graphics.ShaderProgram = this.shaderProgram; this.vertexBuffer = new StaticVertexBuffer<Vertex>(this.Graphics, this.vertexData); this.palette = Texture1D.LoadFromFile(this.Graphics, "Palette.png", new TextureParams() { WrapS = TextureWrap.Repeat, WrapT = TextureWrap.Repeat }); this.keyboard = new Keyboard(); }
public DemoGame() { this.Window.Title = "Samurai Demo"; this.Graphics.BlendEnabled = true; this.Graphics.SourceBlendFactor = SourceBlendFactor.SourceAlpha; this.Graphics.DestinationBlendFactor = DestinationBlendFactor.OneMinusDestinationAlpha; this.Graphics.DepthBufferEnabled = true; this.Graphics.DepthFunction = DepthFunction.LessThanOrEqual; this.Graphics.FrontFace = FrontFace.Clockwise; this.Graphics.CullMode = CullMode.Back; this.shaderProgram = new ShaderProgram( this.Graphics, VertexShader.Compile(this.Graphics, File.ReadAllText("Shader.vert")), FragmentShader.Compile(this.Graphics, File.ReadAllText("Shader.frag"))); this.vertexBuffer = new StaticVertexBuffer<Vertex>(this.Graphics, this.vertexData); this.indexBuffer = new StaticIndexBuffer<byte>(this.Graphics, this.indexData); this.texture0 = Texture2D.LoadFromFile(this.Graphics, "Texture0.png", new TextureParams() { WrapS = TextureWrap.Repeat, WrapT = TextureWrap.Repeat }); this.texture1 = Texture2D.LoadFromFile(this.Graphics, "Texture1.png", new TextureParams() { WrapS = TextureWrap.Clamp, WrapT = TextureWrap.Clamp }); this.gamePad1 = new GamePad(GamePadIndex.One); this.controlInputHandler = new ControlInputHandler(this.Window); this.controlRenderer = new ControlRenderer(this.Graphics); this.controlRenderer.DefaultFont = TextureFont.Build(this.Graphics, "Segoe UI", 72, new TextureFontParams() { BackgroundColor = Color4.Transparent }); this.panel = new Panel() { Position = new Vector2(100, 100), Size = new Size(100, 100) }; this.label = new Label() { Text = "Hello World!", Font = TextureFont.Build(this.Graphics, "Segoe UI", 24, new TextureFontParams() { BackgroundColor = Color4.Transparent }) }; this.label.CursorEnter += (s, e) => { this.label.ForegroundColor = Color4.Black; }; this.label.CursorLeave += (s, e) => { this.label.ForegroundColor = Color4.White; }; this.panel.Controls.Add(label); }
private void GraphicsBox_GraphicsContextCreated(object sender, GraphicsContextEventArgs e) { e.Graphics.ClearColor = Color4.CornflowerBlue; this.vertexBuffer = new StaticVertexBuffer<Vertex>(e.Graphics, new Vertex[] { new Vertex() { Position = Vector2.Zero, TexCoords = Vector2.Zero }, new Vertex() { Position = Vector2.UnitX, TexCoords = Vector2.UnitX }, new Vertex() { Position = Vector2.UnitY, TexCoords = Vector2.UnitY }, new Vertex() { Position = Vector2.UnitY, TexCoords = Vector2.UnitY }, new Vertex() { Position = Vector2.UnitX, TexCoords = Vector2.UnitX }, new Vertex() { Position = Vector2.One, TexCoords = Vector2.One }, }); this.currentShaderProgram = new ShaderProgram( e.Graphics, VertexShader.Compile(e.Graphics, vertexShaderCode), FragmentShader.Compile(e.Graphics, defaultFragmentShaderCode)); this.currentPicture = Texture2D.LoadFromFile(e.Graphics, "SamuraiLogo.png", new TextureParams()); this.stopwatch.Start(); }