예제 #1
0
	void operator()(const Particles& particles)
	{
		gl.Enable(Capability::Blend);
		gl.Bind(vao);
		gl.Use(prog);
		gl.DrawElements(PrimitiveType::Points, particles.Count(), (GLuint*)0);
		gl.Disable(Capability::Blend);
	}
예제 #2
0
	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()
		);
	}
예제 #3
0
	void Render(double time)
	{
		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			3.0,
			FullCircles(time / 13.0),
			Degrees(-SineWave(time / 19.0) * 85)
		);
		camera_matrix.Set(camera);

		gl.Clear().ColorBuffer().DepthBuffer();
		gl.DrawElements(PrimitiveType::TriangleStrip, 6*5, DataType::UnsignedInt);
	}
예제 #4
0
파일: 015_graph.cpp 프로젝트: xdray/oglplus
    void Render(double time)
    {
        gl.Clear().ColorBuffer().DepthBuffer();
        //
        // set the matrix for camera orbiting the origin
        camera_matrix.Set(
            CamMatrixf::LookingAt(
                cam_path.Position(time / 9.0),
                tgt_path.Position(time / 7.0)
            )
        );

        // draw the points
        gl.DrawArrays(PrimitiveType::Points, 0, node_count * 3);
        // draw the edges
        gl.DrawElements(
            PrimitiveType::Lines,
            edge_count,
            DataType::UnsignedInt
        );
    }