virtual void initEvent()
  {
    if (!GLEW_ARB_multitexture)
    {
      vl::Log::error("GL_ARB_multitexture required.\n");
      openglContext()->quitApplication();
      return;
    }
    vl::Log::print(appletInfo());

    ghostCameraManipulator()->setMovementSpeed(5);
    // allocate terrain scene manager
    vl::ref<vl::Terrain> terrain = new vl::Terrain;
    // use GLSL?
    terrain->setUseGLSL( GLEW_ARB_shading_language_100 ? true : false );
    // dimensions of the terrain
    terrain->setWidth(100);
    terrain->setDepth(100);
    terrain->setHeight(5.0f);
    // heightmap texture size used by the GLSL program
    if (GLEW_ATI_texture_float || GLEW_ARB_texture_float)
      terrain->setHeightmapTextureFormat(vl::TF_LUMINANCE16F);
    else
      terrain->setHeightmapTextureFormat(vl::TF_LUMINANCE);
    // origin of the terrain
    terrain->setOrigin(vl::vec3(0,0,0));
    // define textures
    terrain->setHeightmapTexture("/images/ps_height_4k.jpg");
    terrain->setTerrainTexture("/images/ps_texture_4k.jpg");
    terrain->setDetailTexture("/images/noise.png");
    terrain->setDetailRepetitionCount(8);
    // define shaders to be used to render the terrain
    terrain->setFragmentShader("/glsl/terrain.fs");
    terrain->setVertexShader("/glsl/terrain.vs");
    // initialize the terrain
    terrain->init();
    // add the terrain scene manager to the rendering
    rendering()->as<vl::Rendering>()->sceneManagers()->push_back( terrain.get() );

    // adds fog if we are not using GLSL but the fixed function pipeline
    if (!terrain->useGLSL())
    {
      // set sky to white
      rendering()->as<vl::Rendering>()->camera()->viewport()->setClearColor(vl::white);
      // set fog render state
      vl::ref<vl::Fog> fog = new vl::Fog;
      fog->setColor(vl::white);
      fog->setDensity(0.045f);
      fog->setMode(vl::FM_EXP);
      // install and enable fog
      terrain->shaderNode()->setRenderState(fog.get());
      terrain->shaderNode()->setEnable(vl::EN_FOG,true);
      terrain->shaderNode()->updateHierarchy();
    }

    // for debugging purposes
    #if 0
      showBoundingVolumes(1,0);
    #endif
  }
  // called once after the OpenGL window has been opened 
  void initEvent()
  {
    // allocate the Transform 
    mCubeTransform = new vl::Transform;
    // bind the Transform with the transform tree of the rendring pipeline 
    rendering()->as<vl::Rendering>()->transform()->addChild( mCubeTransform.get() );

    // create the cube's Geometry and compute its normals to support lighting 
    vl::ref<vl::Geometry> cube = vl::makeBox( vl::vec3(0,0,0), 10, 10, 10 );
    cube->computeNormals();

    // setup the effect to be used to render the cube 
    vl::ref<vl::Effect> effect = new vl::Effect;
    // enable depth test and lighting 
    effect->shader()->enable(vl::EN_DEPTH_TEST);
    // add a Light to the scene, since no Transform is associated to the Light it will follow the camera 
    effect->shader()->setRenderState( new vl::Light, 0 );
    // enable the standard OpenGL lighting 
    effect->shader()->enable(vl::EN_LIGHTING);
    // set the front and back material color of the cube 
    // "gocMaterial" stands for "get-or-create Material"
    effect->shader()->gocMaterial()->setDiffuse( vl::crimson );

    // install our scene manager, we use the SceneManagerActorTree which is the most generic
    vl::ref<vl::SceneManagerActorTree> scene_manager = new vl::SceneManagerActorTree;
    rendering()->as<vl::Rendering>()->sceneManagers()->push_back(scene_manager.get());
    // add the cube to the scene using the previously defined effect and transform 
    scene_manager->tree()->addActor( cube.get(), effect.get(), mCubeTransform.get()  );
  }
  void loadFile(const vl::String& file)
  {
    if (mMode == AnimateMode)
      return;

    mImage = vl::loadImage(file);
    if (!mImage)
      return;
    if (file.endsWith(".dcm"))
      mImage->contrastHounsfieldAuto();

    mTexture->destroyTexture();
    mTexture->prepareTexture2D(mImage.get(), vl::TF_RGBA);

    // perfectly center the texture texels (see GL_CLAMP documentation)
    vl::mat4 m;
    float x_texel = 1.0f/mImage->width();
    float y_texel = 1.0f/mImage->height();
    float x_scale = 1.0f - x_texel;
    float y_scale = 1.0f - y_texel;
    m.scale(x_scale, y_scale, 1.0f);
    m.translate(x_texel/2.0f, y_texel/2.0f, 0.0f);
    mTextureMatrix->setMatrix(m);

    resizeEvent( rendering()->as<vl::Rendering>()->camera()->viewport()->width(), rendering()->as<vl::Rendering>()->camera()->viewport()->height() );
    reset();
  }
  void initEvent()
  {
    vl::Log::notify(appletInfo());

    if(!vl::Has_Occlusion_Query)
    {
      vl::Log::error("No support to hardware occlusion culling found!\n");
      vl::Time::sleep(2000);
      exit(1);
    }

    // #######################################################################
    // # These 4 lines are the only code needed to enable occlusion culling, #
    // # no special sorter or render rank/block setup needed!                #
    // #######################################################################

    // wraps the regular renderer inside the occlusion renderer
    vl::Renderer* regular_renderer = rendering()->as<vl::Rendering>()->renderer();
    // creates our occlusion renderer
    mOcclusionRenderer = new vl::OcclusionCullRenderer;
    mOcclusionRenderer->setWrappedRenderer( regular_renderer );
    // installs the occlusion renderer in place of the regular one
    rendering()->as<vl::Rendering>()->setRenderer( mOcclusionRenderer.get() );

    // note: to disable occlusion culling just restore the 'regular_renderer' as we do below in 'keyPressEvent()'

    populateScene();
  }
  void updateSelection()
  {
    mSelection.clear();
    // select points
    vl::vec4 c = vl::vec4(mCursorTransform->worldMatrix().getT(),1);
    rendering()->as<vl::Rendering>()->camera()->project(c, c);
    for(int x=0; x<mSlices; ++x)
    for(int y=0; y<mSlices; ++y)
    {
      int i = x + mSlices*y;
      if ( x == 0 || y == 0 || x == mSlices-1 || y == mSlices-1 )
        continue;

      vl::vec4 p = vl::vec4((vl::vec3)mPoints->at(i),1);
      p = mTransform->worldMatrix() * p;
      rendering()->as<vl::Rendering>()->camera()->project(p, p);
      float distance = (float)( (p.xy()-c.xy()).length() );
      if (distance < mBrushSize)
      {
        Point point;
        point.mIndex     = i;
        point.mWeight    = 1.0f - distance / mBrushSize;
        point.mStartPos  = (vl::vec3)mPoints->at(i);
        point.mDirection = (p.xy()-c.xy()).normalize();
        mSelection.push_back(point);
      }
    }
  }
  void multitexturing()
  {
    if (!GLEW_ARB_multitexture)
    {
      vl::Log::error("Multitexturing not supported.\n");
      return;
    }

    vl::ref<vl::Geometry> box = vl::makeBox( vl::vec3(0,0,0), 5,5,5, true );
    box->computeNormals();
    box->setTexCoordArray(1, box->texCoordArray(0));

    mCubeRightTransform = new vl::Transform;
    mCubeLeftTransform = new vl::Transform;
    rendering()->as<vl::Rendering>()->transform()->addChild(mCubeRightTransform.get());
    rendering()->as<vl::Rendering>()->transform()->addChild(mCubeLeftTransform.get());

    vl::ref<vl::Image> img_holebox = vl::loadImage("/images/holebox.tif");
    vl::ref<vl::Image> img_detail  = vl::loadImage("/images/detail.tif");

    vl::ref<vl::Texture> tex_holebox = new vl::Texture(img_holebox.get(), vl::TF_RGBA, mMipmappingOn, false);
    vl::ref<vl::Texture> tex_detail  = new vl::Texture(img_detail.get(),  vl::TF_RGBA, mMipmappingOn, false);

    tex_holebox->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
    tex_holebox->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
    tex_detail->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
    tex_detail->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);

    vl::ref<vl::Light> light = new vl::Light(0);

    vl::ref<vl::Effect> cube_right_fx = new vl::Effect;
    // to ensure the cubes are drawn after the textured quads
    cube_right_fx->setRenderRank(1);
    cube_right_fx->shader()->setRenderState( light.get() );
    cube_right_fx->shader()->enable(vl::EN_LIGHTING);
    cube_right_fx->shader()->enable(vl::EN_DEPTH_TEST);
    cube_right_fx->shader()->enable(vl::EN_BLEND);
    cube_right_fx->shader()->enable(vl::EN_ALPHA_TEST);
    cube_right_fx->shader()->gocAlphaFunc()->set(vl::FU_GEQUAL, 1.0f - 0.02f);
    cube_right_fx->shader()->gocLightModel()->setTwoSide(true);
    cube_right_fx->shader()->gocTextureUnit(0)->setTexture( tex_holebox.get() );

    vl::ref<vl::Effect> cube_left_fx = new vl::Effect;
    // to ensure the cubes are drawn after the textured quads
    cube_left_fx->setRenderRank(1);
    cube_left_fx->shader()->setRenderState( light.get() );
    cube_left_fx->shader()->enable(vl::EN_LIGHTING);
    cube_left_fx->shader()->enable(vl::EN_DEPTH_TEST);
    cube_left_fx->shader()->enable(vl::EN_BLEND);
    cube_left_fx->shader()->enable(vl::EN_ALPHA_TEST);
    cube_left_fx->shader()->gocAlphaFunc()->set(vl::FU_GEQUAL, 1.0f - 0.02f);
    cube_left_fx->shader()->gocLightModel()->setTwoSide(true);
    cube_left_fx->shader()->gocTextureUnit(0)->setTexture( tex_holebox.get() );
    cube_left_fx->shader()->gocTextureUnit(1)->setTexture( tex_detail.get() );
    cube_left_fx->shader()->gocTexEnv(1)->setMode( vl::TEM_MODULATE );

    sceneManager()->tree()->addActor( box.get(), cube_right_fx.get(), mCubeRightTransform.get() );
    sceneManager()->tree()->addActor( box.get(), cube_left_fx.get(),  mCubeLeftTransform.get() );
  }
  void generateStars(float side, int star_count)
  {
    // simple effect to render a star billboard
    vl::ref<vl::Effect> effect = new vl::Effect;
    // speedup tip: this allows VL to batch all the stars together greatly speeding up the rendering and avoiding switching textures back and forth with the trees.
    effect->setRenderRank(1);
    effect->shader()->enable(vl::EN_BLEND);
    effect->shader()->enable(vl::EN_DEPTH_TEST);
    effect->shader()->gocTextureSampler(0)->setTexture( new vl::Texture("images/sun.png", vl::TF_RGBA, true) );

    vl::ref<vl::Geometry> star = generateQuad();

    for(int i=0; i<star_count; i++)
    {
      // new billboard
      vl::ref<vl::Billboard> billboard = new vl::Billboard;
      // set spherical billboard type: orient the object always towards the camera.
      billboard->setType(vl::BT_SphericalBillboard);
      // add billboard to the transform tree
      rendering()->as<vl::Rendering>()->transform()->addChild(billboard.get());
      // compute a random point on the skydome
      vl::real x = vl::random(-1.0f,+1.0f);
      vl::real y = vl::random(0,2.0f);
      vl::real z = vl::random(-1.0f,+1.0f);
      vl::vec3 n(x,y,z);
      n.normalize();
      n = n * sqrt(side*side/2.0f);
      n.y() *= 0.2f;
      // set the billboard position and rotation center.
      billboard->setPosition( n );
      // add the star actor
      sceneManager()->tree()->addActor(star.get(), effect.get(), billboard.get());
    }
  }
