Exemplo n.º 1
0
	void Render(double time)
	{
		namespace se = oglplus::smart_enums;
		gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();
		// make the camera matrix orbiting around the origin
		// at radius of 3.5 with elevation between 15 and 90 degrees
		Mat4f camera = CamMatrixf::Orbiting(
			Vec3f(),
			6.5,
			Degrees(time * 135),
			Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)*0.5*75)
		);
		ModelMatrixf model = ModelMatrixf::Translation(0.0f, 1.5f, 0.0);
		ModelMatrixf identity;
		//
		SetProgramUniform(prog_norm, "CameraMatrix", camera);
		SetProgramUniform(prog_refl, "CameraMatrix", camera);
		// draw the plane into the stencil buffer
		prog_norm.Use();

		gl.Disable(se::Blend());
		gl.Disable(se::DepthTest());
		gl.Enable(se::StencilTest());
		gl.ColorMask(false, false, false, false);
		gl.StencilFunc(se::Always(), 1, 1);
		gl.StencilOp(se::Keep(), se::Keep(), se::Replace());

		Uniform<Mat4f> model_matrix_norm(prog_norm, "ModelMatrix");
		model_matrix_norm.Set(identity);
		plane.Bind();
		gl.DrawArrays(se::TriangleStrip(), 0, 4);

		gl.ColorMask(true, true, true, true);
		gl.Enable(se::DepthTest());
		gl.StencilFunc(se::Equal(), 1, 1);
		gl.StencilOp(se::Keep(), se::Keep(), se::Keep());

		// draw the torus using the reflection program
		prog_refl.Use();
		Uniform<Mat4f>(prog_refl, "ModelMatrix").Set(model);
		torus.Bind();
		torus_instr.Draw(torus_indices);

		gl.Disable(se::StencilTest());

		prog_norm.Use();
		// draw the torus using the normal object program
		model_matrix_norm.Set(model);
		torus_instr.Draw(torus_indices);

		// blend-in the plane
		gl.Enable(se::Blend());
		gl.BlendEquation(se::Max());
		model_matrix_norm.Set(identity);
		plane.Bind();
		gl.DrawArrays(se::TriangleStrip(), 0, 4);
	}
Exemplo n.º 2
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();
		// make the camera matrix orbiting around the origin
		// at radius of 3.5 with elevation between 15 and 90 degrees
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				5.0,
				Degrees(time * 11),
				Degrees(15 + (-SineWave(0.25+time/12.5)+1.0)*0.5*75)
			)
		);
		ModelMatrixf identity;
		// make the model transformation matrix
		ModelMatrixf model =
			ModelMatrixf::Translation(0.0f, 1.5f, 0.0) *
			ModelMatrixf::RotationZ(Degrees(time * 43))*
			ModelMatrixf::RotationY(Degrees(time * 63))*
			ModelMatrixf::RotationX(Degrees(time * 79));
		// make the reflection matrix
		auto reflection = ModelMatrixf::Reflection(false, true, false);
		//
		gl.Disable(Capability::Blend);
		gl.Disable(Capability::DepthTest);
		gl.Enable(Capability::StencilTest);
		gl.ColorMask(false, false, false, false);
		gl.StencilFunc(CompareFunction::Always, 1, 1);
		gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Replace);

		gl.Bind(plane);
		model_matrix.Set(identity);
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

		gl.ColorMask(true, true, true, true);
		gl.Enable(Capability::DepthTest);
		gl.StencilFunc(CompareFunction::Equal, 1, 1);
		gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Keep);

		// draw the cube using the reflection program
		model_matrix.Set(reflection * model);
		gl.Bind(cube);
		cube_instr.Draw(cube_indices);

		gl.Disable(Capability::StencilTest);

		// draw the cube using the normal object program
		model_matrix.Set(model);
		cube_instr.Draw(cube_indices);

		// blend-in the plane
		gl.Enable(Capability::Blend);
		gl.BlendEquation(BlendEquation::Max);
		gl.Bind(plane);
		model_matrix.Set(identity);
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
	}
Exemplo n.º 3
0
	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);
	}
