Beispiel #1
0
	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 RenderGlassShadowMap(
		const Vec3f& light_position,
		const Vec3f& torus_center,
		const Mat4f& torus_matrix,
		const Mat4f& light_proj_matrix
	)
	{
		glass_shadow_fbo.Bind(Framebuffer::Target::Draw);

		gl.Viewport(shadow_tex_side, shadow_tex_side);
		const GLfloat clear_color[4] = {1.0f, 1.0f, 1.0f, 0.0f};
		gl.ClearColorBuffer(0, clear_color);

		transf_prog.camera_matrix.Set(light_proj_matrix);
		transf_prog.camera_position.Set(light_position);
		transf_prog.light_proj_matrix.Set(light_proj_matrix);
		transf_prog.light_position.Set(light_position);

		// Render the torus' frame
		transf_prog.model_matrix.Set(torus_matrix);

		// setup the view clipping plane
		Planef clip_plane = Planef::FromPointAndNormal(
			torus_center,
			Normalized(light_position-torus_center)
		);
		transf_prog.clip_plane.Set(clip_plane.Equation());

		light_pp.Bind();

		light_prog.color = Vec3f(0.6f, 0.4f, 0.1f);

		gl.Disable(Capability::DepthTest);
		gl.Enable(Functionality::ClipDistance, 0);
		gl.Enable(Capability::Blend);

		for(int c=0; c!=2; ++c)
		{
			transf_prog.clip_direction.Set((c == 0)?1:-1);

			for(int p=3; p>=0; --p)
			{
				if(p % 2 == 0) gl.CullFace(Face::Front);
				else gl.CullFace(Face::Back);
				torus.Draw(
					[&p](GLuint phase) -> bool
					{
						if(p == 0 || p == 3)
						{
							return (phase == 4);
						}
						else return (phase > 4);
					}
				);
			}
		}
		gl.Disable(Capability::Blend);
		gl.Disable(Functionality::ClipDistance, 0);
		gl.Enable(Capability::DepthTest);
	}