Beispiel #8
0
void
tinto_take_snapshot(const char *path) {
  Panel* panel = &panel1[0];

  if (panel->area.bounds.width > server.monitor[0].width)
    panel->area.bounds.width = server.monitor[0].width;

  panel->temp_pmap = XCreatePixmap (server.dsp, server.root_win,
				    panel->area.bounds.width,
				    panel->area.bounds.height,
				    server.depth);
  rendering (panel);

  imlib_context_set_drawable (panel->temp_pmap);
  Imlib_Image img =
    imlib_create_image_from_drawable (None, 0, 0,
				      panel->area.bounds.width,
				      panel->area.bounds.height, 0);

  imlib_context_set_image (img);
  if (!panel_horizontal) {
    imlib_image_flip_horizontal ();
    imlib_image_flip_diagonal ();
  }
  imlib_save_image (path);
  imlib_free_image ();
}
Beispiel #9
0
int		main(int ac, char **av, char *envp[])
{
  t_vm	*vm;
  func	*instruct;

  if (ac == 1)
    return (my_printf("Usage: ./corewar[option] [option]champ.cor ...\n"));
  srand(time(NULL));
  if ((vm = create_struct_vm(ac, av)) != NULL)
    {
      instruct = get_ptr_func();
      if (envp[0] != NULL)
	{
	  if ((vm->image = init_image()) == NULL)
	    return (my_printf(
		   "Corewar: error: initialization pictures failed.\n"));
	  if ((vm->sound = init_sound()) == NULL)
	    return (my_printf(
		   "Corewar: error: initialization sounds failed.\n"));
	}
      vm->no_graph = rendering(vm);
      battle_ground(vm, instruct);
      if (vm->winner != NULL)
	return (my_printf("Le joueur %s(%d) a gagné.\n", vm->winner->prog_name,
			  vm->winner->data[ID]));
    }
  return (EXIT_SUCCESS);
}
  void sphericalMapping()
  {
    vl::ref<vl::Image> img_spheric = vl::loadImage("/images/spheremap_klimt.jpg");

    vl::ref<vl::Geometry> torus = vl::makeTorus(vl::vec3(), 8,3, 40,40);
    // normals already present, needed by GL_SPHERE_MAP to work correctly!

    mFXSpheric = new vl::Effect;
    mFXSpheric->shader()->enable(vl::EN_DEPTH_TEST);
    mFXSpheric->shader()->enable(vl::EN_CULL_FACE);
    mFXSpheric->shader()->enable(vl::EN_LIGHTING);
    mFXSpheric->shader()->setRenderState( new vl::Light(0) );
    // to ensure the torus is drawn after the textured quads
    mFXSpheric->setRenderRank(1);

    vl::ref<vl::Texture> texture_spheric = new vl::Texture;
    texture_spheric->prepareTexture2D( img_spheric.get(), vl::TF_RGBA, mMipmappingOn, false );
    mFXSpheric->shader()->gocTextureUnit(0)->setTexture( texture_spheric.get() );
    texture_spheric->getTexParameter()->setAnisotropy(16.0);
    texture_spheric->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
    texture_spheric->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
    // enable automatic texture generation for s,t
    mFXSpheric->shader()->gocTexGen(0)->setGenModeS(vl::TGM_SPHERE_MAP);
    mFXSpheric->shader()->gocTexGen(0)->setGenModeT(vl::TGM_SPHERE_MAP);

    mActSpheric = sceneManager()->tree()->addActor( torus.get(), mFXSpheric.get(), new vl::Transform );
    rendering()->as<vl::Rendering>()->transform()->addChild( mActSpheric->transform() );
  }
  void resizeEvent(int w, int h)
  {
    rendering()->as<vl::Rendering>()->camera()->viewport()->setWidth(w);
    rendering()->as<vl::Rendering>()->camera()->viewport()->setHeight(h);
    rendering()->as<vl::Rendering>()->camera()->setProjectionAsOrtho2D();

    vl::mat4 m;
    m.translate(w/2.0f, h/2.0f, 0.0f);

    float x_scaling = (float)w / mImage->width();
    float y_scaling = (float)h / mImage->height();
    float scaling   = x_scaling < y_scaling ? x_scaling : y_scaling;

    m = m * vl::mat4::getScaling(scaling*mImage->width(), scaling*mImage->height(), scaling);
    mTransform->setLocalMatrix(m);
    // openglContext()->update();
  }
 /* spacebar = toggles occlusion culling */
 void keyPressEvent(unsigned short ch, vl::EKey key)
 {
   BaseDemo::keyPressEvent(ch, key);
   if (key == vl::Key_Space)
   {
     mOcclusionCullingOn = !mOcclusionCullingOn;
     if (mOcclusionCullingOn)
     {
       rendering()->as<vl::Rendering>()->setRenderer( mOcclusionRenderer.get() );
     }
     else
     {
       rendering()->as<vl::Rendering>()->setRenderer( mOcclusionRenderer->wrappedRenderer() );
       mText->setText("Occlusion Culling Off");
     }
   }
 }
