Fixed Font Renderering. Now its perfect!
This commit is contained in:
		
							parent
							
								
									857f5eec64
								
							
						
					
					
						commit
						8ef73e4059
					
				| @ -6,7 +6,7 @@ import java.util.function.BiConsumer; | |||||||
| import org.lwjgl.glfw.GLFW; | import org.lwjgl.glfw.GLFW; | ||||||
| import org.lwjgl.opengl.GL; | import org.lwjgl.opengl.GL; | ||||||
| import org.lwjgl.opengl.GL11; | import org.lwjgl.opengl.GL11; | ||||||
| import org.lwjgl.opengl.GL45; | import org.lwjgl.opengl.GL43; | ||||||
| import org.lwjgl.system.Configuration; | import org.lwjgl.system.Configuration; | ||||||
| import org.lwjgl.util.freetype.FreeType; | import org.lwjgl.util.freetype.FreeType; | ||||||
| 
 | 
 | ||||||
| @ -41,12 +41,10 @@ import speiger.src.coreengine.rendering.tesselation.buffer.VertexBuilder; | |||||||
| import speiger.src.coreengine.rendering.tesselation.format.VertexTypes; | import speiger.src.coreengine.rendering.tesselation.format.VertexTypes; | ||||||
| import speiger.src.coreengine.rendering.textures.custom.Drawable; | import speiger.src.coreengine.rendering.textures.custom.Drawable; | ||||||
| import speiger.src.coreengine.rendering.textures.custom.DynamicTexture; | import speiger.src.coreengine.rendering.textures.custom.DynamicTexture; | ||||||
| import speiger.src.coreengine.rendering.utils.GLFunctions; |  | ||||||
| import speiger.src.coreengine.rendering.utils.GLStateTracker; | import speiger.src.coreengine.rendering.utils.GLStateTracker; | ||||||
| import speiger.src.coreengine.rendering.utils.values.GLBlendFactor; | import speiger.src.coreengine.rendering.utils.values.GLBlendFactor; | ||||||
| import speiger.src.coreengine.rendering.utils.values.GLDataType; | import speiger.src.coreengine.rendering.utils.values.GLDataType; | ||||||
| import speiger.src.coreengine.rendering.utils.values.GLMode; | import speiger.src.coreengine.rendering.utils.values.GLMode; | ||||||
| import speiger.src.coreengine.rendering.utils.values.IGLValue.ISourceFactor; |  | ||||||
| import speiger.src.coreengine.rendering.utils.values.textures.GLTextureFormat; | import speiger.src.coreengine.rendering.utils.values.textures.GLTextureFormat; | ||||||
| import speiger.src.coreengine.utils.eventbus.EventBus; | import speiger.src.coreengine.utils.eventbus.EventBus; | ||||||
| import speiger.src.coreengine.utils.helpers.IOUtils; | import speiger.src.coreengine.utils.helpers.IOUtils; | ||||||
| @ -66,7 +64,7 @@ public class NewInputTest { | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	private void applyWindowSize(Window window) { | 	private void applyWindowSize(Window window) { | ||||||
| 		int scale = 2; | 		int scale = 0; | ||||||
| 		guiShader.get().proView.set(new Matrix4f().ortho(0, 0, window.width() >> scale, window.height() >> scale, 1000, -1000));		 | 		guiShader.get().proView.set(new Matrix4f().ortho(0, 0, window.width() >> scale, window.height() >> scale, 1000, -1000));		 | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| @ -79,7 +77,7 @@ public class NewInputTest { | |||||||
| 		Joystick.INSTANCE.init(manager, bus); | 		Joystick.INSTANCE.init(manager, bus); | ||||||
| 		FileDrop.INSTANCE.init(bus); | 		FileDrop.INSTANCE.init(bus); | ||||||
| 		manager.addDevices(Mouse.INSTANCE, Keyboard.INSTANCE, Joystick.INSTANCE, FileDrop.INSTANCE); | 		manager.addDevices(Mouse.INSTANCE, Keyboard.INSTANCE, Joystick.INSTANCE, FileDrop.INSTANCE); | ||||||
| 		Window window = manager.builder().title("Testing Engine").width(800).height(600).antialis(2).build(); | 		Window window = manager.builder().title("Testing Engine").width(800).height(600).antialis(0).build(); | ||||||
| 		shaderTest.register(); | 		shaderTest.register(); | ||||||
| 		guiShader.register(); | 		guiShader.register(); | ||||||
| 		assets.addListener(GLStateTracker.instance().shaders); | 		assets.addListener(GLStateTracker.instance().shaders); | ||||||
| @ -91,7 +89,7 @@ public class NewInputTest { | |||||||
| 		System.out.println("Testing: "+GL.getCapabilities().OpenGL41); | 		System.out.println("Testing: "+GL.getCapabilities().OpenGL41); | ||||||
| 		System.out.println("Testing: "+Integer.divideUnsigned(-1, 255)); | 		System.out.println("Testing: "+Integer.divideUnsigned(-1, 255)); | ||||||
| 		 | 		 | ||||||
| 		 | 		GL11.glEnable(GL43.GL_MULTISAMPLE); | ||||||
| 		int size = 512; | 		int size = 512; | ||||||
| 		int half = size >> 1; | 		int half = size >> 1; | ||||||
| 		int base = size >> 3; | 		int base = size >> 3; | ||||||
| @ -151,14 +149,20 @@ public class NewInputTest { | |||||||
| 		}); | 		}); | ||||||
| 		 | 		 | ||||||
| //		String s = "The Quick brown fox Jumps over the Lazy dog"; | //		String s = "The Quick brown fox Jumps over the Lazy dog"; | ||||||
| 		float y = 100; | 		float x = 50; | ||||||
| 		float offset = font.drawText("The Quick ", 50, y, -1, buffer, false); | 		float y = 50; | ||||||
| 		offset += font.drawText(TextStyle.DEFAULT.size(24F), "Brown ", 50+offset, y, -1, buffer, false); | 		float scale = 1F; | ||||||
| 		offset += font.drawText(TextStyle.DEFAULT, "§<c=0x24FF00FF>F§<c=r>ox ", 50+offset, y, -1, buffer, false); | 		y /= scale; | ||||||
| 		offset += font.drawText(TextStyle.DEFAULT.size(16), "Jumps ", 50+offset, y, -1, buffer, false); | 		TextStyle style = TextStyle.DEFAULT.size(12).bold(false); | ||||||
| 		offset += font.drawText(TextStyle.DEFAULT, "over the Lazy dog", 50+offset, y, -1, buffer, true); | 		font.drawText(style, "Testing My Theory", x, y, -1, buffer, scale, true); | ||||||
|  | //		float offset = font.drawText(style, "The Quick ", 50, y, -1, buffer, scale, false); | ||||||
|  | //		offset += font.drawText(style, "Brown ", 50+offset, y, -1, buffer, scale, false); | ||||||
|  | //		offset += font.drawText(style, "§<c=0x24FF00FF>F§<c=r>ox ", 50+offset, y, -1, buffer, scale, false); | ||||||
|  | //		offset += font.drawText(style, "Jumps ", 50+offset, y, -1, buffer, scale, false); | ||||||
|  | //		offset += font.drawText(style, "over the Lazy dog", 50+offset, y, -1, buffer, scale, true); | ||||||
| //		font.drawText(s, 50, 50, -1, buffer, true); | //		font.drawText(s, 50, 50, -1, buffer, true); | ||||||
| 		 | 		 | ||||||
|  | 		 | ||||||
| 		GLStateTracker tracker = GLStateTracker.instance(); | 		GLStateTracker tracker = GLStateTracker.instance(); | ||||||
| 		GL11.glClearColor(0.2F, 0.55F, 0.66F, 1F); | 		GL11.glClearColor(0.2F, 0.55F, 0.66F, 1F); | ||||||
| 		while(!window.shouldClose()) { | 		while(!window.shouldClose()) { | ||||||
| @ -166,7 +170,6 @@ public class NewInputTest { | |||||||
| 			if(window.changed()) { | 			if(window.changed()) { | ||||||
| 				window.updateViewport(); | 				window.updateViewport(); | ||||||
| 				applyWindowSize(window); | 				applyWindowSize(window); | ||||||
| 				System.out.println("Called Resize"); |  | ||||||
| 			} | 			} | ||||||
| 			window.beginFrame(); | 			window.beginFrame(); | ||||||
| 			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); | 			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); | ||||||
| @ -185,6 +188,11 @@ public class NewInputTest { | |||||||
| 			} | 			} | ||||||
| 			GLStateTracker.instance().blend.disable(); | 			GLStateTracker.instance().blend.disable(); | ||||||
| 			guiModel[0].unbindArray(); | 			guiModel[0].unbindArray(); | ||||||
|  | //			NanoVG.nvgBeginFrame(vg, window.width(), window.height(), 1F); | ||||||
|  | //			NanoVG.nvgFontSize(vg, 64); | ||||||
|  | //			NanoVG.nvgText(vg, 50, 520, "Testing My Theory"); | ||||||
|  | //			NanoVG.nvgEndFrame(vg); | ||||||
|  | 
 | ||||||
| 			window.handleInput(); | 			window.handleInput(); | ||||||
| 			window.finishFrame(); | 			window.finishFrame(); | ||||||
| 			try { Thread.sleep(100); } | 			try { Thread.sleep(100); } | ||||||
| @ -211,7 +219,6 @@ public class NewInputTest { | |||||||
| 				builder = new VertexBuilder(100000); | 				builder = new VertexBuilder(100000); | ||||||
| 				builder.start(GLMode.TRIANGLES, VertexTypes.TESTING); | 				builder.start(GLMode.TRIANGLES, VertexTypes.TESTING); | ||||||
| 				previousId = textureId; | 				previousId = textureId; | ||||||
| 				System.out.println("Texture: "+textureId); |  | ||||||
| 			} | 			} | ||||||
| 			else if(previousId != textureId) { | 			else if(previousId != textureId) { | ||||||
| 				int count = builder.size() - lastVertex; | 				int count = builder.size() - lastVertex; | ||||||
| @ -256,7 +263,7 @@ public class NewInputTest { | |||||||
| 	public static class TestModel extends VertexArray { | 	public static class TestModel extends VertexArray { | ||||||
| 		public TestModel(byte[] data) { | 		public TestModel(byte[] data) { | ||||||
| 			bind(); | 			bind(); | ||||||
| 			createBuffer(new BufferAttribute(0, 3), new BufferAttribute(1, 2), new BufferAttribute(2, 4, GLDataType.UNSIGNED_BYTE)).set(data).unbind(); | 			createBuffer(new BufferAttribute(0, 3), new BufferAttribute(1, 2), new BufferAttribute(2, 4, GLDataType.UNSIGNED_BYTE, true)).set(data).unbind(); | ||||||
| 			unbind(); | 			unbind(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -44,10 +44,10 @@ public class Font { | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public float drawText(String text, float x, float y, int color, TexturedBuffer buffer, boolean end) { | 	public float drawText(String text, float x, float y, int color, TexturedBuffer buffer, boolean end) { | ||||||
| 		return drawText(TextStyle.DEFAULT, text, x, y, color, buffer, end); | 		return drawText(TextStyle.DEFAULT, text, x, y, color, buffer, 1F, end); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public float drawText(TextStyle style, String text, float x, float y, int color, TexturedBuffer buffer, boolean end) { | 	public float drawText(TextStyle style, String text, float x, float y, int color, TexturedBuffer buffer, float scale, boolean end) { | ||||||
| 		TextStyle[] currentStyle = {style}; | 		TextStyle[] currentStyle = {style}; | ||||||
| 		int[] currentColor = {currentStyle[0].hasColor() ? currentStyle[0].color() : color}; | 		int[] currentColor = {currentStyle[0].hasColor() ? currentStyle[0].color() : color}; | ||||||
| 		float xStart = x; | 		float xStart = x; | ||||||
| @ -67,10 +67,10 @@ public class Font { | |||||||
| 			} | 			} | ||||||
| 			Glyth glyth = glyth(currentStyle[0].font(), codepoint); | 			Glyth glyth = glyth(currentStyle[0].font(), codepoint); | ||||||
| 			if(glyth.isValid()) { | 			if(glyth.isValid()) { | ||||||
| 				float minX = glyth.left() + x; | 				float minX = (glyth.left() + x) * scale; | ||||||
| 				float minY = glyth.top() + y; | 				float minY = (glyth.top() + y) * scale; | ||||||
| 				float maxX = glyth.right() + x; | 				float maxX = (glyth.right() + x) * scale; | ||||||
| 				float maxY = glyth.bottom() + y; | 				float maxY = (glyth.bottom() + y) * scale; | ||||||
| 				 | 				 | ||||||
| 				IVertexBuilder builder = buffer.builderForTexture(glyth.texture()); | 				IVertexBuilder builder = buffer.builderForTexture(glyth.texture()); | ||||||
| 				builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(currentColor[0]).endVertex(); | 				builder.pos(minX, minY, 0F).tex(glyth.minU(), glyth.minV()).rgba(currentColor[0]).endVertex(); | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ import speiger.src.coreengine.rendering.gui.font.providers.STBTrueTypeProvider; | |||||||
| import speiger.src.coreengine.utils.helpers.JsonUtil; | import speiger.src.coreengine.utils.helpers.JsonUtil; | ||||||
| 
 | 
 | ||||||
| public class FontManager extends SteppedReloadableAsset<Map<AssetLocation, ObjectList<IFontProvider>>> { | public class FontManager extends SteppedReloadableAsset<Map<AssetLocation, ObjectList<IFontProvider>>> { | ||||||
| 	private static final int TEXTURE_SIZE = 4096; | 	private static final int TEXTURE_SIZE = 512; | ||||||
| 	private static final AssetFilter FILTER = AssetFilter.json("font"); | 	private static final AssetFilter FILTER = AssetFilter.json("font"); | ||||||
| 	Map<AssetLocation, FontGroup> fonts = Object2ObjectMap.builder().linkedMap(); | 	Map<AssetLocation, FontGroup> fonts = Object2ObjectMap.builder().linkedMap(); | ||||||
| 	Map<String, BiFunction<JsonObject, IAssetProvider, IFontProvider>> fontParsers = Object2ObjectMap.builder().map(); | 	Map<String, BiFunction<JsonObject, IAssetProvider, IFontProvider>> fontParsers = Object2ObjectMap.builder().map(); | ||||||
|  | |||||||
| @ -1,24 +1,32 @@ | |||||||
| package speiger.src.coreengine.rendering.gui.font; | package speiger.src.coreengine.rendering.gui.font; | ||||||
| 
 | 
 | ||||||
| public class FontSplitter { | public class FontSplitter { | ||||||
| 	private static final int SPLITTER_CODE_POINT = '§'; | 	private static final int FORMAT_CODE_POINT = '§'; | ||||||
| 	 | 	 | ||||||
| 	Font font; | 	Font font; | ||||||
| 	 | 	 | ||||||
| 	public FontSplitter(Font font) { | 	public FontSplitter(Font font) { | ||||||
| 		this.font = font; | 		this.font = font; | ||||||
| 		System.out.println("Testing: "+SPLITTER_CODE_POINT); |  | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public float width(String text) { | 	public float width(String text) { | ||||||
| 		return width(TextStyle.DEFAULT, text); | 		return width(TextStyle.DEFAULT, text, true); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public float width(TextStyle style, String text) { | 	public float width(TextStyle style, String text) { | ||||||
|  | 		return width(style, text, true); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public float width(TextStyle style, String text, boolean applyStyleChanges) { | ||||||
|  | 		TextStyle[] currentStyle = new TextStyle[] {style}; | ||||||
| 		float total = 0F; | 		float total = 0F; | ||||||
| 		for(int i = 0,m=text.length();i<m;i++) { | 		for(int i = 0,m=text.length();i<m;i++) { | ||||||
| 			int codePoint = text.codePointAt(i); | 			int codepoint = text.codePointAt(i); | ||||||
| 			total += font.data(style.font(), codePoint).advance(); | 			if(codepoint == FORMAT_CODE_POINT && font.applyStyle(text, i+1, currentStyle[0], style, T -> currentStyle[0] = T)) { | ||||||
|  | 				i = text.indexOf('>', i)+1; | ||||||
|  | 				continue; | ||||||
|  | 			} | ||||||
|  | 			total += font.data(style.font(), codepoint).advance(); | ||||||
| 		} | 		} | ||||||
| 		return total; | 		return total; | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -111,7 +111,7 @@ public record TextStyle(FontStyle font, int styleFlags, int color) { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		if(color != color() || hasColor != hasColor() || bold != bold() || italic != italic() || underline != underline() || strikethrough != strikethrough() || font != font().font() || size != size) { | 		if(color != color() || hasColor != hasColor() || bold != bold() || italic != italic() || underline != underline() || strikethrough != strikethrough() || font != font().font() || size != size) { | ||||||
| 			return new TextStyle(font().with(font, (bold ? FontStyle.BOLD : FontStyle.REGULAR) | (bold ? FontStyle.ITALIC : FontStyle.REGULAR), size), (underline ? UNDERLINE : NONE) | (strikethrough ? STRIKETHROUGH : NONE) | (hasColor ? HAS_COLOR : NONE), color); | 			return new TextStyle(font().with(font, (bold ? FontStyle.BOLD : FontStyle.REGULAR) | (italic ? FontStyle.ITALIC : FontStyle.REGULAR), size), (underline ? UNDERLINE : NONE) | (strikethrough ? STRIKETHROUGH : NONE) | (hasColor ? HAS_COLOR : NONE), color); | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		return this; | 		return this; | ||||||
|  | |||||||
| @ -105,7 +105,8 @@ public class FreeTypeProvider implements IFontProvider { | |||||||
| 	 | 	 | ||||||
| 	@Override | 	@Override | ||||||
| 	public UnbakedGlyth glythData(int codepoint, int style, float size, float oversample) { | 	public UnbakedGlyth glythData(int codepoint, int style, float size, float oversample) { | ||||||
| 		return instance[style & 0x3].gylthData(codepoint, size, oversample); | 		FreeTypeInstance instance = this.instance[style & 0x3]; | ||||||
|  | 		return instance != null ? instance.gylthData(codepoint, size, oversample) : null; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	@Override | 	@Override | ||||||
| @ -244,7 +245,7 @@ public class FreeTypeProvider implements IFontProvider { | |||||||
| 			if(index == 0) return null; | 			if(index == 0) return null; | ||||||
| 			oversample *= this.oversample; | 			oversample *= this.oversample; | ||||||
| 	        int pixels = Math.round(size * oversample); | 	        int pixels = Math.round(size * oversample); | ||||||
| 	        if(FreeTypeLibrary.parseError(FreeType.FT_Set_Pixel_Sizes(face, pixels, pixels), "Set Pixel Size")) return null; | 	        if(FreeTypeLibrary.parseError(FreeType.FT_Set_Pixel_Sizes(face, 0, pixels), "Set Pixel Size")) return null; | ||||||
| 			if(FreeTypeLibrary.parseError(FreeType.FT_Load_Glyph(face, index, FreeType.FT_LOAD_NO_BITMAP | FreeType.FT_LOAD_BITMAP_METRICS_ONLY), "Loading Glyth")) return null; | 			if(FreeTypeLibrary.parseError(FreeType.FT_Load_Glyph(face, index, FreeType.FT_LOAD_NO_BITMAP | FreeType.FT_LOAD_BITMAP_METRICS_ONLY), "Loading Glyth")) return null; | ||||||
| 			FT_GlyphSlot slot = face.glyph(); | 			FT_GlyphSlot slot = face.glyph(); | ||||||
| 			if(slot == null) { | 			if(slot == null) { | ||||||
|  | |||||||
| @ -140,7 +140,7 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer { | |||||||
| 		public Iterator<Object2BooleanMap.Entry<GuiComponent>> iterator() { | 		public Iterator<Object2BooleanMap.Entry<GuiComponent>> iterator() { | ||||||
| 			return new Iterator<>() { | 			return new Iterator<>() { | ||||||
| 				BasicEntry<GuiComponent> entry = new BasicEntry<>();  | 				BasicEntry<GuiComponent> entry = new BasicEntry<>();  | ||||||
| 				int myLayer = layer; | 				int myLayer = 0; | ||||||
| 				Iterator<GuiComponent> childIterator = components.getLast().iterator(); | 				Iterator<GuiComponent> childIterator = components.getLast().iterator(); | ||||||
| 				 | 				 | ||||||
| 				@Override | 				@Override | ||||||
| @ -152,8 +152,8 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer { | |||||||
| 				public Entry<GuiComponent> next() { | 				public Entry<GuiComponent> next() { | ||||||
| 					if(!hasNext()) throw new IllegalStateException("Out of Elements to poll"); | 					if(!hasNext()) throw new IllegalStateException("Out of Elements to poll"); | ||||||
| 					entry.set(childIterator.next(), myLayer == layer); | 					entry.set(childIterator.next(), myLayer == layer); | ||||||
| 					if(!childIterator.hasNext() && myLayer > 0) { | 					if(!childIterator.hasNext() && myLayer < layer) { | ||||||
| 						childIterator = components.get(--myLayer).iterator(); | 						childIterator = components.get(++myLayer).iterator(); | ||||||
| 					} | 					} | ||||||
| 					return entry; | 					return entry; | ||||||
| 				} | 				} | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| { | { | ||||||
| 	"type": "free-ttf", | 	"type": "free-ttf", | ||||||
| 	"regular": { | 	"regular": { | ||||||
| 		"file": "font/roboto/Roboto-Light.ttf", | 		"file": "font/roboto/Roboto-Medium.ttf", | ||||||
| 		"oversample": 2, | 		"oversample": 1, | ||||||
| 		"shadowOffset": 1, | 		"shadowOffset": 1, | ||||||
| 		"skip": "", | 		"skip": "", | ||||||
| 		"offset": { "x": 0, "y": 0 } | 		"offset": { "x": 0, "y": 0 } | ||||||
|  | |||||||
| @ -9,5 +9,6 @@ uniform sampler2D texture; | |||||||
| 
 | 
 | ||||||
| void main() | void main() | ||||||
| { | { | ||||||
| 	frag_color = pass_color * texture2D(texture, pass_tex); | 	vec4 color = texture2D(texture, pass_tex); | ||||||
|  | 	frag_color = pass_color * vec4(1, 1, 1, color.r); | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user