From a236d2c1fc7418d274d3fb58092a5736fb46b481 Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Tue, 23 Apr 2013 17:31:45 +0200 Subject: [PATCH] Draw base after us --- src/Base.cpp | 2 -- src/client/GameRenderer.cpp | 22 +++++++++++++++------- src/client/client.cpp | 22 ++++++++++++++++++---- src/client/client.hpp | 3 +++ src/client_main.cpp | 8 ++++++-- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/Base.cpp b/src/Base.cpp index 20fcd9c..40d9d98 100644 --- a/src/Base.cpp +++ b/src/Base.cpp @@ -58,8 +58,6 @@ void Base::draw(){ try { fbo.unbind(); moggle::gl::set_viewport(0, 0, window_width, window_height); - moggle::gl::set_clear_color(0.0f, 0.0f, 0.0f, 0.0f); - moggle::gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); moggle::gl::enable(GL_DEPTH_TEST); moggle::gl::enable(GL_BLEND); moggle::gl::blend_function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/client/GameRenderer.cpp b/src/client/GameRenderer.cpp index 6941a5d..d66a805 100644 --- a/src/client/GameRenderer.cpp +++ b/src/client/GameRenderer.cpp @@ -83,6 +83,10 @@ void draw_square(GameRenderer::Shader & shader, std::shared_ptr read } void GameRenderer::draw(Client const & client){ + fbo1->unbind(); + moggle::gl::set_viewport(0, 0, client.window_width, client.window_height); + moggle::gl::set_clear_color(0.0f, 0.0f, 0.0f, 0.0f); + moggle::gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl::disable(GL_DEPTH_TEST); gl::disable(GL_CULL_FACE); @@ -91,6 +95,7 @@ void GameRenderer::draw(Client const & client){ std::swap(fbo1, fbo2); fbo1->bind(); + fbo1->set_viewport(); { awe_shader.s.use(); awe_shader.s.uniform("time").set(client.time); @@ -144,13 +149,15 @@ void GameRenderer::draw(Client const & client){ lines.push_back({l.end_point, color}); } } - - gl::enable_vertex_attribute_array(line_shader.attribute_location("position")); - gl::vertex_attribute_pointer(line_shader.attribute_location("position"), 2, GL_FLOAT, GL_FALSE, sizeof(LineVertex), &lines[0]); - gl::enable_vertex_attribute_array(line_shader.attribute_location("color")); - gl::vertex_attribute_pointer(line_shader.attribute_location("color"), 3, GL_FLOAT, GL_FALSE, sizeof(LineVertex), &lines[0].color); - - gl::draw_arrays(GL_LINES, 0, lines.size()); + + if(lines.size() > 0){ + gl::enable_vertex_attribute_array(line_shader.attribute_location("position")); + gl::vertex_attribute_pointer(line_shader.attribute_location("position"), 2, GL_FLOAT, GL_FALSE, sizeof(LineVertex), &lines[0]); + gl::enable_vertex_attribute_array(line_shader.attribute_location("color")); + gl::vertex_attribute_pointer(line_shader.attribute_location("color"), 3, GL_FLOAT, GL_FALSE, sizeof(LineVertex), &lines[0].color); + + gl::draw_arrays(GL_LINES, 0, lines.size()); + } } if(!client.sim.balls.empty()){ @@ -180,6 +187,7 @@ void GameRenderer::draw(Client const & client){ gl::draw_arrays(GL_TRIANGLE_STRIP, 0, balls.size() * 6); } fbo1->unbind(); + moggle::gl::set_viewport(0, 0, client.window_width, client.window_height); draw_square(flat_shader, fbo1); } diff --git a/src/client/client.cpp b/src/client/client.cpp index 0ca4b6c..4564df1 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -167,8 +167,10 @@ namespace games { alListenerfv(AL_ORIENTATION, atup); // simulation - sim.bounds.xmax = window_width_; - sim.bounds.ymax = window_height_; + sim.bounds.xmin = -20; + sim.bounds.ymin = -20; + sim.bounds.xmax = window_width_ + 20; + sim.bounds.ymax = window_height_ + 20; beat.notes.emplace_back(note_type::kQuarterNote, note_info{x1, 10.0f}); beat.notes.emplace_back(note_type::kWholeNote, note_info{x2, 10.0f}); @@ -197,8 +199,15 @@ namespace games { scene->add(std::make_shared(p)); } - world.physics.set_gravity({0.0, 0.0, 0.0}); + 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); } @@ -285,8 +294,13 @@ namespace games { } void Client::draw(){ - Base::draw(); game_renderer.draw(*this); + Base::draw(); + } + + void Client::update_peeps(std::string peeps){ + assert(peeps_lbl); + peeps_lbl->set_text("Peeps: " + peeps); } void Client::update(float const dt, Input input){ diff --git a/src/client/client.hpp b/src/client/client.hpp index 7499c6f..0f261af 100644 --- a/src/client/client.hpp +++ b/src/client/client.hpp @@ -98,6 +98,9 @@ namespace games { // Graphics GameRenderer game_renderer; + std::shared_ptr peeps_lbl; + + void update_peeps(std::string peeps); // Base part Client(int window_width, int window_height, std::shared_ptr& active_base); diff --git a/src/client_main.cpp b/src/client_main.cpp index 9840b81..f48cef2 100644 --- a/src/client_main.cpp +++ b/src/client_main.cpp @@ -18,8 +18,12 @@ int main(int argc, char** argv){ const int window_width = atoi(argv[1]); const int window_height = atoi(argv[2]); - GenericMain m(fullscreen, window_width, window_height); - m.main(); + try { + GenericMain m(fullscreen, window_width, window_height); + m.main(); + } catch (std::exception & e) { + CERR << e.what() << std::endl; + } return 0; }