Beispiel #13
0
 Solution(int _width, int _height, int _depth) : width(_width), height(_height), depth(_depth), Data() {
     buffer = new int [width * height];
     for (int i=0; i<width*height; i++) {
         buffer[i] = std::numeric_limits<int>::min();
     }
     light = Vector3D<double>(0, 0, -1);
     rendering();
 }
  void mouseMoveEvent(int x, int y)
  {
    if (mMode == AnimateMode)
      return;

    openglContext()->update();

    mCursorActor->setEnableMask(0xFFFFFFFF);

    vl::mat4 m;
    m.scale((vl::Real)mBrushSize/2.0f, (vl::Real)mBrushSize/2.0f, (vl::Real)mBrushSize/2.0f);
    if (mMode == ScaleMode)
      m.translate(mCursorTransform->localMatrix().getT());
    else
      m.translate((vl::Real)x, (vl::Real)rendering()->as<vl::Rendering>()->camera()->viewport()->height()-y, 0);

    mCursorTransform->setLocalMatrix(m);

    if (mMode == TranslateMode)
    {
      float tx = +(float)(x-mMouseStart.x())/rendering()->as<vl::Rendering>()->camera()->viewport()->width();
      float ty = -(float)(y-mMouseStart.y())/rendering()->as<vl::Rendering>()->camera()->viewport()->height();
      for(unsigned i=0; i<mSelection.size(); ++i)
      {
        int ipt = mSelection[i].mIndex;
        float w = mSelection[i].mWeight;
        w = w*w;
        vl::vec3 new_pos = mSelection[i].mStartPos + vl::vec3(tx,ty,0)*w;
        new_pos = vl::clamp(new_pos,vl::vec3(-0.5,-0.5,-0.5),vl::vec3(0.5,0.5,0.5));
        mPoints->at(ipt) = (vl::fvec3)new_pos;
      }
    }
    else
    if (mMode == ScaleMode)
    {
      float scaling = 0.1f * (float)(y-mMouseStart.y())/rendering()->as<vl::Rendering>()->camera()->viewport()->height();
      for(unsigned i=0; i<mSelection.size(); ++i)
      {
        int ipt = mSelection[i].mIndex;
        float w = mSelection[i].mWeight;
        vl::vec3 new_pos = mSelection[i].mStartPos + vl::vec3(mSelection[i].mDirection*w*scaling,0);
        new_pos = vl::clamp(new_pos,vl::vec3(-0.5,-0.5,-0.5),vl::vec3(0.5,0.5,0.5));
        mPoints->at(ipt) = (vl::fvec3)new_pos;
      }
    }
  }
  void initEvent()
  {
    // Basic initialization
    vl::Log::print(appletInfo());

    // Filled effect
    vl::ref<vl::Effect> filled_fx = new vl::Effect;

    // Wireframe effect
    vl::ref<vl::Effect> wireframe_fx = new vl::Effect;
    wireframe_fx->shader()->gocPolygonMode()->set(vl::PM_LINE,vl::PM_LINE);

    // Add empty Actors
    mStar1 = sceneManager()->tree()->addActor( new vl::Actor(NULL, filled_fx.get(), new vl::Transform) );
    mStar2 = sceneManager()->tree()->addActor( new vl::Actor(NULL, wireframe_fx.get(), new vl::Transform) );
    rendering()->as<vl::Rendering>()->transform()->addChild(mStar1->transform());
    rendering()->as<vl::Rendering>()->transform()->addChild(mStar2->transform());
  }
  void initEvent()
  {
    vl::Log::notify(appletInfo());

    // load model
    vl::ref<vl::Geometry> model = vl::loadResource("/models/3ds/monkey.3ds")->get<vl::Geometry>(0);
    model->computeNormals();

    // install transform
    mClipTr = new vl::Transform;
    rendering()->as<vl::Rendering>()->transform()->addChild(mClipTr.get());

    // to be used later
    vl::ref<vl::Light> light = new vl::Light;

    // demonstrates multipassing clipping

    vl::ref<vl::Effect> clip_fx  = new vl::Effect;
    vl::ref<vl::Shader> clip1_sh = new vl::Shader; 
    vl::ref<vl::Shader> clip2_sh = new vl::Shader;
    // setup clipping pass 1
    clip1_sh->setRenderState( light.get(), 0 );
    clip1_sh->enable(vl::EN_LIGHTING);
    clip1_sh->enable(vl::EN_DEPTH_TEST);
    clip1_sh->gocMaterial()->setBackDiffuse(vl::yellow);
    clip1_sh->gocLightModel()->setTwoSide(true);
    // clipping plane 1 setup
    clip1_sh->gocClipPlane(0)->setPlane( vl::Plane(0.2f, vl::vec3(0,+1,0)) );
    clip1_sh->gocClipPlane(0)->bindTransform( mClipTr.get() );
    // setup clipping pass 2
    clip2_sh->setRenderState( light.get(), 0 );
    clip2_sh->enable(vl::EN_LIGHTING);
    clip2_sh->enable(vl::EN_DEPTH_TEST);
    clip2_sh->gocMaterial()->setBackDiffuse(vl::green);
    clip2_sh->gocLightModel()->setTwoSide(true);
    // clipping plane 2 setup
    clip2_sh->gocClipPlane(0)->setPlane( vl::Plane(0.2f, vl::vec3(0,-1,0)) );
    clip2_sh->gocClipPlane(0)->bindTransform( mClipTr.get() );
    // install the two passes for LOD 0
    clip_fx->setLOD(0, clip1_sh.get(), clip2_sh.get());
    // add model to the scene
    sceneManager()->tree()->addActor( model.get(), clip_fx.get(), NULL );

    // renders a plane for visual feedback

    // setup effect
    vl::ref<vl::Effect> plane_fx = new vl::Effect;
    plane_fx->setRenderRank(1); // draw after the clipped model
    plane_fx->shader()->enable(vl::EN_DEPTH_TEST);
    plane_fx->shader()->enable(vl::EN_BLEND);
    plane_fx->shader()->gocLightModel()->setTwoSide(true);
    plane_fx->shader()->gocColor()->setValue(vl::fvec4(1,0,0,0.3f)); // transparent red
    // add plane actor
    vl::ref<vl::Geometry> plane = vl::makeGrid( vl::vec3(0,0,0), 4,4, 2,2 );
    sceneManager()->tree()->addActor( plane.get(), plane_fx.get(), mClipTr.get() );
  }
 void updateScene()
 {
   /* animate the camera to rotate around the scene and bounce near/far */
   float s = sin( vl::Time::currentTime() * vl::fPi * 2.0f / 10.0f );
   vl::Real t = pow((s+1.0f)/2.0f,2);
   vl::Real x = t * 200 + 5;
   vl::vec3 eye( x, 0, 0 );
   eye = vl::mat4::getRotation( vl::Time::currentTime() * 30.0f, 0, 1, 0 ) * eye;
   eye += vl::vec3(0,10+70*t,0);
   vl::mat4 m;
   m = vl::mat4::getLookAt( eye, vl::vec3(0,0,0), vl::vec3(0,1,0) );
   rendering()->as<vl::Rendering>()->camera()->setInverseViewMatrix(m);
 }
  void updateScene() 
  {
    // update the torus tranform
    mTransform->setLocalMatrix( vl::mat4::getRotation( vl::Time::currentTime() * 5.0f, 0, -1, 1 ) );
    mTransform->computeWorldMatrix();

    // world to object space matrix
    vl::mat4 obj_mat = mTransform->worldMatrix().getInverse();

    // project camera position from world to object space
    vl::vec3 camera_pos = rendering()->as<vl::Rendering>()->camera()->modelingMatrix().getT();
    vl::vec3 camera_pos_obj_space = obj_mat * camera_pos;
    mLightObjSpacePosition->setUniform( (vl::fvec3)camera_pos_obj_space );
  }
  void cubeMapping()
  {
    // cube mapping, see also http://developer.nvidia.com/object/cube_map_ogl_tutorial.html

    vl::ref<vl::Image> img_cubemap = vl::loadCubemap(
      "/images/cubemap/cubemap00.png", // (x+) right
      "/images/cubemap/cubemap01.png", // (x-) left
      "/images/cubemap/cubemap02.png", // (y+) top
      "/images/cubemap/cubemap03.png", // (y-) bottom
      "/images/cubemap/cubemap04.png", // (z+) back
      "/images/cubemap/cubemap05.png");// (z-) front

    vl::ref<vl::Geometry> torus = vl::makeTorus( vl::vec3(), 8,3, 40,40 );
    // normals already present, needed by GL_SPHERE_MAP to work correctly!

    mFXCubic = new vl::Effect;
    mFXCubic->shader()->enable(vl::EN_DEPTH_TEST);
    mFXCubic->shader()->enable(vl::EN_CULL_FACE);
    mFXCubic->shader()->enable(vl::EN_LIGHTING);
    mFXCubic->shader()->setRenderState( new vl::Light(0) );
    // to ensure the torus is drawn after the textured quads
    mFXCubic->setRenderRank(1);

    if (GLEW_VERSION_1_3||GLEW_ARB_texture_cube_map)
    {
      vl::ref<vl::Texture> texture_cubic = new vl::Texture;
      texture_cubic->prepareTextureCubemap( img_cubemap.get(), vl::TF_RGBA, mMipmappingOn, false );
      mFXCubic->shader()->gocTextureUnit(0)->setTexture( texture_cubic.get() );
      texture_cubic->getTexParameter()->setAnisotropy(16.0);
      texture_cubic->getTexParameter()->setMagFilter(vl::TPF_LINEAR);
      texture_cubic->getTexParameter()->setMinFilter(vl::TPF_LINEAR_MIPMAP_LINEAR);
      texture_cubic->getTexParameter()->setWrapS(vl::TPW_CLAMP_TO_EDGE);
      texture_cubic->getTexParameter()->setWrapT(vl::TPW_CLAMP_TO_EDGE);
      texture_cubic->getTexParameter()->setWrapR(vl::TPW_CLAMP_TO_EDGE);
      // enable automatic texture generation for s,t,r
      mFXCubic->shader()->gocTexGen(0)->setGenModeS(vl::TGM_REFLECTION_MAP);
      mFXCubic->shader()->gocTexGen(0)->setGenModeT(vl::TGM_REFLECTION_MAP);
      mFXCubic->shader()->gocTexGen(0)->setGenModeR(vl::TGM_REFLECTION_MAP);
      // texture matrix
      mFXCubic->shader()->gocTextureMatrix(0)->setUseCameraRotationInverse(true);
    }
    else
      vl::Log::error("Texture cubemap not supported.\n");

    mActCubic = sceneManager()->tree()->addActor( torus.get(), mFXCubic.get(), new vl::Transform );
    rendering()->as<vl::Rendering>()->transform()->addChild( mActCubic->transform() );
  }
  virtual void initEvent()
  {
    vl::Log::print(appletInfo());

    trackball()->setTransform(rendering()->as<vl::Rendering>()->transform());

    mMipmappingOn = true;
    mLodBias = 0.0;

    multitexturing();
    textureRectangle();
    texture3D();
    texture2DArray();
    texture1DArray();
    sphericalMapping();
    cubeMapping();
  }
  /* Loads the specified mol2 file. */
  void loadMolecule(const vl::String& mol2_file)
  {
    mCurrentMolecule = 0;
    vl::loadMOL2( mol2_file, mMolecules );
    if (!mMolecules.empty())
      updateMolecule();

    /* adjust the camera position to nicely see the scene, it also position the rotation pivot to the center of the molecule */
    trackball()->adjustView( rendering()->as<vl::Rendering>(), vl::vec3(0,0,1), vl::vec3(0,1,0), 1.0f );

    for(size_t i=0; i<mMolecules.size(); ++i)
    {
      vl::String msg;
      msg = "New molecule: " + mMolecules[i]->moleculeName() + " - " + vl::String::fromInt(mMolecules[i]->atomCount()) + " atoms\n";
      vl::Log::print(msg);
    }
  }
