diff --git a/CMakeLists.txt b/CMakeLists.txt index 99f9dc7..219cb48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ pkg_check_modules(EGL REQUIRED egl) pkg_check_modules(GBM REQUIRED gbm) pkg_check_modules(FT2 REQUIRED freetype2) +#TODO: check for glm headers + # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/beamwave_frag.glsl b/beamwave_frag.glsl new file mode 100644 index 0000000..62efaa5 --- /dev/null +++ b/beamwave_frag.glsl @@ -0,0 +1,33 @@ +precision mediump float; + +uniform float time; +uniform vec3 resolution; + +vec3 beam(vec2 position) { + float brightness = 1.0 - abs(position.y - 0.5) * 2.0; + brightness = smoothstep(0.7, 1.0, brightness); + return vec3(0.25, 0.75, 1.0) * brightness; +} + +vec4 wave(vec2 position, float frequency, float height, float speed, vec3 color) { + float sinVal = sin(position.x * frequency - time * speed) * height; + sinVal = sinVal * 0.5 + 0.5; + + float brightness = 1.0 - abs(sinVal - position.y) * 1.5; + + brightness = smoothstep(0.5, 1.2, brightness); + float opacity = brightness; + + return vec4(color*brightness, opacity); +} + +void main( void ) { + vec2 position = (gl_FragCoord.xy / resolution.xy); + vec4 result; + + result += wave(position, 2.5, 0.5, 0.2, vec3(0.65, 0.22, 0.47)); + result += wave(position, 3.0, 0.3, 0.5, vec3(0.82, 0.5, 0.07)); + //result += wave(position, 5.0, 0.4, -0.6, vec3(0.0, 1.0, 0.0)); + + gl_FragColor =result; +} diff --git a/driver.cc b/driver.cc index 2e74ca6..48acdf1 100644 --- a/driver.cc +++ b/driver.cc @@ -323,10 +323,16 @@ int main(int argc, char* argv[]) setup_drm(); setup_egl(); - if (optManager->get("mode") == "text") + if (optManager->get("mode") == "text") { dc.action_mode = new TextMode; - else - dc.action_mode = new SceneMode; + } else { + string theme = optManager->get("theme"); + auto m = new SceneMode; + if (!theme.empty()) + m->setThemeFile(theme); + dc.action_mode = m; + + } if (!dc.action_mode->init(dc.mode.hdisplay, dc.mode.vdisplay)) { return -1; } diff --git a/options.cc b/options.cc index 9bedbe2..d129b98 100644 --- a/options.cc +++ b/options.cc @@ -13,7 +13,7 @@ OptionManager::OptionManager() void OptionManager::usage() { - cerr << "usage: " << _progName << " [-m [text|scene]] [-h]" << endl; + cerr << "usage: " << _progName << " [-m [text|scene] [-t theme]] [-h]" << endl; exit(EXIT_FAILURE); } @@ -26,13 +26,15 @@ void OptionManager::parse(int argc, char *argv[]) struct option opts[] = { {"mode", 1, NULL, 0}, + {"theme", 1, NULL, 0}, {NULL, 0, NULL, 0} }; int c, index; - while ((c = getopt_long(argc, argv, "m:h", opts, &index)) != -1) { + while ((c = getopt_long(argc, argv, "m:t:h", opts, &index)) != -1) { switch(c) { - case 'm': _mode = {optarg}; break; + case 'm': _opts["mode"] = {optarg}; break; + case 't': _opts["theme"] = {optarg}; break; case 'h': usage(); break; default: break; } @@ -50,3 +52,9 @@ OptionManager* OptionManager::get(int argc, char *argv[]) return _instance; } + +std::string OptionManager::get(std::string opt) +{ + return _opts[opt]; +} + diff --git a/options.h b/options.h index 2f85077..6fd2931 100644 --- a/options.h +++ b/options.h @@ -1,18 +1,19 @@ #ifndef _OPTIONS_H #define _OPTIONS_H +#include +#include #include class OptionManager { public: static OptionManager* get(int argc, char *argv[]); - template - T get(string opt); + std::string get(std::string opt); private: static OptionManager* _instance; - string _progName; - string _mode; + std::string _progName; + std::map _opts; OptionManager(); void parse(int argc, char *argv[]); @@ -20,13 +21,4 @@ class OptionManager { }; -template -T OptionManager::get(string opt) -{ - if (opt == "mode") - return _mode; - - return ""; -} - #endif diff --git a/scene.cc b/scene.cc index 400c8ce..5acb277 100644 --- a/scene.cc +++ b/scene.cc @@ -16,10 +16,21 @@ using namespace std; #include #include +SceneMode::SceneMode() + :_theme{"scene_frag.glsl"} // default theme +{ +} + +void SceneMode::setThemeFile(const std::string& glsl) +{ + this->_theme = glsl; + //check exists +} + bool SceneMode::init(int width, int height) { _screenWidth = width, _screenHeight = height; - GLProcess* proc = glprocess_create("scene_vertex.glsl", "scene_frag.glsl"); + GLProcess* proc = glprocess_create("scene_vertex.glsl", _theme.c_str()); if (!proc) return false; _proc = *proc; diff --git a/scene.h b/scene.h index 67890dc..a3db19b 100644 --- a/scene.h +++ b/scene.h @@ -1,13 +1,19 @@ #ifndef _SCENE_H #define _SCENE_H +#include #include "actionmode.h" class SceneMode: public ActionMode { public: + SceneMode(); + + void setThemeFile(const std::string& glsl); bool init(int width, int height); void deinit(); void render(); + private: + std::string _theme; // right now only a frag shader file }; #endif