From d399c201eb5190515a5f4cc363059bc9f94f06c5 Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Tue, 23 Apr 2013 17:51:51 +0200 Subject: [PATCH] Using HUD from motor to show the people online --- src/client/GameRenderer.cpp | 2 ++ src/client/client.cpp | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/client/GameRenderer.cpp b/src/client/GameRenderer.cpp index d66a805..1b577fe 100644 --- a/src/client/GameRenderer.cpp +++ b/src/client/GameRenderer.cpp @@ -89,6 +89,8 @@ void GameRenderer::draw(Client const & client){ moggle::gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl::disable(GL_DEPTH_TEST); gl::disable(GL_CULL_FACE); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, 0); auto projectionMatrix = projection_matrices::orthographic(client.sim.bounds.xmin, client.sim.bounds.xmax, client.sim.bounds.ymax, client.sim.bounds.ymin, -100.0f, 100.0f); auto modelViewProjectionMatrix = projectionMatrix; diff --git a/src/client/client.cpp b/src/client/client.cpp index 4564df1..c6aa35b 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -36,6 +36,9 @@ namespace games { auto l = from_json(js); current_client->add_line(l); } + } else if (command == "peeps"){ + auto str = from_json(object["data"]); + current_client->update_peeps(str); } } catch(std::exception& e){ throw websockets::runtime_error(e.what()); @@ -194,21 +197,9 @@ namespace games { if(!wsi) throw std::runtime_error("socket could not be created."); // motor - { - motor::DirectionalLight p{motor::Position{0, 0, 20}, 1.0f, motor::Color{1, 1, 1, 1}}; - scene->add(std::make_shared(p)); - } - - try { - // peeps_lbl = std::make_shared("Peeps:", motor::bundle.get_font_path() + "VeraMoBd.ttf", 72); - // peeps_lbl->get_mesh()->material->diffuse_color = {1.0f, 1.0f, 1.0f, 1.0f}; - // scene->add(peeps_lbl); - } catch (std::exception & e) { - CERR << e.what() << std::endl; - } - world.physics.set_gravity({0.0, 0.0, 0.0}); - scene->camera.set_perspective(80.0f, 4.0f/3.0f, .5f, 50.0f); + hud->camera.set_orthographic(-100, 100, -100, 100, 1, -1); + update_peeps(""); } void Client::handle_input(float dt, Input input){ @@ -277,7 +268,7 @@ namespace games { } if(input.keys_went_down[SDLK_s]){ - scene->update_shader_pipeline(); + hud->update_shader_pipeline(); game_renderer.load_shaders(); } @@ -299,7 +290,18 @@ namespace games { } void Client::update_peeps(std::string peeps){ - assert(peeps_lbl); + if(!peeps_lbl){ + try { + peeps_lbl = std::make_shared("Peeps:", motor::bundle.get_font_path() + "VeraMoBd.ttf", 72); + peeps_lbl->get_mesh()->material->diffuse_color = {1.0f, 1.0f, 1.0f, 1.0f}; + peeps_lbl->set_position({-95.0, -90.0, 0.0}); + peeps_lbl->set_scale(motor::scale(0.05)); + peeps_lbl->set_rotation(motor::lookat_rotation({0, 0, -1}, {0, 1, 0})); + hud->add(peeps_lbl); + } catch (std::exception & e) { + CERR << e.what() << std::endl; + } + } peeps_lbl->set_text("Peeps: " + peeps); } @@ -308,8 +310,6 @@ namespace games { Base::update(dt, input); handle_input(dt, input); - scene->camera.set_position({0, 0, 20}); - float dt2 = dt; if(dt2 > 1.0/70.0 && dt2 < 1.0/55.0) dt2 = 1.0/60.0; if(pause) dt2 = 0.0;