Beispiel #22
0
void FullscreenPass::render_scene(Camera const& camera,
                                  SceneGraph const&,
                                  RenderContext const& ctx,
                                  std::size_t view) {

  if (!depth_stencil_state_)
    depth_stencil_state_ = ctx.render_device
        ->create_depth_stencil_state(false, false, scm::gl::COMPARISON_NEVER);

  if (!fullscreen_quad_)
    fullscreen_quad_ = scm::gl::quad_geometry_ptr(new scm::gl::quad_geometry(
        ctx.render_device, math::vec2(-1.f, -1.f), math::vec2(1.f, 1.f)));
  set_uniforms(pipeline_->get_current_scene(CameraMode::CENTER), ctx);

  for (int i(0); i < gbuffer_->get_eye_buffers().size(); ++i) {
    CameraMode eye(CameraMode::CENTER);

    if (gbuffer_->get_eye_buffers().size() > 1 && i == 0)
      eye = CameraMode::LEFT;
    if (gbuffer_->get_eye_buffers().size() > 1 && i == 1)
      eye = CameraMode::RIGHT;

    pre_rendering(camera, pipeline_->get_current_scene(eye), eye, ctx);

    FrameBufferObject* fbo(gbuffer_->get_eye_buffers()[i]);
    fbo->bind(ctx);

    ctx.render_context->set_viewport(scm::gl::viewport(
        math::vec2(0, 0), math::vec2(float(fbo->width()), float(fbo->height()))));
    ctx.render_context->set_depth_stencil_state(depth_stencil_state_);

    rendering(camera, pipeline_->get_current_scene(eye), eye, ctx);

    ctx.render_context->reset_state_objects();

    fbo->unbind(ctx);

    post_rendering(camera, pipeline_->get_current_scene(eye), eye, ctx);
  }

}
  void mouseDownEvent(vl::EMouseButton, int x, int y)
  {
    vl::Camera* camera = rendering()->as<vl::Rendering>()->camera();

    // convert Y coordinates to the OpenGL conventions
    y = openglContext()->height() - y;
    // compute the ray passing through the selected pixel
    vl::Ray ray = camera->computeRay(x,y);
    // instance our ray-intersector
    vl::RayIntersector intersector;
    // compute a frustum along the ray to accelerate the intersection test
    intersector.setFrustum( camera->computeRayFrustum( x,y ) );
    // compute the intersections!
    // (1) short way
    intersector.intersect(ray, sceneManager());
    // (2) long way
    /*
    // specify the Actor[s] to be tested
    intersector.actors()->clear();
    sceneManager()->extractActors( *intersector.actors() );
    // set the intersecting ray
    intersector.setRay(ray);
    // run intersection test
    intersector.intersect();
    */

    // inspect our intersections, the intersections returned are sorted according to their distance, the first one is the closest.
    if (intersector.intersections().size())
    {
      // highlight the intersection point by moving the green sphere there
      mIntersectionPoint->setLocalMatrix( vl::mat4() );
      mIntersectionPoint->translate( intersector.intersections()[0]->intersectionPoint() );
      mIntersectionPoint->computeWorldMatrix();

      // print the name of the picked object
      vl::Log::print( vl::Say("Intersections detected = %n (%s).\n") << intersector.intersections().size() << intersector.intersections()[0]->actor()->objectName() );
    }
    else
      vl::Log::print("No intersections detected.\n");
  }
    virtual void initEvent()
    {
        vl::Log::notify(appletInfo());

        mSceneKdTree = new vl::SceneManagerActorKdTree;
        rendering()->as<vl::Rendering>()->sceneManagers()->push_back(mSceneKdTree.get());

        mText = new vl::Text;
        mText->setFont( vl::defFontManager()->acquireFont("/font/bitstream-vera/VeraMono.ttf", 10, false) );
        mText->setAlignment(vl::AlignHCenter | vl::AlignTop);
        mText->setViewportAlignment(vl::AlignHCenter | vl::AlignTop);
        mText->setColor(vl::white);
        mText->translate(0,-10,0);
        mTextActor = sceneManager()->tree()->addActor(mText.get(), new vl::Effect);
        mTextActor->effect()->shader()->enable(vl::EN_BLEND);

        mTestNumber = 0;
        mViewDepth  = -1;

        createScene();
        mText->setText( mText->text() + "\nPress left/right to change the test number\nPress up/down to change the visible tree level");
    }
