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.opengl.GL; | ||||
| import org.lwjgl.opengl.GL11; | ||||
| import org.lwjgl.opengl.GL45; | ||||
| import org.lwjgl.opengl.GL43; | ||||
| import org.lwjgl.system.Configuration; | ||||
| 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.textures.custom.Drawable; | ||||
| 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.values.GLBlendFactor; | ||||
| import speiger.src.coreengine.rendering.utils.values.GLDataType; | ||||
| 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.utils.eventbus.EventBus; | ||||
| import speiger.src.coreengine.utils.helpers.IOUtils; | ||||
| @ -66,7 +64,7 @@ public class NewInputTest { | ||||
| 	} | ||||
| 	 | ||||
| 	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));		 | ||||
| 	} | ||||
| 	 | ||||
| @ -79,7 +77,7 @@ public class NewInputTest { | ||||
| 		Joystick.INSTANCE.init(manager, bus); | ||||
| 		FileDrop.INSTANCE.init(bus); | ||||
| 		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(); | ||||
| 		guiShader.register(); | ||||
| 		assets.addListener(GLStateTracker.instance().shaders); | ||||
| @ -91,11 +89,11 @@ public class NewInputTest { | ||||
| 		System.out.println("Testing: "+GL.getCapabilities().OpenGL41); | ||||
| 		System.out.println("Testing: "+Integer.divideUnsigned(-1, 255)); | ||||
| 		 | ||||
| 		 | ||||
| 		GL11.glEnable(GL43.GL_MULTISAMPLE); | ||||
| 		int size = 512; | ||||
| 		int half = size >> 1; | ||||
| 		int base = size >> 3; | ||||
| 		 | ||||
| 				 | ||||
| 		DynamicTexture texture = new DynamicTexture(size, size, DynamicTexture.DEFAULT_PARAMETERS); | ||||
| 		texture.fill(0, 0, size, size, -1); | ||||
| 		texture.fill(0, 0, half, half, 255, 0, 0, 255); | ||||
| @ -151,14 +149,20 @@ public class NewInputTest { | ||||
| 		}); | ||||
| 		 | ||||
| //		String s = "The Quick brown fox Jumps over the Lazy dog"; | ||||
| 		float y = 100; | ||||
| 		float offset = font.drawText("The Quick ", 50, y, -1, buffer, false); | ||||
| 		offset += font.drawText(TextStyle.DEFAULT.size(24F), "Brown ", 50+offset, y, -1, buffer, false); | ||||
| 		offset += font.drawText(TextStyle.DEFAULT, "§<c=0x24FF00FF>F§<c=r>ox ", 50+offset, y, -1, buffer, false); | ||||
| 		offset += font.drawText(TextStyle.DEFAULT.size(16), "Jumps ", 50+offset, y, -1, buffer, false); | ||||
| 		offset += font.drawText(TextStyle.DEFAULT, "over the Lazy dog", 50+offset, y, -1, buffer, true); | ||||
| 		float x = 50; | ||||
| 		float y = 50; | ||||
| 		float scale = 1F; | ||||
| 		y /= scale; | ||||
| 		TextStyle style = TextStyle.DEFAULT.size(12).bold(false); | ||||
| 		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); | ||||
| 		 | ||||
| 		 | ||||
| 		GLStateTracker tracker = GLStateTracker.instance(); | ||||
| 		GL11.glClearColor(0.2F, 0.55F, 0.66F, 1F); | ||||
| 		while(!window.shouldClose()) { | ||||
| @ -166,7 +170,6 @@ public class NewInputTest { | ||||
| 			if(window.changed()) { | ||||
| 				window.updateViewport(); | ||||
| 				applyWindowSize(window); | ||||
| 				System.out.println("Called Resize"); | ||||
| 			} | ||||
| 			window.beginFrame(); | ||||
| 			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); | ||||
| @ -185,6 +188,11 @@ public class NewInputTest { | ||||
| 			} | ||||
| 			GLStateTracker.instance().blend.disable(); | ||||
| 			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.finishFrame(); | ||||
| 			try { Thread.sleep(100); } | ||||
| @ -211,7 +219,6 @@ public class NewInputTest { | ||||
| 				builder = new VertexBuilder(100000); | ||||
| 				builder.start(GLMode.TRIANGLES, VertexTypes.TESTING); | ||||
| 				previousId = textureId; | ||||
| 				System.out.println("Texture: "+textureId); | ||||
| 			} | ||||
| 			else if(previousId != textureId) { | ||||
| 				int count = builder.size() - lastVertex; | ||||
| @ -256,7 +263,7 @@ public class NewInputTest { | ||||
| 	public static class TestModel extends VertexArray { | ||||
| 		public TestModel(byte[] data) { | ||||
| 			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(); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @ -44,10 +44,10 @@ public class Font { | ||||
| 	} | ||||
| 	 | ||||
| 	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}; | ||||
| 		int[] currentColor = {currentStyle[0].hasColor() ? currentStyle[0].color() : color}; | ||||
| 		float xStart = x; | ||||
| @ -67,10 +67,10 @@ public class Font { | ||||
| 			} | ||||
| 			Glyth glyth = glyth(currentStyle[0].font(), codepoint); | ||||
| 			if(glyth.isValid()) { | ||||
| 				float minX = glyth.left() + x; | ||||
| 				float minY = glyth.top() + y; | ||||
| 				float maxX = glyth.right() + x; | ||||
| 				float maxY = glyth.bottom() + y; | ||||
| 				float minX = (glyth.left() + x) * scale; | ||||
| 				float minY = (glyth.top() + y) * scale; | ||||
| 				float maxX = (glyth.right() + x) * scale; | ||||
| 				float maxY = (glyth.bottom() + y) * scale; | ||||
| 				 | ||||
| 				IVertexBuilder builder = buffer.builderForTexture(glyth.texture()); | ||||
| 				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; | ||||
| 
 | ||||
| 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"); | ||||
| 	Map<AssetLocation, FontGroup> fonts = Object2ObjectMap.builder().linkedMap(); | ||||
| 	Map<String, BiFunction<JsonObject, IAssetProvider, IFontProvider>> fontParsers = Object2ObjectMap.builder().map(); | ||||
|  | ||||
| @ -1,24 +1,32 @@ | ||||
| package speiger.src.coreengine.rendering.gui.font; | ||||
| 
 | ||||
| public class FontSplitter { | ||||
| 	private static final int SPLITTER_CODE_POINT = '§'; | ||||
| 	private static final int FORMAT_CODE_POINT = '§'; | ||||
| 	 | ||||
| 	Font font; | ||||
| 	 | ||||
| 	public FontSplitter(Font font) { | ||||
| 		this.font = font; | ||||
| 		System.out.println("Testing: "+SPLITTER_CODE_POINT); | ||||
| 	} | ||||
| 	 | ||||
| 	public float width(String text) { | ||||
| 		return width(TextStyle.DEFAULT, text); | ||||
| 		return width(TextStyle.DEFAULT, text, true); | ||||
| 	} | ||||
| 	 | ||||
| 	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; | ||||
| 		for(int i = 0,m=text.length();i<m;i++) { | ||||
| 			int codePoint = text.codePointAt(i); | ||||
| 			total += font.data(style.font(), codePoint).advance(); | ||||
| 			int codepoint = text.codePointAt(i); | ||||
| 			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; | ||||
| 	} | ||||
|  | ||||
| @ -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) { | ||||
| 			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; | ||||
|  | ||||
| @ -105,7 +105,8 @@ public class FreeTypeProvider implements IFontProvider { | ||||
| 	 | ||||
| 	@Override | ||||
| 	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 | ||||
| @ -244,7 +245,7 @@ public class FreeTypeProvider implements IFontProvider { | ||||
| 			if(index == 0) return null; | ||||
| 			oversample *= this.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; | ||||
| 			FT_GlyphSlot slot = face.glyph(); | ||||
| 			if(slot == null) { | ||||
|  | ||||
| @ -140,7 +140,7 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer { | ||||
| 		public Iterator<Object2BooleanMap.Entry<GuiComponent>> iterator() { | ||||
| 			return new Iterator<>() { | ||||
| 				BasicEntry<GuiComponent> entry = new BasicEntry<>();  | ||||
| 				int myLayer = layer; | ||||
| 				int myLayer = 0; | ||||
| 				Iterator<GuiComponent> childIterator = components.getLast().iterator(); | ||||
| 				 | ||||
| 				@Override | ||||
| @ -152,8 +152,8 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer { | ||||
| 				public Entry<GuiComponent> next() { | ||||
| 					if(!hasNext()) throw new IllegalStateException("Out of Elements to poll"); | ||||
| 					entry.set(childIterator.next(), myLayer == layer); | ||||
| 					if(!childIterator.hasNext() && myLayer > 0) { | ||||
| 						childIterator = components.get(--myLayer).iterator(); | ||||
| 					if(!childIterator.hasNext() && myLayer < layer) { | ||||
| 						childIterator = components.get(++myLayer).iterator(); | ||||
| 					} | ||||
| 					return entry; | ||||
| 				} | ||||
|  | ||||
| @ -1,8 +1,8 @@ | ||||
| { | ||||
| 	"type": "free-ttf", | ||||
| 	"regular": { | ||||
| 		"file": "font/roboto/Roboto-Light.ttf", | ||||
| 		"oversample": 2, | ||||
| 		"file": "font/roboto/Roboto-Medium.ttf", | ||||
| 		"oversample": 1, | ||||
| 		"shadowOffset": 1, | ||||
| 		"skip": "", | ||||
| 		"offset": { "x": 0, "y": 0 } | ||||
|  | ||||
| @ -9,5 +9,6 @@ uniform sampler2D texture; | ||||
| 
 | ||||
| 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