예제 #1
0
  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);
  }
예제 #2
0
	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,
      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);
  }