[RFC,v2,3/5] kernel-shark: Add text rendering to the plotting example
diff mbox series

Message ID 20190703121023.16655-4-y.karadz@gmail.com
State New
Headers show
Series
  • Add support for text rendering
Related show

Commit Message

Yordan Karadzhov (VMware) July 3, 2019, 12:10 p.m. UTC
run:
kernel-shark/bin/dplot -s

And if the font file is loaded successfully you will see "Hello Kernel!"
rendered.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 kernel-shark/examples/dataplot.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch
diff mbox series

diff --git a/kernel-shark/examples/dataplot.cpp b/kernel-shark/examples/dataplot.cpp
index 94841e7..11b4fd9 100644
--- a/kernel-shark/examples/dataplot.cpp
+++ b/kernel-shark/examples/dataplot.cpp
@@ -44,6 +44,12 @@  void usage(const char *prog)
 /* An example function drawing something. */
 void drawShapes()
 {
+	char *font_file = ksplot_find_font_file("FreeMono", "FreeMonoBold");
+	struct ksplot_font font;
+
+	ksplot_init_font(&font, 40, font_file);
+	free(font_file);
+
 	/* Clear the screen. */
 	glClear(GL_COLOR_BUFFER_BIT);
 
@@ -57,6 +63,11 @@  void drawShapes()
 	t._color = {100, 200, 50};
 	t.draw();
 
+	/* Print/draw "Hello Kernel!". */
+	if (!ksplot_font_is_loaded(&font))
+		ksplot_print_text(&font, t._color.color_c_ptr(), 250, 70,
+				  "Hello Kernel!");
+
 	KsPlot::Rectangle r;
 	KsPlot::Point d(400, 200), e(400, 300), f(500, 300), g(500, 200);
 	r.setPoint(0, d);