void Render(double time) { static const Mat4f reflection( Vec4f( 1.0, 0.0, 0.0, 0.0), Vec4f( 0.0,-1.0, 0.0, 0.0), Vec4f( 0.0, 0.0, 1.0, 0.0), Vec4f( 0.0, 0.0, 0.0, 1.0) ); auto camera = CamMatrixf::Orbiting( Vec3f(), GLfloat(7.0 + SineWave(time / 12.0)*2.5), FullCircles(time / 10.0), Degrees(45.0 - SineWave(time / 7.0)*35.0) ); shape_prog.Use(); shape.Bind(); gl.Enable(Capability::CullFace); gl.FrontFace(make_shape.FaceWinding()); // render into the off-screen framebuffer fbo.Bind(Framebuffer::Target::Draw); gl.Viewport( (width - refl_tex_side) / 2, (height - refl_tex_side) / 2, refl_tex_side, refl_tex_side ); gl.Clear().ColorBuffer().DepthBuffer(); shape_camera_matrix.Set( camera * ModelMatrixf::Translation(0.0f, -1.0f, 0.0f) * reflection ); gl.CullFace(Face::Front); shape_instr.Draw(shape_indices); gl.Bind(Framebuffer::Target::Draw, DefaultFramebuffer()); gl.Viewport(width, height); gl.Clear().ColorBuffer().DepthBuffer(); shape_camera_matrix.Set(camera); gl.CullFace(Face::Back); shape_instr.Draw(shape_indices); gl.Disable(Capability::CullFace); // Render the plane plane_prog.Use(); plane.Bind(); plane_camera_matrix.Set(camera); plane_camera_position.Set(camera.Position()); plane_instr.Draw(plane_indices); }
//-------------------------------------------------------------- void testApp::setup(){ ofSoundStreamSetup(2, 0, this, 44100, 256, 4); // create a new oscillator which we'll use for the actual audio signal SineWave tone = SineWave(); // create a sine wave we'll use for some vibrato SineWave vibratoOsc = SineWave(); vibratoOsc.freq(1); // you can use the regular arithmatic operators on Generators and their subclasses (SineWave extends Generator) float basePitch = 400; Generator frequency = basePitch + (vibratoOsc * basePitch * 0.01); // plug that frequency generator into the frequency slot of the main audio-producing sine wave tone.freq(frequency); ControlGenerator envelopeTrigger = synth.addParameter("trigger"); Generator env = ADSR().attack(0.01).decay(0.5).sustain(0).release(0).trigger(envelopeTrigger); // set the synth's final output generator synth.setOutputGen( tone * env ); }
void RenderImage(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // Mat4f perspective = CamMatrixf::PerspectiveX(Degrees(48), width, height, 1, 100); auto camera = CamMatrixf::Orbiting( Vec3f(0, 0, 0), GLfloat(4.0 - SineWave(time / 14.0)), FullCircles(time / 26.0), Degrees(45 + SineWave(time / 17.0) * 40)); Vec3f camera_position = camera.Position(); metal_prog.Use(); metal_prog.camera_position.Set(camera_position); metal_prog.camera_matrix.Set(perspective * camera); plane.Use(); plane.Draw(); blob_prog.Use(); blob_prog.camera_position.Set(camera_position); blob_prog.camera_matrix.Set(perspective * camera); grid.Use(); int side = 1; for(int z = -side; z != side; ++z) for(int y = -side; y != side; ++y) for(int x = -side; x != side; ++x) { blob_prog.grid_offset.Set(x, y, z); grid.Draw(); } }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // liquid_prog.time = time; auto camera = CamMatrixf::Orbiting( Vec3f(0, 0, 0), 4.5 - SineWave(time / 14.0), FullCircles(time / 26.0), Degrees(55 + SineWave(time / 14.0) * 30) ); Vec3f camera_position = camera.Position(); liquid_prog.camera_position = camera_position; liquid_prog.camera_matrix = perspective*camera; for(int z=-grid_repeat; z!=grid_repeat; ++z) for(int x=-grid_repeat; x!=grid_repeat; ++x) { liquid_prog.grid_offset.Set(x, -0.5, z); grid.Draw(); } }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 4.0 - SineWave(time / 6.0) * 2.0, FullCircles(time * 0.4), Degrees(SineWave(time / 30.0) * 90) ) ); // set the model matrix model_matrix.Set( ModelMatrixf::RotationZ(FullCircles(time * 0.1)) ); cube.Bind(); gl.CullFace(Face::Front); cube_instr.Draw(cube_indices); gl.CullFace(Face::Back); cube_instr.Draw(cube_indices); }
void Render(double time) { const double day_duration = 67.0; auto sun = Vec3f(0.000, 1.000, 0.000) * 1e10 * SineWave(time / day_duration) + Vec3f(0.000, 0.000, -1.000) * 1e10 * CosineWave(time / day_duration); auto camera = CamMatrixf::Orbiting( Vec3f(), 5.0, FullCircles(-0.10 - time / 27.0), Degrees(-20 - SineWave(time / 17.0) * 30)); auto model = ModelMatrixf::RotationA( Vec3f(1.0, 1.0, 1.0), FullCircles(time / 13.0)); gl.Clear().ColorBuffer().DepthBuffer(); sky_box.Use(); sky_box_prog.Use(); sky_box_camera_matrix.Set(camera); sky_box_sun_position.Set(sun); sky_box.Draw(); shape.Use(); shape_prog.Use(); shape_model_matrix.Set(model); shape_camera_matrix.Set(camera); shape_camera_position.Set(camera.Position()); shape_sun_position.Set(sun); shape.Draw(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto camera = CamMatrixf::Orbiting( Vec3f(), field.Radius()*(1.4 + SineWave(time / 6.0) * 0.2), FullCircles(time * 0.1), Degrees(SineWave(time / 30.0) * 90) ); auto light = CamMatrixf::Orbiting( Vec3f(), field.Radius()*1.6, FullCircles(0.33-time * 0.07), Degrees(SineWave(time / 31.0) * 80) ); prog.camera_matrix.Set(camera); prog.light_position.Set(light.Position()); GLfloat fade_coef = 1.1*(1.0-CosineWave01(time / 90.0)); prog.fade_coef.Set(fade_coef); field.Draw(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 4.5 - SineWave(time / 16.0) * 2.0, FullCircles(time / 12.0), Degrees(SineWave(time / 30.0) * 90) ) ); // set the model matrix model_matrix.Set( ModelMatrixf::RotationA( Vec3f(1.0f, 1.0f, 1.0f), FullCircles(time / 10.0) ) ); shape.Bind(); shape_instr.Draw(shape_indices); }
double Draw(double time) { assert(!shapes.empty()); assert(ishape != shapes.end()); shapes::ShapeWrapper& shape = *ishape; const double interval = 11.0; double segment = time - shape_time; double fade = segment*(interval-segment); fade -= 1.0; if(fade < 0.0) fade = 0.0; fade = std::sqrt(fade/interval); if(fade > 1.0) fade = 1.0; if(segment > interval) { if(++ishape == shapes.end()) { ishape = shapes.begin(); } shape_time = time; } gl.Clear().DepthBuffer(); float dist = (1.0+SineWave(time / 13.0))*2.5; projection_matrix.Set( CamMatrixf::PerspectiveX( Degrees(45), 1.0, 1.0+dist, shape.BoundingSphere().Radius()*2.0+1.0+dist ) ); camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), shape.BoundingSphere().Radius()+1.5+dist, FullCircles(time / 27.0), Degrees(SineWave(time / 23.0) * 89) ) ); model_matrix.Set( ModelMatrixf::RotationA( Vec3f(1,1,1), FullCircles(time /-37.0) ) ); prog.Use(); shape.Use(); shape.Draw(); return fade; }
void Render(double time) { auto camera = CamMatrixf::Roll(Degrees(SineWave(time / 11.0)*7+SineWave(time/13.0)*5))* CamMatrixf::Orbiting( Vec3f(), 40.0f, Degrees(SineWave(time / 11.0)*10+CosineWave(time/19.0)*10-90), Degrees(SineWave(time / 17.0)*10+SineWave(time/13.0)*10) ); auto mm_identity = ModelMatrixf(); auto mm_rotation = ModelMatrixf::RotationZ(FullCircles(time / 7.0)); Uniform<Mat4f>* model_matrix = nullptr; GLuint drawing_fan = fan_index; auto drawing_driver = [ &model_matrix, &mm_identity, &mm_rotation, &drawing_fan ](GLuint phase) -> bool { if(phase == drawing_fan) model_matrix->Set(mm_rotation); else model_matrix->Set(mm_identity); return true; }; // render the light mask light_fbo.Bind(Framebuffer::Target::Draw); gl.Clear().ColorBuffer().DepthBuffer(); mask_vao.Bind(); mask_prog.Use(); mask_prog.camera_matrix.Set(camera); model_matrix = &mask_prog.model_matrix; meshes.Draw(drawing_driver); // render the final image DefaultFramebuffer().Bind(Framebuffer::Target::Draw); gl.Clear().ColorBuffer().DepthBuffer(); draw_vao.Bind(); draw_prog.Use(); Vec4f lsp = projection * camera * Vec4f(light_position, 1.0); draw_prog.light_screen_pos = lsp.xyz()/lsp.w(); draw_prog.camera_matrix.Set(camera); model_matrix = &draw_prog.model_matrix; meshes.Draw(drawing_driver); }
Mat4f CameraMat(double time) { return CamMatrixf::Orbiting( Vec3f(0, 0, 0), 5.0 - SineWave(time / 11.0), FullCircles(time / 23.0), Degrees(SineWave(time / 17.0) * 80) ); }
void Render(ExampleClock& clock) { positions.clear(); ages.clear(); // update the emitters and get the particle data for(auto i=emitters.begin(), e=emitters.end(); i!=e; ++i) { i->Update(clock); i->Upload(positions, ages); } assert(positions.size() == ages.size()); // make a camera matrix auto cameraMatrix = CamMatrixf::Orbiting( Vec3f(), 38.0 - SineWave(clock.Now().Seconds() / 6.0) * 17.0, FullCircles(clock.Now().Seconds() * 0.1), Degrees(SineWave(clock.Now().Seconds() / 20.0) * 60) ); std::vector<float> depths(positions.size()); std::vector<GLuint> indices(positions.size()); // calculate the depths of the particles for(GLuint i=0, n=positions.size(); i!=n; ++i) { depths[i] = (cameraMatrix * Vec4f(positions[i], 1.0)).z(); indices[i] = i; } // sort the indices by the depths std::sort( indices.begin(), indices.end(), [&depths](GLuint i, GLuint j) { return depths[i] < depths[j]; } ); // upload the particle positions pos_buf.Bind(Buffer::Target::Array); Buffer::Data(Buffer::Target::Array, positions, BufferUsage::DynamicDraw); // upload the particle ages age_buf.Bind(Buffer::Target::Array); Buffer::Data(Buffer::Target::Array, ages, BufferUsage::DynamicDraw); gl.Clear().ColorBuffer().DepthBuffer(); camera_matrix.Set(cameraMatrix); // use the indices to draw the particles gl.DrawElements( PrimitiveType::Points, indices.size(), indices.data() ); }
void Render(double time) { float o = 2; float s = 24; prog.offset.Set( GLfloat(CosineWave(time/59.0)*o), GLfloat(SineWave(time/61.0)*o) ); prog.scale.Set(GLfloat(s + 1 + SineWave(time / 19.0)*s)); screen.Draw(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // camera matrix auto camera = CamMatrixf::Orbiting( Vec3f(), 4.5f, Degrees(time * 50), Degrees(SineWave(time / 15.0) * 70) ); // model matrix auto model = ModelMatrixf::Translation( 0.0f, sqrt(1.0f+SineWave(time / 2.0)), 0.0f ) * ModelMatrixf::RotationX(FullCircles(time)); // // use transform feedback to get transformed hole vertices prog_tfb.Use(); Uniform<Mat4f>(prog_tfb, "CameraMatrix").Set(camera); Uniform<Mat4f>(prog_tfb, "ModelMatrix").Set(model); holes.Bind(); { TransformFeedback::Activator activates_tfb( TransformFeedbackPrimitiveType::Points ); gl.DrawArrays(PrimitiveType::Points, 0, hole_count); } prog.Use(); // Uniform<Mat4f>(prog, "CameraMatrix").Set(camera); Uniform<Mat4f>(prog, "ModelMatrix").Set(model); // map the transform feedback buffer BufferTypedMap<GLfloat> transf_hole_verts_map( Buffer::Target::TransformFeedback, BufferMapAccess::Read ); // use the values stored in the buffer as the input // for the fragment shader, that will use them to // calculate the bump map Uniform<GLfloat>(prog, "TransfHole").SetVectors<3>( transf_hole_verts_map.Count(), transf_hole_verts_map.Data() ); // bind the VAO for the spere and render it sphere.Bind(); sphere_instr.Draw(sphere_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); CamMatrixf camera = CamMatrixf::Orbiting( Vec3f(), 4.5f + float(SineWave(time / 25.0)), FullCircles(time / 30.0), Degrees(SineWave(time / 19.0) * 20) ); light_prog.camera_matrix.Set(camera); flare_prog.camera_matrix.Set(camera); shape_prog.camera_matrix.Set(camera); shape_prog.camera_position.Set(camera.Position()); shape_prog.model_matrix.Set( ModelMatrixf::RotationX(FullCircles(time / 30.0)) ); shape_prog.Use(); shape.Draw(); NoProgram().Use(); lights.Bind(); light_prog.Use(); for(GLuint l=0; l!=n_flares; ++l) { queries[l].Begin(Query::Target::SamplesPassed); gl.DrawArrays(PrimitiveType::Points, l, 1); queries[l].End(Query::Target::SamplesPassed); } gl.Enable(Capability::Blend); gl.Disable(Capability::DepthTest); flare_prog.Use(); for(GLuint l=0; l!=n_flares; ++l) { GLint samples = 0; queries[l].WaitForResult(samples); if(samples != 0) { flare_prog.samples = samples; gl.DrawArrays(PrimitiveType::Points, l, 1); } } gl.Enable(Capability::DepthTest); gl.Disable(Capability::Blend); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 3.5 + SineWave(time / 6.0)*0.5, FullCircles(time * 0.2), Degrees(SineWave(time / 20.0) * 80) ) ); gl.DrawArrays(PrimitiveType::Points, 0, 1); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), GLfloat(30.0 - SineWave(time / 17.0)*25.0), Degrees(time * 47), Degrees(SineWave(time / 31.0) * 90) ) ); gl.DrawArrays(PrimitiveType::Patches, 0, 16); }
void RenderOffscreen(double time) { fbo.Bind(); gl.Clear().ColorBuffer().DepthBuffer(); gl.BlendFunc(BlendFn::One, BlendFn::One); gl.Enable(Capability::Blend); gl.Enable(Capability::DepthTest); draw_prog.Use(); draw_prog.camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 27.0, Degrees(time * 23), Degrees(SineWave(time / 23.0) * 80) ) ); cube.Use(); cube.Draw(n*n*n); gl.Disable(Capability::DepthTest); gl.Disable(Capability::Blend); fbo.Unbind(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // auto camera = CamMatrixf::Orbiting( Vec3f(), 4.5, Degrees(time * 35), Degrees(SineWave(time / 30.0) * 60) ); auto model = ModelMatrixf::RotationY(FullCircles(time * 0.25)) * ModelMatrixf::RotationX(FullCircles(time * 0.33)); camera_matrix.Set(camera); model_matrix.Set(model); transf_time.Set(time); face_pp.Bind(); gl.PolygonMode(PolygonMode::Fill); torus_instr.Draw(torus_indices); frame_pp.Bind(); gl.PolygonMode(PolygonMode::Line); torus_instr.Draw(torus_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 3.0f, Degrees(time * 50), Degrees(SineWave(time / 16.0) * 80) ) ); // the model matrix model_matrix.Set( ModelMatrixf::RotationY(Degrees(time * 25)) ); // draw 36 instances of the cube // first the back faces gl.CullFace(Face::Front); front_facing.Set(0); cube_instr.Draw(cube_indices, inst_count); // then the front faces gl.CullFace(Face::Back); front_facing.Set(1); cube_instr.Draw(cube_indices, inst_count); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 4.0, Degrees(time * 25), Degrees(SineWave(time / 30.0) * 90) ) ); model_matrix.Set( ModelMatrixf::RotationA( Vec3f(1.0f, 1.0f, 1.0f), FullCircles(time * 0.5) ) ); shape.Draw(); thread_ready.Signal(); parent_ready.Wait(); }
void Render(double time) { const GLfloat clear_color[4] = {0.8f, 0.8f, 0.7f, 0.0f}; gl.ClearColorBuffer(0, clear_color); gl.ClearDepthBuffer(1.0f); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 3.5, Degrees(time * 15), Degrees(SineWave(time / 6.3) * 45) ) ); model_matrix.Set( ModelMatrixf::Translation(-1.0, 0.0, 0.0) * ModelMatrixf::RotationZ(Degrees(time * 180)) ); cube_instr.Draw(cube_indices); model_matrix.Set( ModelMatrixf::Translation(+1.0, 0.0, 0.0) * ModelMatrixf::RotationY(Degrees(time * 90)) ); cube_instr.Draw(cube_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // auto camera = CamMatrixf::Orbiting( Vec3f(), 4.5, Degrees(time * 35), Degrees(SineWave(time / 30.0) * 60) ); auto model = ModelMatrixf::RotationY(FullCircles(time * 0.25)) * ModelMatrixf::RotationX(FullCircles(0.25)); Vec4f lightPos(4.0f, 4.0f, -8.0f, 1.0f); prog.Use(); camera_matrix.Set(camera); model_matrix.Set(model); light_pos_cam.Set(camera * lightPos); front_color.Set(Vec3f(0.3f, 0.2f, 0.0f)); back_color.Set(Vec3f(0.2f, 0.1f, 0.0f)); gl.PolygonMode(PolygonMode::Line); torus_instr.Draw(torus_indices); front_color.Set(Vec3f(0.9f, 0.8f, 0.1f)); back_color.Set(Vec3f(1.0f, 0.9f, 0.8f)); gl.PolygonMode(PolygonMode::Fill); torus_instr.Draw(torus_indices); }
//-------------------------------------------------------------- void ofApp::setup(){ //makes audio go out of openframeworks ofSoundStreamSetup(2,0,this,44100,256,4); //these will be the nods and we name them. ControlGenerator midiNote= synth.addParameter("midiNumber"); //convert a midi note to a frequincy ControlGenerator noteFreq = ControlMidiToFreq().input(midiNote); Generator tone = SawtoothWave().freq(noteFreq); //create a tone tone= LPF12().input(tone).Q(2).cutoff((noteFreq*2) +SineWave().freq(3) *0.5* noteFreq); //trigger ControlGenerator envelopeTrigger = synth.addParameter("trigger"); Generator toneWithEnvelope = tone * ADSR().attack(0.01).decay(1.5).sustain(0).release(0).trigger(envelopeTrigger).legato(true); Generator toneWithDelay= StereoDelay(0.5,.7).input(toneWithEnvelope).wetLevel(0.1).feedback(0.2); synth.setOutputGen(toneWithDelay); // arduino bit ard.connect("COM4", 57600); ofAddListener(ard.EInitialized, this, &ofApp::setupArd); }
void Render(ExampleClock& clock) { if(long(clock.Now().Seconds()) % 4 == 0) { status += clock.Interval().Seconds(); } else if(status != double(long(status))) { if(status - double(long(status)) < 0.5) status = double(long(status)); else status = 1.0 + double(long(status)); } gl.Clear().ColorBuffer().DepthBuffer(); point_prog.status = GLfloat(0.5 - 0.5 * CosineWave(status * 0.5)); CamMatrixf camera = CamMatrixf::Orbiting( Vec3f(), 5.5f, FullCircles(clock.Now().Seconds() / 19.0), Degrees(45 + SineWave(clock.Now().Seconds() / 15.0) * 40)); point_prog.camera_matrix.Set(camera); point_prog.model_matrix.Set( ModelMatrixf::RotationX(RightAngles(status))); shape.Draw(); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // auto lightAzimuth = FullCircles(time * -0.5); light_pos.Set( Vec3f( Cos(lightAzimuth), 1.0f, Sin(lightAzimuth) ) * 2.0f ); // camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 3.0f, Degrees(-45), Degrees(SineWave(time / 30.0) * 70) ) ); // set the model matrix model_matrix.Set( ModelMatrixf::RotationY(FullCircles(time * 0.05)) ); cube.Bind(); gl.CullFace(Face::Back); cube_instr.Draw(cube_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); // // set the matrix for camera orbiting the origin camera_matrix.Set( CamMatrixf::Orbiting( Vec3f(), 3.5, Degrees(time * 35), Degrees(SineWave(time / 20.0) * 60) ) ); // set the model matrix model_matrix.Set( ModelMatrixf::RotationY(FullCircles(time * 0.25)) * ModelMatrixf::RotationX(FullCircles(0.25)) ); gl.PolygonMode(PolygonMode::Line); gl.CullFace(Face::Front); torus_instr.Draw(torus_indices); // gl.PolygonMode(PolygonMode::Fill); gl.CullFace(Face::Back); torus_instr.Draw(torus_indices); }
//-------------------------------------------------------------- void testApp::setup(){ ofSoundStreamSetup(2, 0, this, 44100, 256, 4); // create a new oscillator which we'll use for the actual audio signal // create a sine wave we'll use for some vibrato float frequency = 440; Generator tone = SawtoothWave().freq(frequency); // Generator tone = Noise(); // Generator tone = SquareWave().freq(frequency); // Generator tone = TriangleWave().freq(frequency); // Generator tone = RectWave().freq(frequency); tone = LPF12().input(tone).Q(100).cutoff(frequency*2 + SineWave().freq(3) * 1.5 * frequency); ControlGenerator envelopeTrigger = synth.addParameter("trigger"); Generator env = ADSR().attack(0.001).decay(0.5).sustain(0).release(0).trigger(envelopeTrigger).legato(true); Generator output = tone * env; // set the synth's final output generator synth.setOutputGen( output ); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); int period = int(time * 0.125); if(prev_period < period) { if(period % 2) gl.PolygonMode(PolygonMode::Line); else gl.PolygonMode(PolygonMode::Fill); prev_period = period; } auto camera = CamMatrixf::Orbiting( Vec3f(0.0f, 2.0f, 0.0f), 17.0f - CosineWave(time / 31.0f) * 10.0f, FullCircles(time / 43.0f), Degrees(45 - SineWave(time / 29.0f) * 35) ); camera_matrix.Set(camera); camera_position.Set(camera.Position()); anim_time.Set(time); plane_instr.Draw(plane_indices); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto camera = CamMatrixf::Orbiting( Vec3f(), 16.0, FullCircles(time * 0.1), Degrees(SineWave(time / 20.0) * 30) ); // use the picking program pick_prog.Use(); Uniform<Mat4f>(pick_prog, "CameraMatrix").Set(camera); // query the number of values written to the feedabck buffer GLuint picked_count = 0; { Query::Execution<GLuint> query_exec( count_query, Query::Target:: TransformFeedbackPrimitivesWritten, picked_count ); TransformFeedback::Activator xfb_act( TransformFeedbackPrimitiveType::Points ); // draw 36 instances of the cube // the vertex shader will take care of their placement cube_instr.Draw(cube_indices, 36); // xfb_act.Finish(); query_exec.WaitForResult(); } std::map<GLfloat, GLint> picked_objs; { picked_instances.Bind(Buffer::Target::TransformFeedback); BufferTypedMap<DepthAndID> picked_instances_map( Buffer::Target::TransformFeedback, BufferMapAccess::Read ); picked_objs.insert( picked_instances_map.Data(), picked_instances_map.Data()+picked_count ); } draw_prog.Use(); Uniform<GLint> picked(draw_prog, "Picked"); if(picked_objs.empty()) picked = -1; else picked = picked_objs.begin()->second; Uniform<Mat4f>(draw_prog, "CameraMatrix").Set(camera); // draw 36 instances of the cube // the vertex shader will take care of their placement cube_instr.Draw(cube_indices, 36); }