protected override void Copy(Color4[] source, int sourceIndex, int length, int stride) { fixed(Color4 *sourcePtr = source) { Color4 * src = sourcePtr + sourceIndex; RGBAColor *dst = FPDst + Position; for (int i = 0; i < length; i++) { dst->R = src->Red; dst->G = src->Green; dst->B = src->Blue; dst->A = src->Alpha; src++; dst += stride; } } }
static unsafe extern void convert_to_jpg(Color4 *pixels, int w, int h, int quality, WriteFunc func);
static unsafe extern void convert_to_tga(Color4 *pixels, int w, int h, WriteFunc func);
public override bool Draw() { if (base.Draw()) { Color4 c = AlphaAppliedColour; Vector2 pos = FieldPosition; Vector2 scale = FieldScale; Vector2 origin = OriginVector * GameBase.BaseToNativeRatio; if (Colours == null) { SpriteManager.SetColour(c); } else { #if NO_PIN_SUPPORT Color4 *colours = (Color4 *)handle_colours_pointer.ToPointer(); #endif for (int i = 0; i < Colours.Length; i++) { Color4 col = Colours[i]; if (SpriteManager.UniversalDim > 0) { float multi = 1 - SpriteManager.UniversalDim; colours[i] = new Color4(col.R * multi, col.G * multi, col.B * multi, c.A); } else { colours[i] = new Color4(col.R, col.G, col.B, c.A); } //todo: optimise } GL.EnableClientState(ArrayCap.ColorArray); GL.ColorPointer(4, ColorPointerType.Float, 0, handle_colours_pointer); } //first move everything so it is centered on (0,0) /*float vLeft = -origin.X; * float vTop = -origin.Y; * float vRight = -origin.X + scale.X; * float vBottom = -origin.Y + scale.Y; * * if (Rotation != 0) * { * float cos = (float)Math.Cos(Rotation); * float sin = (float)Math.Sin(Rotation); * * vertices[0] = vLeft * cos - vTop * sin + pos.X; * vertices[1] = vLeft * sin + vTop * cos + pos.Y; * vertices[2] = vRight * cos - vTop * sin + pos.X; * vertices[3] = vRight * sin + vTop * cos + pos.Y; * vertices[4] = vRight * cos - vBottom * sin + pos.X; * vertices[5] = vRight * sin + vBottom * cos + pos.Y; * vertices[6] = vLeft * cos - vBottom * sin + pos.X; * vertices[7] = vLeft * sin + vBottom * cos + pos.Y; * } * else*/ /*vLeft += pos.X; * vRight += pos.X; * vTop += pos.Y; * vBottom += pos.Y;*/ #if NO_PIN_SUPPORT Vector2 *vertices = (Vector2 *)handle_vertices_pointer.ToPointer(); #endif vertices[0].X = pos.X + p1.X * scale.X - origin.X; vertices[0].Y = pos.Y + p1.Y * scale.Y - origin.Y; vertices[1].X = pos.X + p2.X * scale.X - origin.X; vertices[1].Y = pos.Y + p2.Y * scale.Y - origin.Y; vertices[2].X = pos.X + p4.X * scale.X - origin.X; vertices[2].Y = pos.Y + p4.Y * scale.Y - origin.Y; vertices[3].X = pos.X + p3.X * scale.X - origin.X; vertices[3].Y = pos.Y + p3.Y * scale.Y - origin.Y; if (Texture != null && Texture.TextureGl != null) { SpriteManager.TexturesEnabled = true; Texture.TextureGl.Bind(); #if !NO_PIN_SUPPORT if (coordinates == null) { coordinates = new[] { (float)Texture.X / Texture.TextureGl.potWidth, (float)Texture.Y / Texture.TextureGl.potHeight, (float)(Texture.X + Texture.Width) / Texture.TextureGl.potWidth, (float)Texture.Y / Texture.TextureGl.potHeight, (float)(Texture.X + Texture.Width) / Texture.TextureGl.potWidth, (float)(Texture.Y + Texture.Height) / Texture.TextureGl.potHeight, (float)Texture.X / Texture.TextureGl.potWidth, (float)(Texture.Y + Texture.Height) / Texture.TextureGl.potHeight }; handle_coordinates = GCHandle.Alloc(coordinates, GCHandleType.Pinned); handle_coordinates_pointer = handle_coordinates.AddrOfPinnedObject(); } #else if (handle_coordinates_pointer == IntPtr.Zero) { unsafe { Color4 *colours = (Color4 *)handle_colours_pointer.ToPointer(); handle_coordinates_pointer = Marshal.AllocHGlobal(8 * sizeof(float)); float *coordinates = (float *)handle_coordinates_pointer.ToPointer(); coordinates[0] = (float)Texture.X / Texture.TextureGl.potWidth; coordinates[1] = (float)Texture.Y / Texture.TextureGl.potHeight; coordinates[2] = (float)(Texture.X + Texture.Width) / Texture.TextureGl.potWidth; coordinates[3] = (float)Texture.Y / Texture.TextureGl.potHeight; coordinates[4] = (float)(Texture.X + Texture.Width) / Texture.TextureGl.potWidth; coordinates[5] = (float)(Texture.Y + Texture.Height) / Texture.TextureGl.potHeight; coordinates[6] = (float)Texture.X / Texture.TextureGl.potWidth; coordinates[7] = (float)(Texture.Y + Texture.Height) / Texture.TextureGl.potHeight; } } #endif GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, handle_coordinates_pointer); } else { SpriteManager.TexturesEnabled = false; } GL.VertexPointer(2, VertexPointerType.Float, 0, handle_vertices_pointer); GL.DrawArrays(BeginMode.TriangleFan, 0, 4); if (Colours != null) { GL.DisableClientState(ArrayCap.ColorArray); } return(true); } return(false); }
static extern void pg_drawstring(IntPtr ctx, IntPtr str, IntPtr fontName, float fontSize, int indent, int underline, float r, float g, float b, float a, Color4 *shadow);
static extern void pg_drawstring(IntPtr ctx, IntPtr str, IntPtr fontName, float fontSize, TextAlignment align, int underline, float r, float g, float b, float a, Color4 *shadow, float *oWidth, float *oHeight);