further cleanup
This commit is contained in:
parent
075d18b4b8
commit
05dea19436
8 changed files with 54 additions and 25 deletions
|
@ -38,7 +38,7 @@ struct rect_ {
|
||||||
|
|
||||||
rect_(point_<T_> const & p,size_<T_> const & s) : size(s), position(p) {}
|
rect_(point_<T_> const & p,size_<T_> const & s) : size(s), position(p) {}
|
||||||
|
|
||||||
bool contains(const point_<T_>& p)
|
bool contains(const point_<T_>& p) const
|
||||||
{
|
{
|
||||||
return p.x >= position.x && p.x <= position.x + size.width &&
|
return p.x >= position.x && p.x <= position.x + size.width &&
|
||||||
p.y >= position.y && p.y <= position.y + size.height;
|
p.y >= position.y && p.y <= position.y + size.height;
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
static timer global_timer;
|
|
||||||
|
|
||||||
timer::timer()
|
timer::timer()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
|
@ -48,6 +46,7 @@ double timer::elapsed() const
|
||||||
|
|
||||||
double timer::now()
|
double timer::now()
|
||||||
{
|
{
|
||||||
|
static timer global_timer;
|
||||||
return global_timer.elapsed();
|
return global_timer.elapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,8 @@ void script_system::load(sol::table &ns)
|
||||||
"size",sol::property(&window::size,&window::set_size),
|
"size",sol::property(&window::size,&window::set_size),
|
||||||
"client_size",sol::readonly_property(&window::client_size),
|
"client_size",sol::readonly_property(&window::client_size),
|
||||||
"position",sol::property(&window::position,&window::set_position),
|
"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)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,7 @@ end
|
||||||
--n_1:add_child()
|
--n_1:add_child()
|
||||||
|
|
||||||
local w = pw.window.new()
|
local w = pw.window.new()
|
||||||
|
w.visible = false
|
||||||
|
|
||||||
-- set title
|
-- set title
|
||||||
w.title = "pixwerx 0.1"
|
w.title = "pixwerx 0.1"
|
||||||
|
@ -75,6 +76,8 @@ w.size = pw.size.new(800,600)
|
||||||
-- move window
|
-- move window
|
||||||
w.position = pw.point.new(100,100)
|
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()
|
local pl = pw.pipeline.new()
|
||||||
if pl:create(w.client_size) then
|
if pl:create(w.client_size) then
|
||||||
|
@ -83,12 +86,11 @@ else
|
||||||
print("pipeline failed")
|
print("pipeline failed")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- setup a lua callback function as callback
|
||||||
-- setup a lua callback function
|
|
||||||
w.on_update = function(self)
|
w.on_update = function(self)
|
||||||
|
|
||||||
pl:draw()
|
pl:draw()
|
||||||
-- print("test on update",w.position.x,w.position.y,pw.timer.now)
|
-- print("test on update",w.position.x,w.position.y,pw.timer.now)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local ds = pw.display:all()
|
local ds = pw.display:all()
|
||||||
|
@ -98,8 +100,9 @@ end
|
||||||
|
|
||||||
local t = pw.timer.new()
|
local t = pw.timer.new()
|
||||||
|
|
||||||
while w:update()
|
w.visible = true
|
||||||
do
|
|
||||||
|
while w:update() do
|
||||||
-- somehow works
|
-- somehow works
|
||||||
if (pw.input.get().input_string == 'f') then
|
if (pw.input.get().input_string == 'f') then
|
||||||
w.fullscreen = not w.fullscreen
|
w.fullscreen = not w.fullscreen
|
||||||
|
@ -109,7 +112,7 @@ do
|
||||||
if (pw.input:get().mouse_button == 1) then
|
if (pw.input:get().mouse_button == 1) then
|
||||||
print("elapsed",t.elapsed)
|
print("elapsed",t.elapsed)
|
||||||
t:reset()
|
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
|
end
|
||||||
|
|
||||||
-- print("update")
|
-- print("update")
|
||||||
|
|
|
@ -40,6 +40,9 @@ private:
|
||||||
int _mouse_button;
|
int _mouse_button;
|
||||||
bool _mouse_pressed;
|
bool _mouse_pressed;
|
||||||
|
|
||||||
|
int _key_code;
|
||||||
|
bool _key_pressed;
|
||||||
|
|
||||||
std::string _input_string;
|
std::string _input_string;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ public:
|
||||||
|
|
||||||
void set_on_update(on_update_t f) { _on_update = f; }
|
void set_on_update(on_update_t f) { _on_update = f; }
|
||||||
|
|
||||||
|
bool visible() const;
|
||||||
|
void set_visible(bool is_visible);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
on_update_t _on_update;
|
on_update_t _on_update;
|
||||||
|
|
|
@ -70,12 +70,15 @@ struct window::impl {
|
||||||
|
|
||||||
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
|
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<float>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
|
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)
|
// static void character_callback(GLFWwindow* window, unsigned int codepoint)
|
||||||
|
@ -167,7 +170,7 @@ struct window::impl {
|
||||||
|
|
||||||
glfwSetWindowUserPointer(_window,this);
|
glfwSetWindowUserPointer(_window,this);
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
|
//glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
|
||||||
glfwSetKeyCallback(_window, window::impl::key_callback);
|
glfwSetKeyCallback(_window, window::impl::key_callback);
|
||||||
// glfwSetCharCallback(_window, character_callback);
|
// glfwSetCharCallback(_window, character_callback);
|
||||||
glfwSetCharModsCallback(_window, charmods_callback);
|
glfwSetCharModsCallback(_window, charmods_callback);
|
||||||
|
@ -200,13 +203,6 @@ struct window::impl {
|
||||||
|
|
||||||
_parent._on_update(_parent);
|
_parent._on_update(_parent);
|
||||||
|
|
||||||
|
|
||||||
// do other stuff
|
|
||||||
#if 0
|
|
||||||
glClearColor(1,0,0,1);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
glfwSwapBuffers(_window);
|
glfwSwapBuffers(_window);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -280,6 +276,14 @@ struct window::impl {
|
||||||
bool fullscreen() const {
|
bool fullscreen() const {
|
||||||
return glfwGetWindowMonitor(_window) != nullptr;
|
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);
|
_impl->set_fullscreen(use_fullscreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool window::visible() const
|
||||||
|
{
|
||||||
|
return _impl->visible();
|
||||||
|
}
|
||||||
|
|
||||||
|
void window::set_visible(bool is_visible)
|
||||||
|
{
|
||||||
|
_impl->set_visible(is_visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct triangle_renderer
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
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 =
|
const char* vertex_shader =
|
||||||
"#version 400\n"
|
"#version 400\n"
|
||||||
|
@ -56,7 +56,7 @@ struct triangle_renderer
|
||||||
"#version 400\n"
|
"#version 400\n"
|
||||||
"out vec4 frag_colour;"
|
"out vec4 frag_colour;"
|
||||||
"void main() {"
|
"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
|
#if 0
|
||||||
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
|
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
@ -185,10 +185,13 @@ bool pipeline::impl::create(sizei size)
|
||||||
void pipeline::impl::draw()
|
void pipeline::impl::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
glClearColor(0,0,0,1);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_msaa);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_msaa);
|
||||||
|
|
||||||
glClearColor(1,0,0,1);
|
glClearColor(1,1,1,1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
tr.draw();
|
tr.draw();
|
||||||
|
|
||||||
|
@ -225,7 +228,12 @@ void pipeline::impl::draw()
|
||||||
GL_COLOR_BUFFER_BIT, // buffer mask
|
GL_COLOR_BUFFER_BIT, // buffer mask
|
||||||
GL_LINEAR); // scale filter
|
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
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue