void opengl_impl::resize(int w, int h) { gl_viewport(0, 0, w, h); gl_matrix_mode(GL_PROJECTION); gl_load_identity(); gl_ortho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0); gl_matrix_mode(GL_MODELVIEW); gl_load_identity(); }
BOOL setup_hud_matrices(const LLRect& screen_region) { LLVOAvatar* my_avatarp = gAgent.getAvatarObject(); if (my_avatarp && my_avatarp->hasHUDAttachment()) { F32 zoom_level = gAgent.mHUDCurZoom; LLBBox hud_bbox = my_avatarp->getHUDBBox(); // set up transform to keep HUD objects in front of camera glMatrixMode(GL_PROJECTION); F32 hud_depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f); glh::matrix4f proj = gl_ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, hud_depth); proj.element(2,2) = -0.01f; F32 aspect_ratio = LLViewerCamera::getInstance()->getAspect(); glh::matrix4f mat; F32 scale_x = (F32)gViewerWindow->getWindowWidth() / (F32)screen_region.getWidth(); F32 scale_y = (F32)gViewerWindow->getWindowHeight() / (F32)screen_region.getHeight(); mat.set_scale(glh::vec3f(scale_x, scale_y, 1.f)); mat.set_translate( glh::vec3f(clamp_rescale((F32)screen_region.getCenterX(), 0.f, (F32)gViewerWindow->getWindowWidth(), 0.5f * scale_x * aspect_ratio, -0.5f * scale_x * aspect_ratio), clamp_rescale((F32)screen_region.getCenterY(), 0.f, (F32)gViewerWindow->getWindowHeight(), 0.5f * scale_y, -0.5f * scale_y), 0.f)); proj *= mat; glLoadMatrixf(proj.m); glh_set_current_projection(proj); glMatrixMode(GL_MODELVIEW); glh::matrix4f model((GLfloat*) OGL_TO_CFR_ROTATION); mat.set_scale(glh::vec3f(zoom_level, zoom_level, zoom_level)); mat.set_translate(glh::vec3f(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f)); model *= mat; glLoadMatrixf(model.m); glh_set_current_modelview(model); return TRUE; } else { return FALSE; } }
bool get_hud_matrices(const LLRect& screen_region, glh::matrix4f &proj, glh::matrix4f &model) { if (isAgentAvatarValid() && gAgentAvatarp->hasHUDAttachment()) { F32 zoom_level = gAgentCamera.mHUDCurZoom; LLBBox hud_bbox = gAgentAvatarp->getHUDBBox(); F32 hud_depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f); proj = gl_ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, hud_depth); proj.element(2,2) = -0.01f; F32 aspect_ratio = LLViewerCamera::getInstance()->getAspect(); glh::matrix4f mat; F32 scale_x = (F32)gViewerWindow->getWorldViewWidthScaled() / (F32)screen_region.getWidth(); F32 scale_y = (F32)gViewerWindow->getWorldViewHeightScaled() / (F32)screen_region.getHeight(); mat.set_scale(glh::vec3f(scale_x, scale_y, 1.f)); mat.set_translate( glh::vec3f(clamp_rescale((F32)(screen_region.getCenterX() - screen_region.mLeft), 0.f, (F32)gViewerWindow->getWorldViewWidthScaled(), 0.5f * scale_x * aspect_ratio, -0.5f * scale_x * aspect_ratio), clamp_rescale((F32)(screen_region.getCenterY() - screen_region.mBottom), 0.f, (F32)gViewerWindow->getWorldViewHeightScaled(), 0.5f * scale_y, -0.5f * scale_y), 0.f)); proj *= mat; glh::matrix4f tmp_model((GLfloat*) OGL_TO_CFR_ROTATION); mat.set_scale(glh::vec3f(zoom_level, zoom_level, zoom_level)); mat.set_translate(glh::vec3f(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f)); tmp_model *= mat; model = tmp_model; return TRUE; } else { return FALSE; } }
void CamaraLucida::render() { if (!inited()) return; if (mesh->is_render_enabled()) { fbo.bind(); //ofEnableAlphaBlending(); //glEnable(GL_BLEND); //glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA); ofNotifyEvent( render_texture, void_event_args ); fbo.unbind(); //ofDisableAlphaBlending(); //glDisable(GL_BLEND); } glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT, GL_FILL); // TODO wireframe it's not working with fbo textures.. why? // @see cmlMesh.enable_render(); // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor3f(1, 1, 1); glViewport(0, 0, ofGetWidth(), ofGetHeight()); gl_ortho(); ofNotifyEvent( render_hud, void_event_args ); render_screenlog(); gl_projection(); gl_viewpoint(); gl_scene_control(); if (_debug) { render_world_CS(); render_proj_CS(); render_rgb_CS(); render_proj_ppal_point(); } // if (using_opencl) // opencl.finish(); // TODO alpha blending! //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE); //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //glBlendFuncSeparate(GL_ONE, GL_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //ofEnableAlphaBlending(); if (mesh->is_render_enabled()) { fbo.getTextureReference(0).bind(); mesh->render(); fbo.getTextureReference(0).unbind(); } //glDisable(GL_BLEND); //ofDisableAlphaBlending(); }
void Renderer::render( cml::Events *ev, Mesh *mesh, bool wireframe ) { // texture fbo.bind(); //ofEnableAlphaBlending(); //glEnable(GL_BLEND); //glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA); ofNotifyEvent(ev->render_texture, ev->void_args); fbo.unbind(); //ofDisableAlphaBlending(); //glDisable(GL_BLEND); // gl init glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 3d glEnable( GL_DEPTH_TEST ); glViewport( 0,0,ofGetWidth(),ofGetHeight() ); glPushAttrib( GL_POLYGON_BIT ); if ( wireframe ) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode( GL_FRONT, GL_FILL ); glColor3f(1, 1, 1); gl_projection(); gl_viewpoint(); gl_scene_control(); if ( _debug ) { render_depth_CS(); render_proj_CS(); render_rgb_CS(); render_proj_ppal_point(); } //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE); //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //glBlendFuncSeparate(GL_ONE, GL_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //ofEnableAlphaBlending(); //shader.begin(); fbo.getTextureReference(0).bind(); //shader.setUniform1i("render_tex", 0); //shader.setUniformTexture("normals_tex", mesh->get_normals_tex_ref(), 1); mesh->render(); //ofNotifyEvent(ev->render_mesh, ev->void_args); fbo.getTextureReference(0).unbind(); //shader.end(); //glDisable(GL_BLEND); //ofDisableAlphaBlending(); ofNotifyEvent(ev->render_3d, ev->void_args); // 2d hud glPopAttrib();//GL_POLYGON_BIT //glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); glPolygonMode( GL_FRONT, GL_FILL ); glColor3f(1, 1, 1); gl_ortho(); ofNotifyEvent(ev->render_2d, ev->void_args); }
void Renderer::render( cml::Events *ev, Mesh *mesh, ofTexture& depth_ftex, bool gpu, bool wireframe ) { // texture fbo.bind(); //ofEnableAlphaBlending(); //glEnable(GL_BLEND); //glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA); ofNotifyEvent(ev->render_texture, ev->void_args); fbo.unbind(); //ofDisableAlphaBlending(); //glDisable(GL_BLEND); // gl init glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 3d glEnable( GL_DEPTH_TEST ); glViewport(0,0,ofGetWidth(),ofGetHeight()); glPushAttrib( GL_POLYGON_BIT ); if ( wireframe ) glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); else glPolygonMode( GL_FRONT, GL_FILL ); glColor3f(1, 1, 1); gl_projection(); gl_viewpoint(); gl_scene_control(); if ( _debug ) { render_depth_CS(); render_proj_CS(); render_rgb_CS(); render_proj_ppal_point(); } //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE); //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //glBlendFuncSeparate(GL_ONE, GL_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //ofEnableAlphaBlending(); ofTexture render_tex = fbo .getTextureReference(0); if ( gpu ) { shader.begin(); /* shader depth calib */ OpticalDevice::Config cfg = depth->config(); ofVec4f k = ((cml::DepthCamera*)depth)->k(); shader.setUniform1f("width", cfg.width); shader.setUniform1f("height", cfg.height); shader.setUniform1f("near", cfg.near); shader.setUniform1f("far", cfg.far); shader.setUniform1f("cx", cfg.cx); shader.setUniform1f("cy", cfg.cy); shader.setUniform1f("fx", cfg.fx); shader.setUniform1f("fy", cfg.fy); shader.setUniform1f("k1", k[0]); shader.setUniform1f("k2", k[1]); shader.setUniform1f("k3", k[2]); shader.setUniform1f("k4", k[3]); /* shader depth calib */ render_tex.bind(); shader.setUniformTexture( "render_tex", render_tex, 0 ); shader.setUniformTexture( "depth_tex", depth_ftex, 1 ); mesh->render(); render_tex.unbind(); shader.end(); } //end of gpu else { render_tex.bind(); mesh->render(); render_tex.unbind(); } //end of cpu //glDisable(GL_BLEND); //ofDisableAlphaBlending(); ofNotifyEvent(ev->render_3d, ev->void_args); // 2d hud glPopAttrib();//GL_POLYGON_BIT //glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); glPolygonMode( GL_FRONT, GL_FILL ); glColor3f(1, 1, 1); gl_ortho(); ofNotifyEvent(ev->render_2d, ev->void_args); }