Ejemplo n.º 1
0
		public Sprite (Stream stream, TextureSettings settings, Vector4 rect, bool relativeRect, Vector4 color, bool flipV = true) {
			var tex = new Texture(stream, settings);
			_material = new SpriteMaterial(new SpriteShader(), tex);
			
			if (rect == Vector4.Zero)
				rect = new Vector4(0, 0, tex.Size.Width, tex.Size.Height);
			else if (relativeRect) {
				rect.X *= tex.Size.Width;
				rect.Y *= tex.Size.Height;
				rect.Z *= tex.Size.Width;
				rect.W *= tex.Size.Height;
			}
			
			_size = new Vector2(rect.Z - rect.X, rect.W - rect.Y);

			_vbuffer = new VertexBuffer(VertexFormat.PositionColorUV);
			_vbuffer.Data = new [] {
				rect.X, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 1f : 0f,
				rect.Z, rect.Y, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 1f : 0f,
				rect.Z, rect.W, 0f, color.X, color.Y, color.Z, color.W, 1f, flipV ? 0f : 1f,
				rect.X, rect.W, 0f, color.X, color.Y, color.Z, color.W, 0f, flipV ? 0f : 1f
			};
			_vbuffer.Commit ();
			
			_ibuffer = new IndexBuffer();
			_ibuffer.Data = new [] { 0, 1, 2, 2, 3, 0 };
			_ibuffer.Commit ();
			
			_ioffset = 0;
			_icount = 6;
			
			_ownResources = true;
		}
Ejemplo n.º 2
0
		public FrameBuffer (Texture texture) {
			ThreadContext.Current.EnsureGLContext();

			_size = texture.Size;

			_oldfb = this.CurrentFrameBuffer;
			_oldViewport = new int[4];

			GL.GenFramebuffers(1, out _fb);
			GL.BindFramebuffer(FramebufferTarget.Framebuffer, _fb);
			GL.BindTexture(TextureTarget.Texture2D, texture.Handle);
			#if __DESKTOP__
			GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, texture.Handle, 0);
			#else
			GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, TextureTarget.Texture2D, texture.Handle, 0);
			#endif

			GL.BindTexture(TextureTarget.Texture2D, 0);
			GL.BindFramebuffer(FramebufferTarget.Framebuffer, _oldfb);

			this.ClearOnBegin = true;
		}
Ejemplo n.º 3
0
		public TextureSlot(Texture texture, int uvIndex, float blendFactor, TextureOperation operation, TextureWrap wrapS, TextureWrap wrapT) {
			this.Texture = texture;
			this.UVIndex = uvIndex;
			this.BlendFactor = blendFactor;
			this.Operation = operation;
			this.WrapS = wrapS;
			this.WrapT = wrapT;
		}
Ejemplo n.º 4
0
		public SpriteMaterial (Shader shader, Texture texture) : base(shader) {
			_texture = texture;
			this.Color = Vector4.One;
		}