Exemplo n.º 4
0
	void Update(void)
	{
		gl.Viewport(size, size);

		fbo.Bind(Framebuffer::Target::Draw);
		Framebuffer::AttachColorTexture(
			Framebuffer::Target::Draw,
			1,
			holder.CurrentHeightMap(),
			0
		);
		Context::ColorBuffer draw_buffs[2] = {
			FramebufferColorAttachment::_0,
			FramebufferColorAttachment::_1
		};
		gl.DrawBuffers(draw_buffs);

		prog.Use();
		prog.tex_1.Set(holder.TexUnit1());
		prog.tex_2.Set(holder.TexUnit2());
		prog.new_drop.Set(std::rand()%size, std::rand()%size);

		vao.Bind();
		gl.DrawArrays(PrimitiveType::Points, 0, 1);

		holder.Swap();
	}
Exemplo n.º 5
0
	void Render(double time)
	{
		std::size_t metaball_count = ball_paths.size(), k = 0;
		std::vector<GLfloat> metaballs(metaball_count*4);
		for(std::size_t ball=0; ball != metaball_count; ++ball)
		{
			Vec4f pos = ball_paths[ball].Position(time / 10.0);

			for(std::size_t coord=0; coord != 4; ++coord)
				metaballs[k++] = pos.At(coord);
		}

		Texture::Image1D(
			Texture::Target::_1D,
			0,
			PixelDataInternalFormat::RGBA32F,
			metaball_count,
			0,
			PixelDataFormat::RGBA,
			PixelDataType::Float,
			metaballs.data()
		);
		gl.Clear().DepthBuffer();
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
	}
Exemplo n.º 6
0
	void Render(const PangoCairoLayout& layout)
	{
		_bitmap.Set(GLint(layout.Use()));
		_log_coords.Set(layout._log_coords);
		_tex_coords.Set(layout._tex_coords);
		_gl.DrawArrays(PrimitiveType::Points, 0, 1);
	}
Exemplo n.º 7
0
	void Render(const BitmapGlyphLayoutTpl<BitmapFont>& layout)
	{
		// we'll need the layout font's essence
		assert(layout._font._essence);
		// use the layout's font
		_use_font(*layout._font._essence);
		// use the layout's storage
		_use_layout(layout._data);

		// load the font pages referenced by the layout
		layout._font._essence->LoadPages(
			layout._pages.data(),
			layout._pages.size()
		);

		// set the Layout Width uniform value if necessary
		if(_layout_width_active)
			_layout_width.Set(layout._data._width);

		// draw the glyphs
		Context gl;
		gl.DrawArrays(
			PrimitiveType::Points,
			layout._data._offset,
			layout._data._length
		);
	}
Exemplo n.º 8
0
	void Render(double time)
	{
		// update the particle positions, ages and directions
		GLuint i = 0;
		float time_diff = (time - prev_time);
		float age_mult = 0.2f;
		while(i != positions.size())
		{
			float drag = 0.1f * (time_diff);
			if((ages[i] += time_diff * age_mult) < 1.0f)
			{
				directions[i] *= (1.0f - drag);
				positions[i] += directions[i]*time_diff;
			}
			else
			{
				ages[i] = 0.0f;
				directions[i] = NewDirection();
				positions[i] = Vec3f();
			}
			++i;
		}
		// if there are not enough particles yet
		if(i != particle_count)
		{
			float spawn_interval = 1.0f/(age_mult*particle_count);
			if(prev_spawn + spawn_interval < time)
			{
				directions.push_back(NewDirection());
				positions.push_back(Vec3f());
				ages.push_back(0.0f);
				prev_spawn = time;
			}
		}
		prev_time = time;

		assert(positions.size() == directions.size());
		assert(positions.size() == ages.size());

		// upload the particle positions
		pos_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, positions);
		// upload the particle ages
		age_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, ages);

		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				18.0f,
				FullCircles(time * 0.5),
				Degrees(45)
			)
		);

		gl.DrawArrays(PrimitiveType::Points, 0, positions.size());
	}
Exemplo n.º 9
0
	void operator()(const Particles& particles)
	{
		gl.Bind(vao);
		gl.Use(prog);
		xfb.BeginPoints();
		gl.DrawArrays(PrimitiveType::Points, 0, particles.Count());
		xfb.End();
	}
Exemplo n.º 10
0
	void Render(double /*time*/)
	{
		gl.Clear().ColorBuffer();
		// draw the lines between control points
		color = Vec3f(0.9f, 0.9f, 0.2f);
		control.Bind();
		gl.DrawArrays(PrimitiveType::LineStrip, 0, ctrl_n);
		// draw the curve
		color = Vec3f(0.1f, 0.1f, 0.1f);
		curve.Bind();
		gl.DrawArrays(PrimitiveType::LineStrip, 0, curve_n);
		// draw the control points
		color = Vec3f(0.9f, 0.0f, 0.0f);
		control.Bind();
		gl.PointSize(8.0);
		gl.DrawArrays(PrimitiveType::Points, 0, ctrl_n);
		gl.PointSize(1.0);
	}
Exemplo n.º 11
0
	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);
	}
Exemplo n.º 12
0
	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);
	}
Exemplo n.º 13
0
	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);
	}
Exemplo n.º 14
0
	void Render(double time)
	{
		fbo.Bind(Framebuffer::Target::Draw);

		gl.Clear().ColorBuffer().DepthBuffer();

		main_prog.Use();
		cube.Bind();

		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				20.5,
				FullCircles(time / 20.0),
				Degrees(SineWave(time / 25.0) * 30)
			)
		);

		auto i = cube_matrices.begin(), e = cube_matrices.end();
		while(i != e)
		{
			model_matrix.Set(*i);
			ambient_color.Set(0.7f, 0.6f, 0.2f);
			diffuse_color.Set(1.0f, 0.8f, 0.3f);
			face_instr.Draw(face_indices);

			ambient_color.Set(0.1f, 0.1f, 0.1f);
			diffuse_color.Set(0.3f, 0.3f, 0.3f);
			edge_instr.Draw(edge_indices);
			++i;
		}

		dfb.Bind(Framebuffer::Target::Draw);

		gl.Clear().ColorBuffer().DepthBuffer();

		dof_prog.Use();
		screen.Bind();

		focus_depth.Set(0.6 + SineWave(time / 9.0)*0.3);

		gl.Enable(Capability::Blend);
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
		gl.Disable(Capability::Blend);
	}
Exemplo n.º 15
0
unsigned SpectraDefaultGPUMatrixTransf::BeginTransform(
	const float* input,
	std::size_t inbufsize,
	float* /*output*/,
	std::size_t /*outbufsize*/
)
{
	using namespace oglplus;

	assert(inbufsize >= in_size);

	if(current_transform >= max_transforms)
		current_transform = 0;

	input_buf.Bind(Buffer::Target::Texture);
	Buffer::SubData(
		Buffer::Target::Texture,
		current_transform*in_size,
		in_size,
		input
	);

	prog_input_offs.Set(current_transform*in_size);

	xfbs[current_transform].Bind();

	Query::Activator qrya(
		queries[current_transform],
		Query::Target::TransformFeedbackPrimitivesWritten
	);
	TransformFeedback::Activator xfba(
		TransformFeedbackPrimitiveType::Points
	);

	Context gl;
	gl.DrawArrays(PrimitiveType::Points, 0, out_size);

	xfba.Finish();
	qrya.Finish();

	TransformFeedback::BindDefault();

	return current_transform++;
}
Exemplo n.º 16
0
    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
        );
    }
Exemplo n.º 17
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			8.5,
			FullCircles(time / 5.0),
			Degrees(15 + (-SineWave(time/10.0)+1.0)* 0.5 * 75)
		);
		ModelMatrixf model =
			ModelMatrixf::Translation(0.0f, 2.5f, 0.0) *
			ModelMatrixf::RotationA(
				Vec3f(1.0f, 1.0f, 1.0f),
				FullCircles(time / 7.0)
			);

		plane_prog.Use();
		plane_camera_matrix.Set(camera);

		plane.Bind();
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

		shape_prog.Use();
		shape_camera_matrix.Set(camera);

		shape_model_matrix.Set(model);
		shape.Bind();
		shape_instr.Draw(shape_indices);

		halo_prog.Use();
		halo_camera_matrix.Set(camera);
		halo_model_matrix.Set(model);

		gl.DepthMask(false);
		gl.Enable(Capability::Blend);
		shape_instr.Draw(shape_indices);
		gl.Disable(Capability::Blend);
		gl.DepthMask(true);
	}
Exemplo n.º 18
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		auto cameraMatrix = CamMatrixf::Orbiting(
			Vec3f(0.0f, 3.0f, 0.0f),
			8.0f,
			FullCircles(time / 12.0),
			Degrees(SineWave(time / 20.0) * 80)
		);

		plane.Bind();
		plane_prog.Use();
		Uniform<Mat4f>(plane_prog, "CameraMatrix").Set(cameraMatrix);

		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

		gl.Enable(Capability::Blend);

		volume.Bind();
		volume_prog.Use();
		Uniform<Mat4f>(volume_prog, "CameraMatrix").Set(cameraMatrix);
		Uniform<Vec3f>(volume_prog, "ViewX").Set(
			cameraMatrix.Row(0).xyz()
		);
		Uniform<Vec3f>(volume_prog, "ViewY").Set(
			cameraMatrix.Row(1).xyz()
		);
		Uniform<Vec3f>(volume_prog, "ViewZ").Set(
			cameraMatrix.Row(2).xyz()
		);
		gl.DrawArraysInstanced(
			PrimitiveType::Points,
			0, 1,
			samples
		);

		gl.Disable(Capability::Blend);
	}
