Selaa lähdekoodia

Poking around with fonts. I think the font scale thingy is wrong, so there are some hacks in there right now to just get going and test it a bit

Karl Zylinski 5 kuukautta sitten
vanhempi
sitoutus
49a3a62306
2 muutettua tiedostoa jossa 23 lisäystä ja 4 poistoa
  1. 8 2
      README.md
  2. 15 2
      karl2d.odin

+ 8 - 2
README.md

@@ -16,7 +16,13 @@ Might not be included:
 
 Here follows my near-future TODO list
 
-* bunnymark
+* basic text rendering
+	* make draw_text and load_default_font do somethig more sensible
+	* look at how to properly get the scale from stb_ttf
+	* compare if we are doing the same as raylib by loading its default font and drawing some things, can we make it look similar?
+	* font smoothing -> make it look crisp by disabling filtering on "pixel fonts"
+	* next stage: Look into something more fancy than just loading bitmaps. What can we do?
+
 * should gamepad come from separate interface than window?
 	* keyboard input could also come from some input interface, but
 	  it is tightly bound to window in windows, so we'll see.
@@ -27,7 +33,6 @@ Here follows my near-future TODO list
 	* check status of gamepad
 	* what happens when you pull one out?
 	* playstation
-* basic text rendering
 * Do proper checks of vertex count and dispatch rendering when full
 	* What happens when list is full? We can't just empty the vertex list due to being used by input assembler etc.
 * Should we sort by depth? Maybe we should use Vec3 because some 2D games rely on it?
@@ -39,6 +44,7 @@ Here follows my near-future TODO list
 * set filtering: for scaling up, down and mipmap
 
 ## DONE
+* bunnymark
 * win32: Resizable window
 * Flashing textures in Abyss -- Better now but still flashes when you use nose... Check the "odd_frame" stuff in d3d backend
 * Is the 1/zoom in set_camera wrong? Is the matrix multiply order wrong? Hmmmm...

+ 15 - 2
karl2d.odin

@@ -622,13 +622,26 @@ draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotati
 	batch_vertex(bl, uv5, c)
 }
 
+measure_text :: proc(text: string, font_size: f32) -> Vec2 {
+	res: Vec2
+	res.y = font_size
+	scl := (font_size / s.default_font.size)
+
+	for t in text {
+		chr := s.default_font.chars[int(t)]
+		res.x += chr.xadvance * scl
+	}
+
+	return res
+}
+
 draw_text :: proc(text: string, pos: Vec2, font_size: f32, color: Color) {
 	if font_size == 0 || s.default_font.size == 0 {
 		return
 	}
 
 	x := pos.x
-	scl := 1.5 * (font_size / s.default_font.size)
+	scl := (font_size / s.default_font.size)
 
 	for t in text {
 		if t >= FONT_MAX_CHARS {
@@ -640,7 +653,7 @@ draw_text :: proc(text: string, pos: Vec2, font_size: f32, color: Color) {
 
 		dst := Rect {
 			x = x + chr.offset.x * scl,
-			y = pos.y + chr.offset.y * scl + font_size,
+			y = pos.y + chr.offset.y * scl + font_size*0.5,
 			w = src.w * scl,
 			h = src.h * scl,
 		}