public void GlyphMetrics() { this.Quit(); this.Init(); IntPtr fontPtr = SdlTtf.TTF_OpenFont("../../FreeSans.ttf", 12); int minx; int miny; int maxx; int maxy; int advance; SdlTtf.TTF_GlyphMetrics(fontPtr, 1, out minx, out maxx, out miny, out maxy, out advance); Assert.AreEqual(-1, minx); Assert.AreEqual(4, maxx); Assert.AreEqual(0, miny); Assert.AreEqual(8, maxy); Assert.AreEqual(5, advance); // Console.WriteLine("minx: " + minx.ToString()); // Console.WriteLine("maxx: " + maxx.ToString()); // Console.WriteLine("miny: " + miny.ToString()); // Console.WriteLine("maxy: " + maxy.ToString()); // Console.WriteLine("advance: " + advance.ToString()); this.Quit(); }
private SDLGlyph CreateGlyph(char Char) { Sdl.SDL_Surface initial; Sdl.SDL_Surface intermediary; //Sdl.SDL_Rect rect; int w, h; int[] texture = new int[1]; Sdl.SDL_Color color = new Sdl.SDL_Color(255, 255, 255, 255); /* Use SDL_TTF to render our text */ //IntPtr Test = SdlTtf.TTF_RenderGlyph_Shaded(m_Font, (short)Char, color, new Sdl.SDL_Color(0, 0, 0, 0)); IntPtr Test = SdlTtf.TTF_RenderGlyph_Blended(m_Font, (short)Char, color); //initial = test; initial = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(Test, typeof(Sdl.SDL_Surface)); /* Convert the rendered text to a known format */ w = nextpoweroftwo(initial.w); h = nextpoweroftwo(initial.h); IntPtr Temp = Sdl.SDL_CreateRGBSurface(Sdl.SDL_SRCALPHA, w, h, 32, 0, 0, 0, 0); intermediary = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(Temp, typeof(Sdl.SDL_Surface)); Sdl.SDL_SetAlpha(Temp, Sdl.SDL_SRCALPHA, 255); //Sdl.SDL_PixelFormat; Sdl.SDL_BlitSurface(Test, ref initial.clip_rect, Temp, ref intermediary.clip_rect); /* Tell GL about our new texture */ Gl.glGenTextures(1, texture); Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture[0]); if (!MipMap) { Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 4, w, h, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, intermediary.pixels); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_ENV, Gl.GL_MODULATE); } else { Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_NEAREST); Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGB8, w, h, Gl.GL_ABGR_EXT, Gl.GL_UNSIGNED_BYTE, intermediary.pixels); } /*int[] ExtraTex = new int[1]; * Gl.glGenTextures(1, ExtraTex); * Gl.glBindTexture(Gl.GL_TEXTURE_2D, ExtraTex[0]); * * Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 4, w, h, 0, Gl.GL_ABGR_EXT, * Gl.GL_UNSIGNED_BYTE, intermediary.pixels); * * Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR); * Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR); * Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_ENV, Gl.GL_MODULATE);// * * * /* Clean up */ Sdl.SDL_FreeSurface(Temp); Sdl.SDL_FreeSurface(Test); //Gl.glDeleteTextures(1, texture); SDLMetrics Metrics = new SDLMetrics(); SdlTtf.TTF_GlyphMetrics(m_Font, (short)Char, out Metrics.MinX, out Metrics.MaxX, out Metrics.MinY, out Metrics.MaxY, out Metrics.Advance); SDLGlyph ReturnGlyph = new SDLGlyph(Metrics, texture[0], w, h, Char); BuildList(ReturnGlyph); //ReturnGlyph.extraGLTex = ExtraTex[0]; return(ReturnGlyph); }