unsafe private void SetupGlyphTexCoord(string content, IFontTexture fontTexture) { FullDictionary <char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary; IntPtr pointer = this.uvBuffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (TextModel.GlyphTexCoord *)pointer.ToPointer(); int width = fontTexture.TextureSize.Width; int height = fontTexture.TextureSize.Height; /* * 0 3 4 6 8 11 12 15 * ------- ------- ------- ------- * | | | | | | | | * | | | | | | | | * | | | | | | | | * ------- ------- ------- ------- * 1 2 5 6 9 10 13 14 */ for (int i = 0; i < content.Length; i++) { char ch = content[i]; GlyphInfo info = fontTexture.GlyphInfoDictionary[ch]; const int shrimp = 0; array[i] = new TextModel.GlyphTexCoord( //new vec2(0, 0), //new vec2(0, 1), //new vec2(1, 1), //new vec2(1, 0) new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset) / (float)height), new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset + info.height) / (float)height), new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset + info.height) / (float)height), new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset) / (float)height) ); } this.uvBuffer.UnmapBuffer(); }
private unsafe void SetupGlyphTexCoord(string content, FontResource fontResource) { FullDictionary<char, CharacterInfo> charInfoDict = fontResource.CharInfoDict; OpenGL.BindBuffer(BufferTarget.ArrayBuffer, this.model.uvBufferPtr.BufferId); IntPtr pointer = OpenGL.MapBuffer(BufferTarget.ArrayBuffer, MapBufferAccess.WriteOnly); var array = (TextModel.GlyphTexCoord*)pointer.ToPointer(); int width = fontResource.TextureSize.Width; int height = fontResource.TextureSize.Height; /* * 0 3 4 6 8 11 12 15 * ------- ------- ------- ------- * | | | | | | | | * | | | | | | | | * | | | | | | | | * ------- ------- ------- ------- * 1 2 5 6 9 10 13 14 */ for (int i = 0; i < content.Length; i++) { char ch = content[i]; CharacterInfo info = fontResource.CharInfoDict[ch]; const int shrimp = 0; array[i] = new TextModel.GlyphTexCoord( //new vec2(0, 0), //new vec2(0, 1), //new vec2(1, 1), //new vec2(1, 0) new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset) / (float)height), new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset + info.height) / (float)height), new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset + info.height) / (float)height), new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset) / (float)height) ); } OpenGL.UnmapBuffer(BufferTarget.ArrayBuffer); OpenGL.BindBuffer(BufferTarget.ArrayBuffer, 0); }
private unsafe void SetupGlyphTexCoord(string content, IFontTexture fontTexture) { FullDictionary<char, GlyphInfo> charInfoDict = fontTexture.GlyphInfoDictionary; IntPtr pointer = this.uvBuffer.MapBuffer(MapBufferAccess.WriteOnly); var array = (TextModel.GlyphTexCoord*)pointer.ToPointer(); int width = fontTexture.TextureSize.Width; int height = fontTexture.TextureSize.Height; /* * 0 3 4 6 8 11 12 15 * ------- ------- ------- ------- * | | | | | | | | * | | | | | | | | * | | | | | | | | * ------- ------- ------- ------- * 1 2 5 6 9 10 13 14 */ for (int i = 0; i < content.Length; i++) { char ch = content[i]; GlyphInfo info = fontTexture.GlyphInfoDictionary[ch]; const int shrimp = 0; array[i] = new TextModel.GlyphTexCoord( //new vec2(0, 0), //new vec2(0, 1), //new vec2(1, 1), //new vec2(1, 0) new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset) / (float)height), new vec2((float)(info.xoffset + shrimp) / (float)width, (float)(info.yoffset + info.height) / (float)height), new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset + info.height) / (float)height), new vec2((float)(info.xoffset - shrimp + info.width) / (float)width, (float)(info.yoffset) / (float)height) ); } this.uvBuffer.UnmapBuffer(); }