diff --git a/README.md b/README.md index e5d4900..8778a36 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,10 @@ A simple plymouth replacement by using egl and drm. Build ===== -simple guide: +before build, install dependencies. On Ubuntu/Debian +`sudo apt-get install libglfw3-dev libglm-dev` + +simple version: ``` mkdir build @@ -15,8 +18,8 @@ make to compile successfully, you need mesa compiled with drm platform support and also gbm enabled. -this is satisfied in modern GNU/Linux (tested on iSoft Client OS -which is based on Archlinux). glm is required for opengl es matrix +this is satisfied in any of modern GNU/Linux distributions. +glm is required for openGLES matrix operation. for compiling demos, glfw3 is also needed. Run @@ -25,18 +28,18 @@ right now, there is no installation provided. you need to run it at project dir. ``` -./build/prometheus -m scene -t beamwave_frag.glsl +./build/prometheusd -m scene -t beamwave_frag.glsl ``` or run text rendering mode ``` -sudo ./build/prometheus -m text +sudo ./build/prometheusd -m text ``` if you got multiple video cards, you can use -c (--card) to specify one that is in use. ``` -sudo ./build/prometheus -m text --card /dev/dri/card1 -T /dev/tty2 +sudo ./build/prometheusd -m text --card /dev/dri/card1 -T /dev/tty2 ``` **note**: remember to run it at a virtual console. diff --git a/atlas.cc b/atlas.cc index 26ecbad..0fbf9a1 100644 --- a/atlas.cc +++ b/atlas.cc @@ -17,19 +17,28 @@ static FT_Library ft; static FT_Face face; static GLuint tex; -static void init_ft() +static void init_ft(const string& font) { if (FT_Init_FreeType(&ft)) { std::cerr << "init freetype failed" << std::endl; exit(-1); } - if (FT_New_Face(ft, "/usr/share/fonts/microsoft/msyh.ttf", 0, &face)) { - std::cerr << "load face failed" << std::endl; - exit(-1); + if (FT_New_Face(ft, font.c_str(), 0, &face)) { + std::cerr << "load " << font << " failed" << std::endl; + if (FT_New_Face(ft, "/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf", 0, &face)) { + std::cerr << "load face failed" << std::endl; + exit(-1); + } } } +void TextMode::setFontPath(const std::string& path) +{ + /* TODO: check validity */ + _fontPath = path; +} + bool TextMode::load_char_helper(FT_ULong char_code) { FT_GlyphSlot slot = face->glyph; @@ -137,7 +146,7 @@ extern const char _binary_atlas_vertex_glsl_start[]; bool TextMode::init(int width, int height) { _screenWidth = width, _screenHeight = height; - init_ft(); + init_ft(_fontPath); GLuint vlen = _binary_atlas_vertex_glsl_end - _binary_atlas_vertex_glsl_start; GLuint flen = _binary_atlas_frag_glsl_end - _binary_atlas_frag_glsl_start; @@ -176,7 +185,7 @@ bool TextMode::init(int width, int height) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - create_atlas(face, 28, "普华客户端操作系统"); + create_atlas(face, 28, "正在加载操作系统....."); glClearColor(0.1, 0.1, 0.4, 1.0); return true; @@ -209,14 +218,14 @@ void TextMode::render() float sx = 2.0 / _screenWidth, sy = 2.0 / _screenHeight; float x = -1.0, y = 1.0 - ps1 * sy; - render_str("Welcome to iSoft Client OS", x, y, sx, sy); + render_str("Welcome to Linux", x, y, sx, sy); GLfloat bgcolor2[] = { 0, float((glm::cos(t) + 1.0)/2.0), float((glm::sin(t)+1.0)/2.0), 0.5 }; glUniform4fv(glGetUniformLocation(_proc.program, "bgcolor"), 1, bgcolor2); x = -1.0 + (_screenWidth/2.0) * sx - 0.3, y = 1.0 - (_screenHeight/2.0) * sy; - render_str("普华客户端操作系统", x, y, sx, sy); + render_str("真正加载操作系统......", x, y, sx, sy); y -= ps1 * 2 * sy; render_str("System Loading...", x, y, sx, sy); diff --git a/atlas.h b/atlas.h index b5a1729..d1fc1e6 100644 --- a/atlas.h +++ b/atlas.h @@ -34,9 +34,12 @@ class TextMode: public ActionMode { bool init(int width, int height); void deinit(); void render(); + void setFontPath(const std::string& path); private: atlas_t _atlas; + std::string _fontPath; + void create_atlas(FT_Face face, int pointSize, std::string preloads); void render_str(std::string s, float x, float y, float sx, float sy); bool load_char_helper(FT_ULong char_code); diff --git a/driver.cc b/driver.cc index 824fef5..21793bd 100644 --- a/driver.cc +++ b/driver.cc @@ -538,7 +538,10 @@ int main(int argc, char* argv[]) if (optManager->value("mode") == "text") { std::cerr << "run in text rendering mode" << endl; - dc.action_mode = new TextMode; + auto m = new TextMode; + string font = optManager->value("font"); + if (!font.empty()) m->setFontPath(font); + dc.action_mode = m; } else { string theme = optManager->value("theme"); auto m = new SceneMode; diff --git a/options.cc b/options.cc index be9d4e5..5fbbc92 100644 --- a/options.cc +++ b/options.cc @@ -14,8 +14,9 @@ OptionManager::OptionManager() void OptionManager::usage() { cerr << "usage: " << _progName - << " [-c|--card card] [-m|--mode [text|scene] " - << "[-t|--theme theme]] [-T|--tty ttyname] [-n|--nodaemon] [-h]" + << " [-c|--card card] [-m|--mode [text|scene]] [-T|--tty ttyname] [-n|--nodaemon] [-h]" << endl + << " scene mode [-t|--theme theme] " << endl + << " text mode [-f|--font full_ttf_font_path] " << endl << endl; exit(EXIT_FAILURE); } @@ -33,14 +34,16 @@ void OptionManager::parse(int argc, char *argv[]) {"card", 1, NULL, 'c'}, {"tty", 1, NULL, 'T'}, {"nodaemon", 0, NULL, 'n'}, + {"font", 1, NULL, 'f'}, {NULL, 0, NULL, 0}, }; int c, index; - while ((c = getopt_long(argc, argv, "m:t:c:T:nh", opts, &index)) != -1) { + while ((c = getopt_long(argc, argv, "f:m:t:c:T:nh", opts, &index)) != -1) { switch(c) { case 'm': _opts["mode"] = {optarg}; break; case 't': _opts["theme"] = {optarg}; break; + case 'f': _opts["font"] = {optarg}; break; case 'c': _opts["card"] = {optarg}; break; case 'T': _opts["tty"] = {optarg}; break; case 'n': _opts["nodaemon"] = "true"; break;