void Game::renderPass(uint64_t frame) { const Rect cameraRect(mCameraPosition - (mScreenSize / 2), mScreenSize); Renderables renderables = Renderable::all(); for (Renderables::iterator iter = renderables.begin(); iter != renderables.end(); ++iter) { Renderable& object = **iter; Rect boundingRect = object.boundingRect(); if (!object.hidden() && cameraRect.overlaps(boundingRect)) { // Motion blur Color::push(); int max = 1; Color::translate(Color(1.0, 1.0, 1.0, 1.0 / max)); for (int i = 0; i < max; ++i) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); object.render(frame - i); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } Color::pop(); } } }
void Game::update() { Renderables renderables = Renderable::all(); for (Renderables::iterator iter = renderables.begin(); iter != renderables.end(); ++iter) { (*iter)->update(); } }
void Game::render() { glPushMatrix(); // Camera. glTranslatef(-(mCameraPosition.x - (mScreenSize.width / 2)), -(mCameraPosition.y - (mScreenSize.height / 2)), 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); renderPass(frames); if (drawBoundingBoxes) { Renderables rs = Renderable::all(); for (Renderables::const_iterator iter = rs.begin(); iter != rs.end(); ++iter) { Rect boundingRect = (*iter)->boundingRect(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(boundingRect.origin.x, boundingRect.origin.y, 0.0); glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); glBegin(GL_LINE_LOOP); { glLineWidth(1.0); Color(1.0, 1.0, 1.0, 0.5).set(); glVertex2f(0.0, 0.0); glVertex2f(boundingRect.size.width, 0.0); glVertex2f(boundingRect.size.width, boundingRect.size.height); glVertex2f(0.0, boundingRect.size.height); } glEnd(); glPopMatrix(); } } glPopMatrix(); // TODO: Draw widgets here instead of compensating for the translation in the widget drawing code. // ^ would also ensure that widgets are always on top of content. SDL_GL_SwapBuffers(); }
const_iterator begin() const { return m_children.begin(); }