简体   繁体   中英

Text not appearing in the compiled window while using fltk

I am going through the book "C++ programming principles and practices". I am learning how to use fltk (Chapter 12) and I have managed to install the library and compile the programs. I can draw basic shapes and color them,change the line texture used to draw them, however, the problem is that I cannot get text to appear on my final compiled window. The "Text" function responsible for outputting text to screen doesn't do anything. The screen has no text. The geometric shapes appear in the window, the problem is exclusive to text. The same is true when I try to add labels to my graphs. The "label" text doesn't appear. Everything else works perfectly and I have tried to compile the basic fltk hello,world programs. The text appears on the screen when I compiled them.

Here is the code

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main(){
    Point tl {100,100};
    Simple_window win {tl,600,400,"Canvas"};
    Axis xa {Axis::x, Point{20,300},280,10,"x axis"};
    win.attach(xa);
    win.set_label("Canvas#2");
    Axis ya{Axis::y, Point{20,300},280,10,"y axis"};
    ya.set_color(Color::cyan);
    ya.label.set_color(Color::dark_red);
    win.attach(ya);
    win.set_label("Canvas #3");
    Function sine{sin,0,100,Point{20,150},1000,50,50};
    win.attach(sine);
    win.set_label("Canvas#4");
    sine.set_color(Color::blue);
    Polygon poly;
    poly.add(Point{300,200});
    poly.add(Point{350,100});
    poly.add(Point{400,200});
    poly.set_color(Color::red);
    poly.set_style(Line_style::dash);
    win.attach(poly);
    Rectangle r{Point{200,200},100,50};
    win.attach(r);
    win.set_label("Canvas 6");
    Closed_polyline poly_rect;
    poly_rect.add(Point{100,50});
    poly_rect.add(Point{200,50});
    poly_rect.add(Point{200,100});
    poly_rect.add(Point{100,100});
    win.attach(poly_rect);
    poly_rect.add(Point{50,75});
    r.set_fill_color(Color::yellow);
    poly.set_style(Line_style(Line_style::dash,4));
    poly_rect.set_style(Line_style(Line_style::dash,2));
    poly_rect.set_fill_color(Color::green);
    win.set_label("Canvas 7");
    Text t{Point{150,150},"testing..."};
    win.attach(t);
    win.set_label("Canvas 8");
    win.wait_for_button();


}

The Simple_window and Graph files are files included with the book. These files utilize fl_draw to "draw" the text on the screen and I am assuming it is this function that is not working. I am using ubuntu and utilizing the g++ compiler.

This is my current ouptut

Ah, The problem was solved. Turns out the default font size for text is way too small to be visible to the naked eye. I had to increase the font size of the text by using the function "set_font_size" and the text became visible again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM