1
Fork 0

Draw base after us

This commit is contained in:
Joshua Moerman 2013-04-23 17:31:45 +02:00
parent 666197087e
commit a236d2c1fc
5 changed files with 42 additions and 15 deletions

View file

@ -58,8 +58,6 @@ void Base::draw(){
try { try {
fbo.unbind(); fbo.unbind();
moggle::gl::set_viewport(0, 0, window_width, window_height); 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_DEPTH_TEST);
moggle::gl::enable(GL_BLEND); moggle::gl::enable(GL_BLEND);
moggle::gl::blend_function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); moggle::gl::blend_function(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View file

@ -83,6 +83,10 @@ void draw_square(GameRenderer::Shader & shader, std::shared_ptr<motor::Fbo> read
} }
void GameRenderer::draw(Client const & client){ 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_DEPTH_TEST);
gl::disable(GL_CULL_FACE); gl::disable(GL_CULL_FACE);
@ -91,6 +95,7 @@ void GameRenderer::draw(Client const & client){
std::swap(fbo1, fbo2); std::swap(fbo1, fbo2);
fbo1->bind(); fbo1->bind();
fbo1->set_viewport();
{ {
awe_shader.s.use(); awe_shader.s.use();
awe_shader.s.uniform<GLfloat>("time").set(client.time); awe_shader.s.uniform<GLfloat>("time").set(client.time);
@ -145,6 +150,7 @@ void GameRenderer::draw(Client const & client){
} }
} }
if(lines.size() > 0){
gl::enable_vertex_attribute_array(line_shader.attribute_location("position")); 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::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::enable_vertex_attribute_array(line_shader.attribute_location("color"));
@ -152,6 +158,7 @@ void GameRenderer::draw(Client const & client){
gl::draw_arrays(GL_LINES, 0, lines.size()); gl::draw_arrays(GL_LINES, 0, lines.size());
} }
}
if(!client.sim.balls.empty()){ if(!client.sim.balls.empty()){
gl::blend_function(GL_ONE, GL_ONE); gl::blend_function(GL_ONE, GL_ONE);
@ -180,6 +187,7 @@ void GameRenderer::draw(Client const & client){
gl::draw_arrays(GL_TRIANGLE_STRIP, 0, balls.size() * 6); gl::draw_arrays(GL_TRIANGLE_STRIP, 0, balls.size() * 6);
} }
fbo1->unbind(); fbo1->unbind();
moggle::gl::set_viewport(0, 0, client.window_width, client.window_height);
draw_square(flat_shader, fbo1); draw_square(flat_shader, fbo1);
} }

View file

@ -167,8 +167,10 @@ namespace games {
alListenerfv(AL_ORIENTATION, atup); alListenerfv(AL_ORIENTATION, atup);
// simulation // simulation
sim.bounds.xmax = window_width_; sim.bounds.xmin = -20;
sim.bounds.ymax = window_height_; 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::kQuarterNote, note_info{x1, 10.0f});
beat.notes.emplace_back(note_type::kWholeNote, note_info{x2, 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<motor::DirectionalLight>(p)); scene->add(std::make_shared<motor::DirectionalLight>(p));
} }
world.physics.set_gravity({0.0, 0.0, 0.0}); try {
// peeps_lbl = std::make_shared<motor::TextureLabel>("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); scene->camera.set_perspective(80.0f, 4.0f/3.0f, .5f, 50.0f);
} }
@ -285,8 +294,13 @@ namespace games {
} }
void Client::draw(){ void Client::draw(){
Base::draw();
game_renderer.draw(*this); 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){ void Client::update(float const dt, Input input){

View file

@ -98,6 +98,9 @@ namespace games {
// Graphics // Graphics
GameRenderer game_renderer; GameRenderer game_renderer;
std::shared_ptr<motor::TextureLabel> peeps_lbl;
void update_peeps(std::string peeps);
// Base part // Base part
Client(int window_width, int window_height, std::shared_ptr<Base>& active_base); Client(int window_width, int window_height, std::shared_ptr<Base>& active_base);

View file

@ -18,8 +18,12 @@ int main(int argc, char** argv){
const int window_width = atoi(argv[1]); const int window_width = atoi(argv[1]);
const int window_height = atoi(argv[2]); const int window_height = atoi(argv[2]);
try {
GenericMain<Game> m(fullscreen, window_width, window_height); GenericMain<Game> m(fullscreen, window_width, window_height);
m.main(); m.main();
} catch (std::exception & e) {
CERR << e.what() << std::endl;
}
return 0; return 0;
} }