Beispiel #25
0
int main()
{

vector v1,v2,v3;
    
vec(&v1,0,-10004,-20);
vec(&v2,0.20,0.20,0.20);
vec(&v3,0,0,0);

sph(v1,10000,v2,0,0,v3,sp);

vec(&v1,0,0,-20);
vec(&v2,1,0.32,0.36);

sph(v1,4,v2,1,0.5,v3,sp+1);

vec(&v1,5,-1,-15);
vec(&v2,0.90,0.76,0.46);

sph(v1,2,v2,1,0,v3,sp+2);

vec(&v1,5,0,-25);
vec(&v2,0.65,0.77,0.97);

sph(v1,3,v2,1,0,v3,sp+3);

vec(&v1,-5.5,0,-15);
vec(&v2,0.90,0.90,0.90);

sph(v1,3,v2,1,0,v3,sp+4);

vec(&v1,0,20,-30);
vec(&v2,0,0,0);
vec(&v3,3,3,3);

sph(v1,3,v2,0,0,v3,sp+5);

rendering();
}
void WindowCheckKeyterms::get_renderings(vector <ustring> &renderings, vector <bool> &wholewords, vector <bool> &casesensitives)
{
  GtkTreeModel *model = (GtkTreeModel *) treestore_renderings;
  GtkTreeIter iter;
  gboolean valid;
  valid = gtk_tree_model_get_iter_first(model, &iter);
  while (valid) {
    int wholeword, casesensitive;
    gchar *str_data;
    gtk_tree_model_get(model, &iter, 0, &wholeword, 1, &casesensitive, 2, &str_data, -1);
    ustring rendering(str_data);
    if (!rendering.empty()) {
      if (rendering != enter_new_rendering_here()) {
        renderings.push_back(rendering);
        wholewords.push_back(wholeword);
        casesensitives.push_back(casesensitive);
      }
    }
    g_free(str_data);
    valid = gtk_tree_model_iter_next(model, &iter);
  }
}
  virtual void updateScene()
  {
    // note that this creates a delay on the application of the camera transform

    bool update_matrices = !mTimer.isStarted( ) || mTimer.elapsed() > 1.0f/30.0f;

    if (update_matrices)
      mTimer.start();
    else
      return;

    vl::fmat4 mat_array[1000];
    vl::fmat3 mat_array_norm[1000];

    for (int batch = 0; batch < 10; ++batch)
    {
      // update matrices
      vl::fmat4 view = (vl::fmat4)rendering()->as<vl::Rendering>()->camera()->viewMatrix();
      for(int k=0; k<100; ++k)
      {
        int i = batch*100 + k;

        float x = float( i % 10)  * 5.0f;
        float y = float( ( i % 100) / 10 ) * 5.0f;
        float z = float( i / 100) * 5.0f;
        float deg = 0;
        deg = (float)vl::Time::currentTime() * 240.0f;

        mat_array[i].rotate(deg, rot[batch*100+k]);
        mat_array[i].translate(x,y,z);
        mat_array[i] = view * mat_array[i];
        mat_array_norm[i] = mat_array[i].getInverse().transpose().get3x3();
      }

      // update the uniforms
      _model_view_matrix[batch]->setUniform(100, mat_array      + batch * 100);
      _normal_matrix    [batch]->setUniform(100, mat_array_norm + batch * 100);
    }
  }
  // This function demonstrates how a billboard behaves when it is put under an animated transform hierarchy.
  // Note how the cube always faces the camera even if it follows its parent's rotation.
  void generateLunapark()
  {
    vl::ref<vl::Effect> effect = new vl::Effect;
    effect->shader()->setRenderState( new vl::Light, 0 );
    effect->shader()->enable(vl::EN_BLEND);
    effect->shader()->enable(vl::EN_DEPTH_TEST);
    effect->shader()->enable(vl::EN_LIGHTING);

    vl::ref<vl::Geometry>  arm_g = vl::makeCylinder(vl::vec3(0,0,0), 0.5f, 4.0f);
    arm_g->computeNormals();
    vl::ref<vl::Transform> arm1_t = new vl::Transform;
    vl::ref<vl::Transform> arm2_t = new vl::Transform;
    rendering()->as<vl::Rendering>()->transform()->addChild(arm1_t.get());
    arm1_t->addChild(arm2_t.get());
    arm2_t->setLocalMatrix(vl::mat4::getTranslation(0.0f,2.0f,0.0f) * vl::mat4::getRotation(90,0,0,1) * vl::mat4::getTranslation(0.0f,2.0f,0.0f));

    sceneManager()->tree()->addActor( arm_g.get(), effect.get(), arm1_t.get());
    sceneManager()->tree()->addActor( arm_g.get(), effect.get(), arm2_t.get());

    vl::ref<vl::Geometry> box = vl::makeBox(vl::vec3(0,-0.75f,0), 1, 1, 1);
    box->computeNormals();

    // the billboard
    vl::ref<vl::Billboard> billboard = new vl::Billboard;
    // use an axis aligned billboard
    billboard->setType(vl::BT_AxisAlignedBillboard);
    // the axis is always in world coordinates
    billboard->setAxis(vl::vec3(0,1,0));
    // remember that "position" is relative to the billboard's parent's coordinates
    billboard->setPosition(0,2,0);
    // add the billboard to its transform parent
    arm2_t->addChild(billboard.get());
    // add the box actor
    sceneManager()->tree()->addActor( box.get(), effect.get(), billboard.get());

    // to be animated below
    mArm1Transform = arm1_t;
  }
  void generateTrees(float side, int tree_count)
  {
    // simple effect to render a tree billboard
    vl::ref<vl::Effect> effect = new vl::Effect;
    // speedup tip: this allows VL to batch all the trees together greatly speeding up the rendering and avoiding switching textures back and forth with the stars.
    effect->setRenderRank(2);
    effect->shader()->setRenderState( new vl::Light, 0 );
    effect->shader()->enable(vl::EN_BLEND);
    effect->shader()->enable(vl::EN_DEPTH_TEST);
    effect->shader()->gocDepthMask()->set(false);
    effect->shader()->enable(vl::EN_LIGHTING);
    effect->shader()->gocLight(0)->setLinearAttenuation(0.025f);
    effect->shader()->gocTextureSampler(0)->setTexture( new vl::Texture("images/tree.png") );

    vl::ref<vl::Geometry> tree = generateQuad();
    tree->transform( vl::mat4::getTranslation(0,+0.5f,0) );
    tree->transform( vl::mat4::getScaling(1.0f,+2.0f,1.0f) );
    tree->computeNormals();

    for(int i=0; i<tree_count; i++)
    {
      // new billboard
      vl::ref<vl::Billboard> billboard = new vl::Billboard;
      // set axis-aligned billboard type: rotate the billboard towards the camera but only around the specified axis.
      billboard->setType(vl::BT_AxisAlignedBillboard);
      billboard->setAxis(vl::vec3(0,1.0f,0));
      // bind billboard to the transform tree
      rendering()->as<vl::Rendering>()->transform()->addChild(billboard.get());
      // generate a random position
      vl::real x = vl::random(-side/2.0f,+side/2.0f);
      vl::real y = 0;
      vl::real z = vl::random(-side/2.0f,+side/2.0f);
      billboard->setPosition( vl::vec3(x,y,z) );
      // add the tree actor
      sceneManager()->tree()->addActor(tree.get(), effect.get(), billboard.get());
    }
  }
  virtual void initEvent()
  {
    vl::Log::notify(appletInfo());

    // transform used for the moving cube and star

    vl::ref< vl::Transform > transf = new vl::Transform;
    rendering()->as<vl::Rendering>()->transform()->addChild(transf.get());

    // effect for 2d rendering

    vl::ref<vl::Effect> pixel_fx = new vl::Effect;
    pixel_fx->shader()->enable(vl::EN_BLEND);
    pixel_fx->shader()->enable(vl::EN_ALPHA_TEST);
    pixel_fx->shader()->gocAlphaFunc()->set(vl::FU_GEQUAL, 0.9f);

    // points rendering

    vl::ref<vl::ImagePBO> circle16 = new vl::ImagePBO("/images/circle16.png");

    mPoints = new vl::DrawPixels;
    for(int i=0; i<1000; ++i)
    {
      vl::ref<vl::DrawPixels::Pixels> pixels = new vl::DrawPixels::Pixels(circle16.get(), 0,0);
      mPoints->draws()->push_back( pixels.get() );
      vl::ivec2 pos;
      pos.x() = int(openglContext()->width()  / 2.0 + rand()%300 - 150);
      pos.y() = int(openglContext()->height() / 2.0 + rand()%300 - 150);
      pixels->setPosition(pos);
      pixels->setAlign(vl::AlignHCenter | vl::AlignVCenter);
    }

    mPoints->generatePixelBufferObjects(vl::BU_STATIC_DRAW, true);

    sceneManager()->tree()->addActor( mPoints.get(), pixel_fx.get(), NULL )->setRenderRank(0);

    // split star rendering

    vl::ref<vl::ImagePBO> star_img = new vl::ImagePBO("/images/star.png");

    int w = star_img->width() / 2;
    mStar1 = new vl::DrawPixels::Pixels( star_img.get(), 0, 0, 0, 0, w, w );
    mStar2 = new vl::DrawPixels::Pixels( star_img.get(), 0, 0, w, w, w, w );
    mStar3 = new vl::DrawPixels::Pixels( star_img.get(), 0, 0, w, 0, w, w);
    mStar4 = new vl::DrawPixels::Pixels( star_img.get(), 0, 0, 0, w, w, w);

    mStar1->setAlign(vl::AlignRight|vl::AlignTop);
    mStar2->setAlign(vl::AlignLeft|vl::AlignBottom);
    mStar3->setAlign(vl::AlignLeft|vl::AlignTop);
    mStar4->setAlign(vl::AlignRight|vl::AlignBottom);

    mStar = new vl::DrawPixels;
    mStar->draws()->push_back( mStar1.get() );
    mStar->draws()->push_back( mStar2.get() );
    mStar->draws()->push_back( mStar3.get() );
    mStar->draws()->push_back( mStar4.get() );

    mStar->generatePixelBufferObjects(vl::BU_STATIC_DRAW, true);

    sceneManager()->tree()->addActor( mStar.get(), pixel_fx.get(), transf.get() )->setRenderRank(1);

    // moving cube

    vl::ref<vl::Effect> cube_fx = new vl::Effect;
    cube_fx->shader()->enable(vl::EN_DEPTH_TEST);
    cube_fx->shader()->enable(vl::EN_LIGHTING);
    cube_fx->shader()->setRenderState( new vl::Light, 0 );

    vl::ref<vl::Geometry> cube = vl::makeBox( vl::vec3(0,0,0), 1, 1, 1 );
    cube->computeNormals();
    mCube = sceneManager()->tree()->addActor(cube.get(), cube_fx.get(), transf.get() );
    mCube->setRenderRank(2); // draw after 2d objects
  }