aboutsummaryrefslogtreecommitdiffstatsci
path: root/OTKCrow/OpenGL/GLBackend/Font
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-04-22 12:19:40 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2016-04-22 12:19:40 +0200
commit68056c452876b77bb443e89f49b6dd52ca50cfbb (patch)
tree7d6ef98f0dc7e688fe85b8b07701c1357962807b /OTKCrow/OpenGL/GLBackend/Font
parent88769581ad8993ae9e3b1cb60ccbdc4cb5008fe7 (diff)
copy old glbackend files, no changes made for now, not workingtestglbackend2
Diffstat (limited to 'OTKCrow/OpenGL/GLBackend/Font')
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/Font.cs115
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontExtents.cs39
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontFace.cs307
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontFlag.cs18
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontShader (copier).cs146
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontShader.cs128
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontSlant.cs42
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontStyle.cs15
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/FontWeight.cs41
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/TextExtents.cs98
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/glFont.cs90
-rw-r--r--OTKCrow/OpenGL/GLBackend/Font/glGlyph.cs22
12 files changed, 1061 insertions, 0 deletions
diff --git a/OTKCrow/OpenGL/GLBackend/Font/Font.cs b/OTKCrow/OpenGL/GLBackend/Font/Font.cs
new file mode 100644
index 00000000..d07b9bd0
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/Font.cs
@@ -0,0 +1,115 @@
+using System;
+
+
+namespace Crow.GLBackend
+{
+ public class Font
+ {
+ public Font ()
+ {
+ }
+
+ public Font (string name, FontSlant fs, FontWeight fw)
+ {
+ _name = name;
+ switch (fs) {
+ case FontSlant.Italic:
+ Style |= FontStyle.Italic;
+ break;
+ case FontSlant.Oblique:
+ Style |= FontStyle.Oblique;
+ break;
+ }
+ if (fw == FontWeight.Bold)
+ Style |= FontStyle.Bold;
+ }
+
+ string _name = "droid";
+ FontStyle _style = FontStyle.Normal;
+ FontFlag _flags = FontFlag.None;
+
+ int _size = 10;
+
+ public string Name {
+ get { return _name; }
+ set { _name = value; }
+ }
+ public FontStyle Style {
+ get { return _style; }
+ set { _style = value; }
+ }
+ public FontFlag Flags {
+ get { return _flags; }
+ set { _flags = value; }
+ }
+ public FontSlant Slant {
+ get{
+ if ((Style & FontStyle.Italic) == FontStyle.Italic)
+ return FontSlant.Italic;
+ if ((Style & FontStyle.Oblique) == FontStyle.Oblique)
+ return FontSlant.Oblique;
+ return FontSlant.Normal;
+ }
+ }
+ public FontWeight Wheight {
+ get{ return (Style & FontStyle.Bold) == FontStyle.Bold ? FontWeight.Bold : FontWeight.Normal; }
+ }
+ public int Size {
+ get { return _size; }
+ set { _size = value; }
+ }
+
+ #region Operators
+ public static implicit operator string(Font c)
+ {
+ return c.ToString();
+ }
+ public static implicit operator Font(string s)
+ {
+ Font f = new Font ();
+
+ if (!string.IsNullOrEmpty (s)) {
+ f.Name = "";
+ string[] attribs = s.TrimStart().TrimEnd().Split(',');
+ for (int i = 0; i < attribs.Length; i++) {
+ FontFlag fl;
+ FontStyle fs;
+ int sz;
+ if (Enum.TryParse<FontFlag> (attribs [i], true, out fl))
+ f.Flags |= fl;
+ else if (Enum.TryParse<FontStyle> (attribs [i], true, out fs))
+ f.Style |= fs;
+ else if (int.TryParse (attribs [i], out sz))
+ f.Size = sz;
+ else
+ f.Name += attribs[i] + " ";
+ }
+ f.Name = f.Name.Trim();
+ }
+
+ return f;
+ }
+ #endregion
+ public string FontFaceString
+ {
+ get {
+ string tmp = Name;
+ if (Style != FontStyle.Normal)
+ tmp += "," + Style.ToString ();
+ if (Flags != FontFlag.None)
+ tmp += "," + Flags.ToString ();
+ return tmp;
+ }
+ }
+ public override string ToString()
+ {
+ return string.Format("{0},{1}", FontFaceString, _size);
+ }
+
+ public static object Parse(string s)
+ {
+ return (Font)s;
+ }
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontExtents.cs b/OTKCrow/OpenGL/GLBackend/Font/FontExtents.cs
new file mode 100644
index 00000000..fba77cb0
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontExtents.cs
@@ -0,0 +1,39 @@
+using System;
+
+namespace Crow.GLBackend
+{
+ public class FontExtents
+ {
+ double ascent;
+ double descent;
+ double height;
+ double maxXAdvance;
+ double maxYAdvance;
+
+ public double Ascent {
+ get { return ascent; }
+ set { ascent = value; }
+ }
+ public double Descent {
+ get { return descent; }
+ set { descent = value; }
+ }
+ public double Height {
+ get { return height; }
+ set { height = value; }
+ }
+ public double MaxXAdvance {
+ get { return maxXAdvance; }
+ set { maxXAdvance = value; }
+ }
+ public double MaxYAdvance {
+ get { return maxYAdvance; }
+ set { maxYAdvance = value; }
+ }
+
+ public FontExtents ()
+ {
+ }
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontFace.cs b/OTKCrow/OpenGL/GLBackend/Font/FontFace.cs
new file mode 100644
index 00000000..88bdaa15
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontFace.cs
@@ -0,0 +1,307 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpFont;
+using System.Diagnostics;
+using System.Linq;
+using System.Text.RegularExpressions;
+using OpenTK.Graphics.OpenGL;
+
+namespace Crow.GLBackend
+{
+ public class FontFace
+ {
+ public static int testTexture;
+
+ static List<FontFace> fonts = new List<FontFace>();
+ public Dictionary<uint,Dictionary<uint, glGlyph>> glyphesCache = new Dictionary<uint, Dictionary<uint, glGlyph>>();
+
+ #region CTOR
+ public FontFace ()
+ {
+ }
+ #endregion
+
+ string _name = "droid";
+ string _family;
+ string _fontPath;
+ public FontExtents originalFontExtents;
+
+ FontStyle _style = FontStyle.Normal;
+ FontFlag _flags = FontFlag.None;
+
+ public string Name {
+ get { return _name; }
+ set { _name = value; }
+ }
+ public string Family {
+ get {return _family;}
+ set {_family = value;}
+ }
+ public string FontPath {
+ get { return _fontPath; }
+ set { _fontPath = value; }
+ }
+
+ public FontStyle Style {
+ get { return _style; }
+ set { _style = value; }
+ }
+ public FontFlag Flags {
+ get { return _flags; }
+ set { _flags = value; }
+ }
+
+ public FontSlant Slant {
+ get{
+ if ((Style & FontStyle.Italic) == FontStyle.Italic)
+ return FontSlant.Italic;
+ if ((Style & FontStyle.Oblique) == FontStyle.Oblique)
+ return FontSlant.Oblique;
+ return FontSlant.Normal;
+ }
+ }
+ public FontWeight Wheight {
+ get{ return (Style & FontStyle.Bold) == FontStyle.Bold ? FontWeight.Bold : FontWeight.Normal; }
+ }
+
+ public static FontFace SearchFont(Font font)
+ {
+ FontFace[] tmp = fonts.Where (f =>
+ (string.Compare(f.Name,font.Name,true)==0 && f.Style == font.Style)).ToArray();
+
+ tmp = tmp.Where (f => (f.Flags & font.Flags) == font.Flags).OrderBy(f=>f.Flags).ToArray();
+
+ return tmp.FirstOrDefault();
+ }
+
+ public static void BuildFontsList(string _path)
+ {
+ DirectoryInfo dir = new DirectoryInfo (_path);
+ try
+ {
+ using (Library lib = new Library())
+ {
+ foreach (FileInfo f in dir.GetFiles("*.ttf",SearchOption.AllDirectories)) {
+ try {
+
+ Face face = new Face(lib,f.FullName, 0);
+ FontFace font = new FontFace();
+
+ //TODO:test if font is scalable, if not=>continue
+ font.Family = face.FamilyName;
+ font.FontPath = f.FullName;
+
+ //check if no particularities hidde in family name
+ font.Name = "";
+ string[] styles = face.FamilyName.Split(' ');
+ for (int i = 0; i < styles.Length; i++) {
+ FontFlag fl;
+ FontStyle fs;
+ if (Enum.TryParse<FontFlag> (styles [i], true, out fl))
+ font.Flags |= fl;
+ else if (Enum.TryParse<FontStyle> (styles [i], true, out fs))
+ font.Style |= fs;
+ else//add only unknown word to create shortest possible name
+ font.Name += styles[i] + " ";
+ }
+ font.Name = font.Name.Trim();
+
+ styles = face.StyleName.Split(' ');
+ for (int i = 0; i < styles.Length; i++) {
+ switch (styles[i].ToLowerInvariant()) {
+ case "regular":
+ case "normal":
+ break;
+ case "bold":
+ font.Style |= FontStyle.Bold;
+ break;
+ case "italic":
+ font.Style |= FontStyle.Italic;
+ break;
+ case "oblique":
+ font.Style |= FontStyle.Oblique;
+ break;
+ default:
+ FontFlag fl;
+ if (Enum.TryParse<FontFlag>(styles[i], true, out fl))
+ font.Flags |= fl;
+ break;
+ }
+
+ }
+ fonts.Add(font);
+ face.Dispose();
+ }
+ catch (FreeTypeException ee)
+ { Console.Write(ee.Error.ToString() + ": " + f.FullName); }
+ }
+ }
+ }
+ catch (FreeTypeException e)
+ { Console.Write(e.Error.ToString()); }
+ }
+
+ const int FONT_TEX_SIZE = 1024;
+
+ public void buildGlyphesTextures(uint activeSize, uint startChar, uint endChar){
+ try
+ {
+ using (Library lib = new Library())
+ {
+ Face face = new Face(lib,_fontPath, 0);
+
+ face.SetPixelSizes(0,activeSize);
+
+ //face.SetCharSize(0, 32 * 64, 0, 96);
+
+ originalFontExtents = new FontExtents();
+ originalFontExtents.Ascent = face.Size.Metrics.Ascender >> 6;
+ originalFontExtents.Descent = face.Size.Metrics.Descender >> 6;
+ originalFontExtents.Height = face.Size.Metrics.Height >> 6;
+ originalFontExtents.MaxXAdvance = face.Size.Metrics.MaxAdvance >> 6;
+ originalFontExtents.MaxYAdvance = face.MaxAdvanceHeight >> 6;
+
+ if (!glyphesCache.ContainsKey(activeSize))
+ glyphesCache [activeSize] = new Dictionary<uint, glGlyph>();
+
+ buildTexture(ref face,activeSize,startChar,endChar);
+
+ face.Dispose();
+ }
+ }
+ catch (FreeTypeException e)
+ { Console.Write(e.Error.ToString()); }
+ }
+
+ void setTextureData(int tex, byte[] _buffer)
+ {
+ GL.BindTexture(TextureTarget.Texture2D, tex);
+ GL.TexImage2D(TextureTarget.Texture2D,0,
+ PixelInternalFormat.R8, FONT_TEX_SIZE, FONT_TEX_SIZE,0,
+ OpenTK.Graphics.OpenGL.PixelFormat.Red, PixelType.UnsignedByte,_buffer);
+
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+
+ byte[] pixels = new byte[FONT_TEX_SIZE * FONT_TEX_SIZE * 4];
+
+ for (int x = 0; x < FONT_TEX_SIZE; x++)
+ {
+ for (int y = 0; y < FONT_TEX_SIZE; y++)
+ {
+ byte v = _buffer[x + y * FONT_TEX_SIZE];
+
+ pixels[(x + y * FONT_TEX_SIZE) * 4] = v;
+ pixels[(x + y * FONT_TEX_SIZE) * 4 + 1] = v;
+ pixels[(x + y * FONT_TEX_SIZE) * 4 + 2] = v;
+ pixels[(x + y * FONT_TEX_SIZE) * 4 + 3] = 255;
+ }
+ }
+ System.Drawing.Bitmap bmp;
+ unsafe
+ {
+ bmp = new System.Drawing.Bitmap(FONT_TEX_SIZE, FONT_TEX_SIZE, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//, ptr);
+ System.Drawing.Imaging.BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, FONT_TEX_SIZE, FONT_TEX_SIZE),
+ System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+
+ System.Runtime.InteropServices.Marshal.Copy(pixels, 0, data.Scan0, FONT_TEX_SIZE * FONT_TEX_SIZE * 4);
+
+ bmp.UnlockBits(data);
+ }
+
+ bmp.Save(@"/home/jp/fonttex.png");
+
+
+ }
+
+
+ void buildTexture(ref Face face,uint activeSize, uint startChar, uint endChar){
+ int texPage = GL.GenTexture ();
+ byte[] buffer = new byte[FONT_TEX_SIZE*FONT_TEX_SIZE];
+
+ int penX = 0,
+ penY = 0;
+
+ int maxBmpHeight = 0;
+
+ for(uint c=startChar;c<endChar;c++)
+ {
+ uint glyphIndex = face.GetCharIndex((uint)c);
+ if (glyphIndex==0)
+ continue;
+ //face.LoadChar((uint)c, LoadFlags.Render, LoadTarget.Normal);
+ face.LoadGlyph(glyphIndex, LoadFlags.Render, LoadTarget.Normal);
+ testTexture = texPage;
+
+ GlyphSlot slot = face.Glyph;
+ FTBitmap bmp = slot.Bitmap;
+
+ if (penX+bmp.Width > FONT_TEX_SIZE){
+ penX = 0;
+ penY += maxBmpHeight;
+ maxBmpHeight = 0;
+ }
+
+ if (penY+bmp.Rows > FONT_TEX_SIZE)
+ {
+ //glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ setTextureData (texPage, buffer);
+ texPage = GL.GenTexture ();
+ buffer = new byte[FONT_TEX_SIZE*FONT_TEX_SIZE];
+ penX = 0;
+ penY = 0;
+ maxBmpHeight = 0;
+ }
+
+ Rectangle tmp = new Rectangle (
+ penX,
+ penY,
+ bmp.Width, bmp.Rows);
+
+ for(int y=0; y<bmp.Rows; y++)
+ {
+ for(int x=0; x<bmp.Width; x++)
+ buffer[ penX + x + (penY + y)* FONT_TEX_SIZE ] =
+ bmp.BufferData[x + y * bmp.Width];
+ }
+ glyphesCache [activeSize][c] = new glGlyph()
+ {
+ texId = texPage,
+ texX = (float)penX / FONT_TEX_SIZE,
+ texY = (float)penY / FONT_TEX_SIZE,
+ texWidth = (float)(bmp.Width) / FONT_TEX_SIZE,
+ texHeight = (float)(bmp.Rows) / FONT_TEX_SIZE,
+
+// texCoord = new Rectangle(
+// penX / FONT_TEX_SIZE,
+// penY / FONT_TEX_SIZE,
+// (bmp.Width) / FONT_TEX_SIZE,
+// (bmp.Rows) / FONT_TEX_SIZE),
+ dims = new Size(bmp.Width , bmp.Rows),
+ bmpLeft = slot.BitmapLeft, bmpTop = slot.BitmapTop, advanceX = slot.Advance.X>>6,advanceY = slot.Advance.Y>>6
+ };
+
+ if (bmp.Rows>maxBmpHeight)
+ maxBmpHeight=bmp.Rows;
+
+ penX += bmp.Width;
+ }
+
+ if (penX>0 || penY>0)
+ setTextureData(texPage, buffer);
+ }
+
+ public override string ToString()
+ {
+ string tmp = Name;
+ if (Style != FontStyle.Normal)
+ tmp += "," + Style.ToString ();
+ if (Flags != FontFlag.None)
+ tmp += "," + Flags.ToString ();
+ return tmp;
+ }
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontFlag.cs b/OTKCrow/OpenGL/GLBackend/Font/FontFlag.cs
new file mode 100644
index 00000000..f748ec17
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontFlag.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace Crow
+{
+ [Flags]
+ public enum FontFlag
+ {
+ None = 0x00,
+ Sans = 0x01,
+ Serif = 0x02,
+ Mono = 0x04,
+ Condensed = 0x08,
+ Medium = 0x16,
+ Book = 0x32,
+ ExtraLight = 0x64
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontShader (copier).cs b/OTKCrow/OpenGL/GLBackend/Font/FontShader (copier).cs
new file mode 100644
index 00000000..2a4c1571
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontShader (copier).cs
@@ -0,0 +1,146 @@
+using System;
+using OpenTK.Graphics.OpenGL;
+
+namespace Crow.GLBackend
+{
+ public class FontShader : Shader
+ {
+ public FontShader ()
+ {
+ vertSource = @"
+ #version 130
+
+ precision highp float;
+
+ uniform mat4 projection_matrix;
+ uniform mat4 modelview_matrix;
+
+ in vec2 in_position;
+ in vec2 in_tex;
+ out vec2 texCoord;
+
+
+ void main(void)
+ {
+ texCoord = in_tex;
+ gl_Position = projection_matrix * modelview_matrix * vec4(in_position,0, 1);
+ }";
+
+ fragSource = @"
+ #version 130
+ precision highp float;
+
+ uniform vec4 color;
+ uniform sampler2D tex;
+ uniform sampler2D stencil;
+ uniform vec2 resolution;
+
+ in vec2 texCoord;
+ out vec4 out_frag_color;
+
+ vec3
+ energy_distribution( vec4 previous, vec4 current, vec4 next )
+ {
+ float primary = 1.0/3.0;
+ float secondary = 1.0/3.0;
+ float tertiary = 0.0;
+
+ // Energy distribution as explained on:
+ // http://www.grc.com/freeandclear.htm
+ //
+ // .. v..
+ // RGB RGB RGB
+ // previous.g + previous.b + current.r + current.g + current.b
+ //
+ // . .v. .
+ // RGB RGB RGB
+ // previous.b + current.r + current.g + current.b + next.r
+ //
+ // ..v ..
+ // RGB RGB RGB
+ // current.r + current.g + current.b + next.r + next.g
+
+ float r =
+ tertiary * previous.g +
+ secondary * previous.b +
+ primary * current.r +
+ secondary * current.g +
+ tertiary * current.b;
+
+ float g =
+ tertiary * previous.b +
+ secondary * current.r +
+ primary * current.g +
+ secondary * current.b +
+ tertiary * next.r;
+
+ float b =
+ tertiary * current.r +
+ secondary * current.g +
+ primary * current.b +
+ secondary * next.r +
+ tertiary * next.g;
+
+ return vec3(r,g,b);
+ }
+ void main(void)
+ {
+ float a = texture( tex, texCoord).r;
+
+ if (a==0.)
+ discard;
+
+ float x = gl_FragCoord.x / resolution.x;
+ float s = mod(x,x);
+
+ vec4 current = color * texture( tex, texCoord).r;
+ vec4 previous = color * texture( tex, texCoord + vec2(-x,0)).r;
+ vec4 next = color * texture( tex, texCoord + vec2(x,0)).r;
+
+ float r = current.r;
+ float g = current.g;
+ float b = current.b;
+
+ if( s <= 0.333 )
+ {
+ float z = s/0.333;
+ r = mix(current.r, previous.b, z);
+ g = mix(current.g, current.r, z);
+ b = mix(current.b, current.g, z);
+ }
+ else if( s <= 0.666 )
+ {
+ float z = (s-0.33)/0.333;
+ r = mix(previous.b, previous.g, z);
+ g = mix(current.r, previous.b, z);
+ b = mix(current.g, current.r, z);
+ }
+ else if( s < 1.0 )
+ {
+ float z = (s-0.66)/0.334;
+ r = mix(previous.g, previous.r, z);
+ g = mix(previous.b, previous.g, z);
+ b = mix(current.r, previous.b, z);
+ }
+
+
+ out_frag_color = vec4(energy_distribution(previous, current, next),1);
+ }";
+
+ Compile ();
+
+ }
+
+ protected override void BindVertexAttributes ()
+ {
+ base.BindVertexAttributes ();
+ GL.BindAttribLocation(pgmId, 1, "in_tex");
+ }
+ protected override void BindSamplesSlots ()
+ {
+ GL.Uniform1(GL.GetUniformLocation (pgmId, "tex"),0);
+ //GL.Uniform1(GL.GetUniformLocation (pgmId, "stencil"),1);
+ }
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontShader.cs b/OTKCrow/OpenGL/GLBackend/Font/FontShader.cs
new file mode 100644
index 00000000..6086f7b9
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontShader.cs
@@ -0,0 +1,128 @@
+using System;
+using OpenTK.Graphics.OpenGL;
+using OpenTK;
+
+namespace Crow.GLBackend
+{
+ public class FontShader : Shader
+ {
+ protected int coef1Location, coef2Location, coef3Location, coefALocation, resolutionLoc;
+ public float coef1 {
+ set {GL.Uniform1 (coef1Location, value);}
+ }
+ public float coef2 {
+ set {GL.Uniform1 (coef2Location, value);}
+ }
+ public float coef3 {
+ set {GL.Uniform1 (coef3Location, value);}
+ }
+ public float coefA {
+ set {GL.Uniform1 (coefALocation, value);}
+ }
+ public Vector2 Resolution {
+ set { GL.Uniform2 (resolutionLoc, value); }
+ }
+ public FontShader ()
+ {
+ vertSource = @"
+ #version 130
+
+ precision highp float;
+
+ uniform mat4 projection_matrix;
+ uniform mat4 modelview_matrix;
+
+ in vec2 in_position;
+ in vec2 in_tex;
+ out vec2 texCoord;
+
+
+ void main(void)
+ {
+ texCoord = in_tex;
+ gl_Position = projection_matrix * modelview_matrix * vec4(in_position,0, 1);
+ }";
+
+ fragSource = @"
+ #version 130
+ precision highp float;
+
+ uniform vec4 color;
+ uniform sampler2D tex;
+ uniform sampler2D backTex;
+ uniform sampler2D stencil;
+ uniform vec2 resolution;
+ uniform float coef1;
+ uniform float coef2;
+ uniform float coef3;
+ uniform float coefA;
+
+
+ in vec2 texCoord;
+ out vec4 out_frag_color;
+
+ void main(void)
+ {
+ vec2 uv = gl_FragCoord.xy / resolution;
+ vec2 pix = 1.0 / resolution;
+
+ float c = texture( tex, texCoord).r;
+ vec4 bc = texture( backTex, uv);
+
+ vec4 diff = bc - color;
+
+ if (c==0.)
+ discard;
+
+// if (c > 0.75)
+// out_frag_color = vec4(color.rgb,c);
+// else{
+ float p = texture( tex, texCoord + vec2(-pix.x,0)).r;
+ float n = texture( tex, texCoord + vec2( pix.x,0)).r;
+
+ vec3 current = vec3(0,0,0);
+
+ float a = n - c;
+ current.r += coef1 * a * diff.r;
+ current.g += coef2 * a * diff.g;
+ current.b += coef3 * a * diff.b;
+ //current.a *= coefA * a * diff.a;
+
+ a = p - c;
+ current.r += coef3 * a * diff.r;
+ current.g += coef2 * a * diff.g;
+ current.b += coef1 * a * diff.b;
+ //current.a *= coefA * a * diff.a;
+
+ out_frag_color = vec4(color.rgb+current,c*coefA);
+
+// }
+ }";
+
+ Compile ();
+
+ }
+ protected override void GetUniformLocations ()
+ {
+ base.GetUniformLocations ();
+
+ resolutionLoc = GL.GetUniformLocation (pgmId, "resolution");
+ coef1Location = GL.GetUniformLocation (pgmId, "coef1");
+ coef2Location = GL.GetUniformLocation (pgmId, "coef2");
+ coef3Location = GL.GetUniformLocation (pgmId, "coef3");
+ coefALocation = GL.GetUniformLocation (pgmId, "coefA");
+ }
+ protected override void BindVertexAttributes ()
+ {
+ base.BindVertexAttributes ();
+ GL.BindAttribLocation(pgmId, 1, "in_tex");
+ }
+ protected override void BindSamplesSlots ()
+ {
+ GL.Uniform1(GL.GetUniformLocation (pgmId, "tex"),0);
+ GL.Uniform1(GL.GetUniformLocation (pgmId, "backTex"),1);
+ //GL.Uniform1(GL.GetUniformLocation (pgmId, "stencil"),1);
+ }
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontSlant.cs b/OTKCrow/OpenGL/GLBackend/Font/FontSlant.cs
new file mode 100644
index 00000000..8bfd5a6a
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontSlant.cs
@@ -0,0 +1,42 @@
+//
+// Mono.Cairo.FontSlant.cs
+//
+// Authors:
+// Duncan Mak (duncan@ximian.com)
+// Hisham Mardam Bey (hisham.mardambey@gmail.com)
+//
+// (C) Ximian, Inc. 2003
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace Crow.GLBackend
+{
+ [Serializable]
+ public enum FontSlant
+ {
+ Normal,
+ Italic,
+ Oblique
+ }
+}
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontStyle.cs b/OTKCrow/OpenGL/GLBackend/Font/FontStyle.cs
new file mode 100644
index 00000000..eed35057
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontStyle.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace Crow
+{
+ [Flags]
+ public enum FontStyle
+ {
+ Normal = 0x00,
+ Bold = 0x01,
+ Italic = 0x02,
+ Oblique = 0x4,
+ Underlined = 0x8
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/FontWeight.cs b/OTKCrow/OpenGL/GLBackend/Font/FontWeight.cs
new file mode 100644
index 00000000..d361378c
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/FontWeight.cs
@@ -0,0 +1,41 @@
+//
+// Mono.Cairo.FontWeight.cs
+//
+// Authors:
+// Duncan Mak (duncan@ximian.com)
+// Hisham Mardam Bey (hisham.mardambey@gmail.com)
+//
+// (C) Ximian, Inc. 2003
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+namespace Crow.GLBackend
+{
+ [Serializable]
+ public enum FontWeight
+ {
+ Normal,
+ Bold,
+ }
+}
diff --git a/OTKCrow/OpenGL/GLBackend/Font/TextExtents.cs b/OTKCrow/OpenGL/GLBackend/Font/TextExtents.cs
new file mode 100644
index 00000000..a0bc6440
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/TextExtents.cs
@@ -0,0 +1,98 @@
+//
+// Mono.Cairo.TextExtents.cs
+//
+// Authors:
+// Duncan Mak (duncan@ximian.com)
+// Hisham Mardam Bey (hisham.mardambey@gmail.com)
+//
+// (C) Ximian, Inc. 2003
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Crow.GLBackend
+{
+ [StructLayout (LayoutKind.Sequential)]
+ public struct TextExtents
+ {
+ double xbearing;
+ double ybearing;
+ double width;
+ double height;
+ double xadvance;
+ double yadvance;
+
+ public double XBearing {
+ get { return xbearing; }
+ set { xbearing = value; }
+ }
+
+ public double YBearing {
+ get { return ybearing; }
+ set { ybearing = value; }
+ }
+
+ public double Width {
+ get { return width; }
+ set { width = value; }
+ }
+
+ public double Height {
+ get { return height; }
+ set { height = value; }
+ }
+
+ public double XAdvance {
+ get { return xadvance; }
+ set { xadvance = value; }
+ }
+
+ public double YAdvance {
+ get { return yadvance; }
+ set { yadvance = value; }
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (obj is TextExtents)
+ return this == (TextExtents)obj;
+ return false;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (int)XBearing ^ (int)YBearing ^ (int)Width ^ (int)Height ^ (int)XAdvance ^ (int)YAdvance;
+ }
+
+ public static bool operator == (TextExtents extents, TextExtents other)
+ {
+ return extents.XBearing == other.XBearing && extents.YBearing == other.YBearing && extents.Width == other.Width && extents.Height == other.Height && extents.XAdvance == other.XAdvance && extents.YAdvance == other.YAdvance;
+ }
+
+ public static bool operator != (TextExtents extents, TextExtents other)
+ {
+ return !(extents == other);
+ }
+ }
+}
diff --git a/OTKCrow/OpenGL/GLBackend/Font/glFont.cs b/OTKCrow/OpenGL/GLBackend/Font/glFont.cs
new file mode 100644
index 00000000..059fca6a
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/glFont.cs
@@ -0,0 +1,90 @@
+using System;
+using SharpFont;
+using OpenTK.Graphics.OpenGL;
+using System.Collections.Generic;
+using System.IO;
+using System.Diagnostics;
+
+namespace Crow
+{
+ public class glFont
+ {
+ Dictionary<int, glGlyph> glyphs = new Dictionary<int,glGlyph>();
+
+ public static void dumpFontsDirectories(string _path)
+ {
+ List<string> stylesList = new List<string> ();
+ List<string> namesList = new List<string> ();
+ List<string> attribsList = new List<string> ();
+
+ DirectoryInfo dir = new DirectoryInfo (_path);
+ try
+ {
+ using (Library lib = new Library())
+ {
+ Console.WriteLine("FreeType version: " + lib.Version + "\n");
+
+ foreach (FileInfo f in dir.GetFiles("*.ttf",SearchOption.AllDirectories)) {
+ try {
+
+ Face face = new Face(lib,f.FullName, 0);
+
+ Console.Write(System.IO.Path.GetFileNameWithoutExtension(f.Name) + " => ");
+ Console.WriteLine("{0} Faces:{1} Flags:{2}\nStyle:{3} StyleFlags:{4}\n",
+ face.FamilyName,
+ face.FaceCount,
+ face.FaceFlags,
+ face.StyleName,
+ face.StyleFlags);
+ string[] styles = face.StyleName.Split(' ');
+ foreach (string s in styles) {
+ if (stylesList.Contains(s))
+ continue;
+ stylesList.Add(s);
+ }
+
+ string[] names = face.FamilyName.Split(' ');
+ if (!namesList.Contains(names[0]))
+ namesList.Add(names[0]);
+ for (int i = 1; i < names.Length; i++) {
+ if (attribsList.Contains(names[i]))
+ continue;
+ attribsList.Add(names[i]);
+ }
+
+ face.Dispose();
+ }
+ catch (FreeTypeException ee)
+ {
+ Console.Write(ee.Error.ToString() + ": " + f.FullName);
+ }
+ }
+ }
+ }
+ catch (FreeTypeException e)
+ {
+ Console.Write(e.Error.ToString());
+ }
+ Console.Write ("Names => ");
+ foreach (string s in namesList) {
+ Console.Write (s + " ");
+ }
+ Console.Write ("\n\nAttrib => ");
+ foreach (string s in attribsList) {
+ Console.Write (s + " ");
+ }
+
+ Console.Write ("\n\nStyles => ");
+ foreach (string s in stylesList) {
+ Console.Write (s + " ");
+ }
+ }
+
+ public glFont (string _fontPath)
+ {
+
+ }
+
+ }
+}
+
diff --git a/OTKCrow/OpenGL/GLBackend/Font/glGlyph.cs b/OTKCrow/OpenGL/GLBackend/Font/glGlyph.cs
new file mode 100644
index 00000000..f0d15d36
--- /dev/null
+++ b/OTKCrow/OpenGL/GLBackend/Font/glGlyph.cs
@@ -0,0 +1,22 @@
+using System;
+
+namespace Crow
+{
+ public struct glGlyph
+ {
+ public int texId;
+ public Rectangle texCoord;
+ public float texX;
+ public float texY;
+ public float texWidth;
+ public float texHeight;
+ public Size dims;
+ public int bmpLeft;
+ public int bmpTop;
+ public long advanceX;
+ public long advanceY;
+
+
+ }
+}
+