From 05dea194366f033a10352c6c0eaa3fcbe172c77b Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 16 Jan 2019 23:45:44 +0100 Subject: [PATCH] further cleanup --- src/core/include/pw/core/rect.hpp | 2 +- src/core/src/timer.cpp | 3 +-- src/scripting/src/script_system.cpp | 3 ++- src/scripts/demos/simple_000.lua | 15 ++++++----- src/system/include/pw/system/input.hpp | 3 +++ src/system/include/pw/system/window.hpp | 2 ++ src/system/src/window.cpp | 33 +++++++++++++++++-------- src/visual/src/pipeline.cpp | 18 ++++++++++---- 8 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/core/include/pw/core/rect.hpp b/src/core/include/pw/core/rect.hpp index 8c91b54..779626f 100644 --- a/src/core/include/pw/core/rect.hpp +++ b/src/core/include/pw/core/rect.hpp @@ -38,7 +38,7 @@ struct rect_ { rect_(point_ const & p,size_ const & s) : size(s), position(p) {} - bool contains(const point_& p) + bool contains(const point_& p) const { return p.x >= position.x && p.x <= position.x + size.width && p.y >= position.y && p.y <= position.y + size.height; diff --git a/src/core/src/timer.cpp b/src/core/src/timer.cpp index 16ae81e..f6c5c44 100644 --- a/src/core/src/timer.cpp +++ b/src/core/src/timer.cpp @@ -24,8 +24,6 @@ namespace pw { -static timer global_timer; - timer::timer() { reset(); @@ -48,6 +46,7 @@ double timer::elapsed() const double timer::now() { + static timer global_timer; return global_timer.elapsed(); } diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 96d81b8..bbc45cc 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -17,7 +17,8 @@ void script_system::load(sol::table &ns) "size",sol::property(&window::size,&window::set_size), "client_size",sol::readonly_property(&window::client_size), "position",sol::property(&window::position,&window::set_position), - "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) + "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen), + "visible",sol::property(&window::visible,&window::set_visible) ); diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 8fea86d..2145f44 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -66,6 +66,7 @@ end --n_1:add_child() local w = pw.window.new() +w.visible = false -- set title w.title = "pixwerx 0.1" @@ -75,6 +76,8 @@ w.size = pw.size.new(800,600) -- move window w.position = pw.point.new(100,100) +print("client size after resize: ",w.client_size.width,w.client_size.height) + local pl = pw.pipeline.new() if pl:create(w.client_size) then @@ -83,12 +86,11 @@ else print("pipeline failed") end - --- setup a lua callback function +-- setup a lua callback function as callback w.on_update = function(self) - pl:draw() -- print("test on update",w.position.x,w.position.y,pw.timer.now) + end local ds = pw.display:all() @@ -98,8 +100,9 @@ end local t = pw.timer.new() -while w:update() -do +w.visible = true + +while w:update() do -- somehow works if (pw.input.get().input_string == 'f') then w.fullscreen = not w.fullscreen @@ -109,7 +112,7 @@ do if (pw.input:get().mouse_button == 1) then print("elapsed",t.elapsed) t:reset() - print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y) + print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y,w.client_size.width,w.client_size.height) end -- print("update") diff --git a/src/system/include/pw/system/input.hpp b/src/system/include/pw/system/input.hpp index 337f1b4..6eeddcc 100644 --- a/src/system/include/pw/system/input.hpp +++ b/src/system/include/pw/system/input.hpp @@ -40,6 +40,9 @@ private: int _mouse_button; bool _mouse_pressed; + int _key_code; + bool _key_pressed; + std::string _input_string; diff --git a/src/system/include/pw/system/window.hpp b/src/system/include/pw/system/window.hpp index 1c20213..0a9d585 100644 --- a/src/system/include/pw/system/window.hpp +++ b/src/system/include/pw/system/window.hpp @@ -35,6 +35,8 @@ public: void set_on_update(on_update_t f) { _on_update = f; } + bool visible() const; + void set_visible(bool is_visible); protected: on_update_t _on_update; diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index e9fea3e..e8a50d9 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -70,12 +70,15 @@ struct window::impl { static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos) { - input::get()._mouse_position = point(xpos,ypos); + input::get()._mouse_position = pointd(xpos,ypos).cast(); } static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods) { - std::cout << __FUNCTION__ << std::endl; + input::get()._key_code = scancode; + input::get()._key_pressed = action; + // action 0,1,2 +// std::cout << __FUNCTION__ << action << std::endl; } // static void character_callback(GLFWwindow* window, unsigned int codepoint) @@ -167,7 +170,7 @@ struct window::impl { glfwSetWindowUserPointer(_window,this); - glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback); + //glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback); glfwSetKeyCallback(_window, window::impl::key_callback); // glfwSetCharCallback(_window, character_callback); glfwSetCharModsCallback(_window, charmods_callback); @@ -200,13 +203,6 @@ struct window::impl { _parent._on_update(_parent); - - // do other stuff -#if 0 - glClearColor(1,0,0,1); - glClear(GL_COLOR_BUFFER_BIT); -#endif - glfwSwapBuffers(_window); return true; @@ -280,6 +276,14 @@ struct window::impl { bool fullscreen() const { return glfwGetWindowMonitor(_window) != nullptr; } + + void set_visible(bool show) { + (show) ? glfwShowWindow(_window) : glfwHideWindow(_window); + } + + bool visible() const { + return glfwGetWindowAttrib(_window, GLFW_VISIBLE) > 0; + } }; @@ -343,6 +347,15 @@ void window::set_fullscreen(bool use_fullscreen) _impl->set_fullscreen(use_fullscreen); } +bool window::visible() const +{ + return _impl->visible(); +} + +void window::set_visible(bool is_visible) +{ + _impl->set_visible(is_visible); +} diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index 1ba3956..ced54c3 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -42,7 +42,7 @@ struct triangle_renderer glBindVertexArray(vao); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vbo); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); const char* vertex_shader = "#version 400\n" @@ -56,7 +56,7 @@ struct triangle_renderer "#version 400\n" "out vec4 frag_colour;" "void main() {" - " frag_colour = vec4(0.5, 0.0, 0.5, 1.0);" + " frag_colour = vec4(0.1, 0.0, 0.5, 1.0);" "}"; #if 0 GLuint vs = glCreateShader(GL_VERTEX_SHADER); @@ -185,10 +185,13 @@ bool pipeline::impl::create(sizei size) void pipeline::impl::draw() { + glClearColor(0,0,0,1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_msaa); - glClearColor(1,0,0,1); - glClear(GL_COLOR_BUFFER_BIT); + glClearColor(1,1,1,1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); tr.draw(); @@ -225,7 +228,12 @@ void pipeline::impl::draw() GL_COLOR_BUFFER_BIT, // buffer mask GL_LINEAR); // scale filter - debug::d() << _size.width << "x" << _size.height; + + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + + // debug::d() << _size.width << "x" << _size.height; #endif