Skip to content

Commit

Permalink
some refinements
Browse files Browse the repository at this point in the history
1. add font option
2. test against Ubuntu/Debian
  • Loading branch information
sonald committed Jan 22, 2016
1 parent 7f9e758 commit f806cc8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
25 changes: 17 additions & 8 deletions atlas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ int main(int argc, char* argv[])

if (optManager->value<string>("mode") == "text") {
std::cerr << "run in text rendering mode" << endl;
dc.action_mode = new TextMode;
auto m = new TextMode;
string font = optManager->value<string>("font");
if (!font.empty()) m->setFontPath(font);
dc.action_mode = m;
} else {
string theme = optManager->value<string>("theme");
auto m = new SceneMode;
Expand Down
9 changes: 6 additions & 3 deletions options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit f806cc8

Please sign in to comment.