Exemplo n.º 19
0
	void operator()(const Particles& particles)
	{
		gl.Bind(vao);
		gl.Use(prog);
		for(GLuint p=0; p!=particles.sort_nw.PassCount(); ++p)
		{
			Buffer::CopySubData(
				BufferTarget::CopyRead,
				BufferTarget::CopyWrite,
				0, 0, particles.Count()*sizeof(GLuint)
			);
			prog.pass.Set(p);

			xfb.BeginPoints();
			gl.DrawArrays(PrimitiveType::Points, 0, particles.Count());
			xfb.End();
		}
		Buffer::CopySubData(
			BufferTarget::CopyRead,
			BufferTarget::CopyWrite,
			0, 0, particles.Count()*sizeof(GLint)
		);
	}
Exemplo n.º 20
0
	void Render(double)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
	}
Exemplo n.º 21
0
	void Render(double /*time*/)
	{
		gl.Clear().ColorBuffer();
		// draw the curve
		gl.DrawArrays(PrimitiveType::LineStrip, 0, curve_n);
	}
Exemplo n.º 22
0
	void Draw(void)
	{
		gl.DrawArrays(PrimitiveType::Points, 0, vert_count);
	}
Exemplo n.º 23
0
    void Render(double time) {
        gl.Clear().ColorBuffer().DepthBuffer().StencilBuffer();

        auto camera = CamMatrixf::Orbiting(
          Vec3f(),
          9.0,
          FullCircles(time * 0.1),
          Degrees(15 + (-SineWave(0.25 + time / 12.5) + 1.0) * 0.5 * 75));
        ModelMatrixf identity;
        ModelMatrixf model =
          ModelMatrixf::Translation(0.0f, 2.5f, 0.0) *
          ModelMatrixf::RotationA(
            Vec3f(1.0f, 1.0f, 1.0f), FullCircles(time * 0.2));

        gl.CullFace(Face::Back);
        gl.ColorMask(true, true, true, true);
        gl.DepthMask(true);
        gl.Disable(Capability::StencilTest);

        object_prog.Use();
        object_camera_matrix.Set(camera);
        object_light_mult.Set(0.2f);

        object_model_matrix.Set(identity);
        plane.Bind();
        gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

        object_model_matrix.Set(model);
        torus.Bind();
        torus_instr.Draw(torus_indices);

        gl.ColorMask(false, false, false, false);
        gl.DepthMask(false);
        gl.Enable(Capability::StencilTest);
        gl.StencilFunc(CompareFunction::Always, 0);
        gl.StencilOpSeparate(
          Face::Front, StencilOp::Keep, StencilOp::Keep, StencilOp::Incr);
        gl.StencilOpSeparate(
          Face::Back, StencilOp::Keep, StencilOp::Keep, StencilOp::Decr);

        shadow_prog.Use();
        shadow_camera_matrix.Set(camera);
        shadow_model_matrix.Set(model);

        gl.CullFace(Face::Back);
        torus_instr.Draw(torus_indices);
        gl.CullFace(Face::Front);
        torus_instr.Draw(torus_indices);
        gl.CullFace(Face::Back);

        gl.ColorMask(true, true, true, true);
        gl.DepthMask(true);
        gl.Clear().DepthBuffer();
        gl.StencilFunc(CompareFunction::Equal, 0);
        gl.StencilOp(StencilOp::Keep, StencilOp::Keep, StencilOp::Keep);

        object_prog.Use();
        object_light_mult.Set(2.5);

        object_model_matrix.Set(identity);
        object_color.Set(0.8f, 0.7f, 0.4f);
        plane.Bind();
        gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);

        object_model_matrix.Set(model);
        object_color.Set(0.9f, 0.8f, 0.1f);
        torus.Bind();
        torus_instr.Draw(torus_indices);
    }
Exemplo n.º 24
0
 void Draw() {
     vao.Bind();
     gl.DrawArrays(PrimitiveType::Points, 0, point_count);
 }
Exemplo n.º 25
0
	void Render(double)
	{
		gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
	}