diff --git a/modules/gfx/pymod/export_scene.cc b/modules/gfx/pymod/export_scene.cc index 23ff9d687b497960588b169884690ff6a071243e..9f3042cb2d7328097691db1d338744d680d0946c 100644 --- a/modules/gfx/pymod/export_scene.cc +++ b/modules/gfx/pymod/export_scene.cc @@ -240,5 +240,7 @@ void export_Scene() .def("GetBoundingBox",scene_get_bb2) .def("GetBoundingBox",scene_get_bb3) .add_property("bounding_box",scene_get_bb1) + .add_property("export_aspect",&Scene::GetExportAspect,&Scene::SetExportAspect) + .add_property("show_export_aspect",&Scene::GetShowExportAspect,&Scene::SetShowExportAspect) ; } diff --git a/modules/gfx/src/scene.cc b/modules/gfx/src/scene.cc index 9212d8eab37f015b5019c25438efe75d162fb268..e4d37b841160760a1c130f832f0b9828abc03daa 100644 --- a/modules/gfx/src/scene.cc +++ b/modules/gfx/src/scene.cc @@ -140,7 +140,9 @@ Scene::Scene(): update_bg_(false), bg_grad_(), bg_bm_(), - bg_tex_() + bg_tex_(), + export_aspect_(1.0), + show_export_aspect_(false) { transform_.SetTrans(Vec3(0,0,-100)); } @@ -1988,6 +1990,73 @@ void Scene::prep_blur() glFlush(); } +namespace { + class ViewportRenderer { + unsigned int vp_width_,vp_height_; + public: + ViewportRenderer(unsigned int vpw, unsigned int vph): + vp_width_(vpw), vp_height_(vph) + { +#if OST_SHADER_SUPPORT_ENABLED + Shader::Instance().PushProgram(); + Shader::Instance().Activate(""); +#endif + glPushAttrib(GL_ALL_ATTRIB_BITS); + glPushClientAttrib(GL_ALL_ATTRIB_BITS); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_COLOR_MATERIAL); + glDisable(GL_FOG); + glDisable(GL_CULL_FACE); + glDisable(GL_BLEND); + glDisable(GL_LINE_SMOOTH); + glDisable(GL_POINT_SMOOTH); +#if defined(OST_GL_VERSION_2_0) + glDisable(GL_MULTISAMPLE); +#endif + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0,vp_width_,0,vp_height_,-1,1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + } + + void DrawTex(GLuint tex_id) { + glEnable(GL_TEXTURE_2D); +#if OST_SHADER_SUPPORT_ENABLED + if(OST_GL_VERSION_2_0) { + glActiveTexture(GL_TEXTURE0); + } +#endif + glBindTexture(GL_TEXTURE_2D, tex_id); + glColor3f(0.0,0.0,0.0); + glBegin(GL_QUADS); + glTexCoord2f(0.0,0.0); glVertex2i(0,0); + glTexCoord2f(0.0,1.0); glVertex2i(0,vp_height_); + glTexCoord2f(1.0,1.0); glVertex2i(vp_width_,vp_height_); + glTexCoord2f(1.0,0.0); glVertex2i(vp_width_,0); + glEnd(); + } + + ~ViewportRenderer() { + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glPopClientAttrib(); + glPopAttrib(); +#if OST_SHADER_SUPPORT_ENABLED + Shader::Instance().PopProgram(); +#endif + } + }; +} + void Scene::render_bg() { if(!gl_init_) return; @@ -1998,65 +2067,62 @@ void Scene::render_bg() update_bg_=false; } - // setup state for simple texture quad -#if OST_SHADER_SUPPORT_ENABLED - Shader::Instance().PushProgram(); - Shader::Instance().Activate(""); -#endif - glPushAttrib(GL_ALL_ATTRIB_BITS); - glPushClientAttrib(GL_ALL_ATTRIB_BITS); - - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); - glDisable(GL_FOG); - glDisable(GL_CULL_FACE); - glDisable(GL_BLEND); - glDisable(GL_LINE_SMOOTH); - glDisable(GL_POINT_SMOOTH); -#if defined(OST_GL_VERSION_2_0) - glDisable(GL_MULTISAMPLE); -#endif - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0,vp_width_,0,vp_height_,-1,1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - // draw bg texture quad - glEnable(GL_TEXTURE_2D); -#if OST_SHADER_SUPPORT_ENABLED - if(OST_GL_VERSION_2_0) { - glActiveTexture(GL_TEXTURE0); + { + ViewportRenderer vpr(vp_width_,vp_height_); + vpr.DrawTex(bg_tex_); + // dtor takes care of the rest } -#endif - glBindTexture(GL_TEXTURE_2D, bg_tex_); - // draw - glColor3f(0.0,0.0,0.0); - glBegin(GL_QUADS); - glTexCoord2f(0.0,0.0); glVertex2i(0,0); - glTexCoord2f(0.0,1.0); glVertex2i(0,vp_height_); - glTexCoord2f(1.0,1.0); glVertex2i(vp_width_,vp_height_); - glTexCoord2f(1.0,0.0); glVertex2i(vp_width_,0); - glEnd(); - // restore all settings - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glPopClientAttrib(); - glPopAttrib(); -#if OST_SHADER_SUPPORT_ENABLED - Shader::Instance().PopProgram(); -#endif check_gl_error("render_bg()"); } +void Scene::render_export_aspect() +{ + unsigned int a_width=static_cast<int>(static_cast<float>(vp_height_)*export_aspect_); + if(a_width<vp_width_) { + // need to draw horizontal boundaries + unsigned int o1=(vp_width_-a_width)>>1; + unsigned int o2=a_width+o1; + ViewportRenderer vpr(vp_width_,vp_height_); + glDisable(GL_DEPTH); + glEnable(GL_BLEND); + glColor4f(0.0,0.0,0.0,0.5); + glBegin(GL_QUADS); + glVertex2i(0,0); + glVertex2i(0,vp_height_); + glVertex2i(o1,vp_height_); + glVertex2i(o1,0); + glVertex2i(o2,0); + glVertex2i(o2,vp_height_); + glVertex2i(vp_width_,vp_height_); + glVertex2i(vp_width_,0); + glEnd(); + // vpr dtor does gl cleanup + } else if(a_width>vp_width_) { + unsigned int a_height=static_cast<int>(static_cast<float>(vp_width_)/export_aspect_); + // need to draw vertical boundaries + unsigned int o1=(vp_height_-a_height)>>1; + unsigned int o2=a_height+o1; + ViewportRenderer vpr(vp_width_,vp_height_); + glDisable(GL_DEPTH); + glEnable(GL_BLEND); + glColor4f(0.0,0.0,0.0,0.5); + glBegin(GL_QUADS); + glVertex2i(0,0); + glVertex2i(0,o1); + glVertex2i(vp_width_,o1); + glVertex2i(vp_width_,0); + glVertex2i(0,o2); + glVertex2i(0,vp_height_); + glVertex2i(vp_width_,vp_height_); + glVertex2i(vp_width_,o2); + glEnd(); + // vpr dtor does gl cleanup + } + + +} // anon ns + void Scene::render_scene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -2110,6 +2176,8 @@ void Scene::render_scene() #endif render_glow(); + + if(show_export_aspect_) render_export_aspect(); } void Scene::render_glow() @@ -2422,4 +2490,20 @@ void Scene::do_autoslab() RequestRedraw(); } +void Scene::SetExportAspect(float a) +{ + if(a>0.0) { + export_aspect_=a; + if(show_export_aspect_) RequestRedraw(); + } +} + +void Scene::SetShowExportAspect(bool f) +{ + if(f!=show_export_aspect_) { + show_export_aspect_=f; + RequestRedraw(); + } +} + }} // ns diff --git a/modules/gfx/src/scene.hh b/modules/gfx/src/scene.hh index f6f4c87f1544b091d0e51777b7b254501ae4d22b..a8a9afbe1a8170083358694a2be1b06da7724936 100644 --- a/modules/gfx/src/scene.hh +++ b/modules/gfx/src/scene.hh @@ -495,6 +495,11 @@ class DLLEXPORT_OST_GFX Scene { /// experimental feature void SetBeaconOff(); + void SetExportAspect(float a); + float GetExportAspect() const {return export_aspect_;} + void SetShowExportAspect(bool f); + bool GetShowExportAspect() const {return show_export_aspect_;} + protected: friend class GfxObj; friend class GfxNode; @@ -585,7 +590,8 @@ private: Bitmap bg_bm_; unsigned int bg_tex_; - + float export_aspect_; + bool show_export_aspect_; void set_near(float n); void set_far(float f); @@ -595,6 +601,7 @@ private: void prep_blur(); void stereo_projection(int view); void render_bg(); + void render_export_aspect(); void render_scene(); void render_glow(); void render_stereo();