Browse Source

Fixing two bugs:
- glClear ordering caused us to not display anything (not even a black screen)
- obj_to_world being zero caused objects to vanish.

Sam Jaffe 6 years ago
parent
commit
df54e19365
2 changed files with 7 additions and 5 deletions
  1. 2 2
      graphics/src/opengl_renderer.cxx
  2. 5 3
      graphics/src/renderer.cxx

+ 2 - 2
graphics/src/opengl_renderer.cxx

@@ -54,13 +54,13 @@ opengl_renderer::~opengl_renderer() {
 void opengl_renderer::clear() {
   world_to_clip = identity;
 
-  math::vec2i resolution = env::screen_resolution();
+  math::vec2i resolution = env::screen_size();
   world_to_clip = graphics::orthogonal_view(0.f, resolution[0], 0.f,
                                             resolution[1], -1.f, 1.f);
 
   glClearDepth(1.f);
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glClearColor(0.f, 0.f, 0.0f, 1.f);
+  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glEnable(GL_DEPTH_TEST);
 
   current_time = env::clock::current_time<double>();

+ 5 - 3
graphics/src/renderer.cxx

@@ -12,6 +12,7 @@
 #include "game/graphics/object.hpp"
 #include "game/graphics/vertex.h"
 #include "matrix/matrix.hpp"
+#include "matrix/matrix_helpers.hpp"
 #include "renderer_impl.hpp"
 
 using namespace graphics;
@@ -33,9 +34,10 @@ void direct_renderer::draw(object const & obj) {
   draw(obj.material, math::matr4(), verts);
 }
 
-void direct_renderer::draw(flyweight<material> material, math::matr4 const &,
+void direct_renderer::draw(flyweight<material> material,
+                           math::matr4 const & object_to_world,
                            std::vector<vertex> const & verts) {
-  pimpl->draw(material, {}, verts);
+  pimpl->draw(material, object_to_world, verts);
 }
 
 void direct_renderer::clear() { pimpl->clear(); }
@@ -74,7 +76,7 @@ void batch_renderer::check() {
 
 void batch_renderer::write() {
   for (auto & pair : batches_) {
-    impl_->draw(pair.first, math::matr4(), pair.second);
+    impl_->draw(pair.first, math::matrix::identity<float, 4>(), pair.second);
   }
   batches_.clear();
   elements_ = 0;