コード例 #1
0
	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();
	}
コード例 #2
0
ファイル: 030_pin_display.cpp プロジェクト: Extrunder/oglplus
	void Draw(double time, double fade)
	{
		// Shadow map
		shadows_fbo.Bind(FramebufferTarget::Draw);
		gl.Viewport(shadow_size, shadow_size);
		gl.Clear().DepthBuffer();

		auto light = CamMatrixf::Orbiting(
			Vec3f(0, side*0.25, 0),
			side*1.5,
			Degrees(-time * 27),
			Degrees(SineWave(time / 19.0)*25  + 45)
		);

		shadow_prog.fade.Set(fade);
		shadow_prog.camera_matrix.Set(light);

		shadow_prog.Use();
		shadow_vao.Bind();
		gl.Enable(Capability::PolygonOffsetFill);
		cube.Draw(side*side);
		gl.Disable(Capability::PolygonOffsetFill);
		gl.Finish();

		// On-screen
		default_fb.Bind(Framebuffer::Target::Draw);
		gl.Viewport(width, height);
		gl.Clear().ColorBuffer().DepthBuffer();

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			side*1.1,
			Degrees(time * 19),
			Degrees(SineWave(time / 20.0) * 39 + 50)
		);

		display_prog.fade.Set(fade);
		display_prog.light_pos.Set(light.Position());
		display_prog.camera_pos.Set(camera.Position());
		display_prog.light_matrix.Set(light);
		display_prog.camera_matrix.Set(camera);

		display_prog.Use();
		display_vao.Bind();
		cube.Draw(side*side);
	}
コード例 #3
0
	void Render(double time)
	{
		gl.ClearDepth(0.0f);
		gl.Clear().DepthBuffer();

		auto camera =
			CamMatrixf::Orbiting(
				objects.BoundingSphere().Center(),
				objects.BoundingSphere().Radius()*2.8,
				FullCircles(time / 19.0),
				Degrees(SineWave(time / 17.0) * 90)
			);



		depth_prog.Use();
		gl.DepthFunc(CompareFn::Greater);
		gl.CullFace(Face::Front);
		depth_prog.camera_matrix.Set(camera);
		depth_prog.model_matrix.Set(Mat4f());
		objects.Draw();

		Texture::CopyImage2D(
			Texture::Target::Rectangle,
			0,
			PixelDataInternalFormat::DepthComponent,
			0, 0,
			width,
			height,
			0
		);

		gl.ClearDepth(1.0f);
		gl.Clear().ColorBuffer().DepthBuffer();

		draw_prog.Use();
		gl.DepthFunc(CompareFn::Less);
		gl.CullFace(Face::Back);
		draw_prog.camera_matrix.Set(camera);
		draw_prog.model_matrix.Set(Mat4f());

		objects.Draw();
	}
コード例 #4
0
ファイル: 007_voronoi.cpp プロジェクト: xubingyue/oglplus
	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();
	}
コード例 #5
0
ファイル: 027_flow.cpp プロジェクト: BrainlessLabsInc/oglplus
	void Render(double time)
	{
		flow.Update(time);

		Framebuffer::BindDefault(Framebuffer::Target::Draw);
		gl.DrawBuffer(ColorBuffer::BackLeft);
		gl.Viewport(width, height);
		gl.Clear().ColorBuffer().DepthBuffer();

		screen_prog.Use();
		screen.Use();
		screen.Draw();
	}
コード例 #6
0
    void Render(ExampleClock& clock) {
        gl.Clear().ColorBuffer().DepthBuffer();

        double time = clock.Now().Seconds();

        auto langle = FullCircles(time / 23.0);
        light_position.Set(
          GLfloat(Cos(langle) * 20.0),
          GLfloat((1.2 + Sin(langle)) * 15.0),
          GLfloat(Sin(langle) * 20.0));

        double x = SineWave(time / 13.0);
        if(x + 0.93 < 0.0)
            clock.Pace(0.2);
        else
            clock.Pace(1.0);

        auto camera = CamMatrixf::Orbiting(
          Vec3f(),
          GLfloat(9.5 + x * 5.1),
          FullCircles(time / 17.0),
          Degrees(SineWave(time / 20.0) * 89));

        camera_matrix.Set(camera);
        camera_position.Set(camera.Position());

        model_matrix.Set(
          ModelMatrixf::TranslationX(+2.0f) *
          ModelMatrixf::RotationX(FullCircles(time / 13.0)));
        shape.Draw();

        model_matrix.Set(
          ModelMatrixf::TranslationX(-2.0f) *
          ModelMatrixf::RotationZ(FullCircles(time / 11.0)));
        shape.Draw();
    }
コード例 #7
0
    void Render(double time) {
        gl.Clear().ColorBuffer().DepthBuffer();

        auto camera = CamMatrixf::Orbiting(
          Vec3f(),
          2.9f,
          FullCircles(time / 17.0),
          Degrees(45 + SineWave(time / 20.0) * 40));

        camera_matrix.Set(camera);
        camera_position.Set(camera.Position());

        auto langle = FullCircles(time / 31.0);
        light_position.Set(
          GLfloat(Cos(langle) * 20.0f),
          GLfloat((1.2 + Sin(langle)) * 15.0f),
          GLfloat(Sin(langle) * 20.0f));

        shape.Draw();
    }
コード例 #8
0
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();

		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				3.0,
				Degrees(time * 35),
				Degrees(SineWave(time / 20.0) * 60)
			)
		);

		model_matrix.Set(ModelMatrixf::RotationX(FullCircles(time * 0.25)));

		assert(thread_ready);
		thread_ready->Wait();

		cube.Draw();

		parent_ready.Signal();
	}
コード例 #9
0
ファイル: 026_ssao.cpp プロジェクト: AdamSimpson/oglplus
	void Render(double time)
	{
		GLfloat bs_rad = shape.BoundingSphere().Radius()*1.2f;

		auto light =
			CamMatrixf::Orbiting(
				shape.BoundingSphere().Center(),
				shape.BoundingSphere().Radius()*10.0f,
				FullCircles(time / 23.0),
				Degrees(-CosineWave(time / 31.0) * 80)
			);

		auto camera =
			CamMatrixf::Orbiting(
				shape.BoundingSphere().Center(),
				shape.BoundingSphere().Radius()*
				GLfloat(3.2+SineWave(time / 23.0)*0.8),
				FullCircles(time / 19.0),
				Degrees(SineWave(time / 21.0) * 80)
			);

		GLfloat cam_tgt_dist = Distance(
			shape.BoundingSphere().Center(),
			camera.Position()
		);

		auto cam_proj =
			CamMatrixf::PerspectiveX(
				Degrees(45),
				width, height,
				cam_tgt_dist-bs_rad,
				cam_tgt_dist+bs_rad
			);

		auto model =
			ModelMatrixf::RotationZ(Degrees(SineWave(time / 21.0)*25))*
			ModelMatrixf::Translation(0.0f,-bs_rad*0.25f, 0.0f);

		data_prog.Use();
		data_prog.camera_matrix.Set(cam_proj*camera);
		data_prog.model_matrix.Set(model);
		data_prog.camera_position.Set(camera.Position());
		data_prog.light_position.Set(light.Position());

		data_buffer.Bind();

		gl.Enable(Capability::DepthTest);
		gl.Clear().ColorBuffer().DepthBuffer();

		shape.Use();
		shape.Draw();

		draw_prog.Use();
		draw_prog.slider.Set(GLfloat(CosineWave01(time / 11.0)*width));

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

		gl.Disable(Capability::DepthTest);
		gl.Clear().ColorBuffer();

		screen.Use();
		screen.Draw();
	}
コード例 #10
0
ファイル: 025_subroutines.cpp プロジェクト: Extrunder/oglplus
	void Render(double time)
	{
		gl.Clear().ColorBuffer().DepthBuffer();
		//
		auto camera = CamMatrixf::Orbiting(
			Vec3f(0.0, 1.5, 0.0),
			7.0 + SineWave(time / 11.0)*1.5,
			FullCircles(time / 19.0),
			Degrees(SineWave(time / 20.0) * 30 + 35)
		);
		cube_prog.camera_matrix = camera;
		cube_prog.camera_position = camera.Position();


		// shiny gray/blue checkered cube
		cube_prog.frag_subroutines.Apply(cube_prog.frag_shiny_checker);

		cube_prog.specular_factor = 32;
		cube_prog.color_1 = Vec3f(0.9, 0.8, 0.7);
		cube_prog.color_2 = Vec3f(0.3, 0.4, 0.5);
		cube_prog.tex_scale = Vec2f(4, 4);
		cube_prog.model_matrix =
			ModelMatrixf::RotationY(FullCircles(time / 7.0))*
			ModelMatrixf::Translation( 2.0, 0.0, 0.0)*
			ModelMatrixf::RotationX(Degrees(25 * time));
		cube.Draw();

		// shiny textured cube
		cube_prog.frag_subroutines.Apply(cube_prog.frag_shiny_texture);

		cube_prog.specular_factor = 16;
		cube_prog.tex_scale = Vec2f(1, 1);
		cube_prog.model_matrix =
			ModelMatrixf::RotationY(FullCircles(time / 7.0))*
			ModelMatrixf::Translation(-2.0, 0.0, 0.0)*
			ModelMatrixf::RotationX(Degrees(-17 * time));
		cube.Draw();

		// shiny yellow/black striped cube
		cube_prog.frag_subroutines.Apply(cube_prog.frag_shiny_strips);

		cube_prog.specular_factor = 32;
		cube_prog.color_1 = Vec3f(0.9, 0.9, 0.1);
		cube_prog.color_2 = Vec3f(0.1, 0.1, 0.1);
		cube_prog.tex_scale = Vec2f(16, 16);
		cube_prog.model_matrix =
			ModelMatrixf::RotationY(FullCircles(time / 7.0))*
			ModelMatrixf::Translation( 0.0, 2.0, 0.0)*
			ModelMatrixf::RotationY(Degrees(37 * time));
		cube.Draw();

		// shiny gray/green spiral cube
		cube_prog.frag_subroutines.Apply(cube_prog.frag_shiny_spiral);

		cube_prog.specular_factor = 24;
		cube_prog.color_1 = Vec3f(0.9, 0.9, 0.9);
		cube_prog.color_2 = Vec3f(0.4, 0.9, 0.4);
		cube_prog.tex_scale = Vec2f(1, 1);
		cube_prog.model_matrix =
			ModelMatrixf::RotationY(FullCircles(time / 7.0))*
			ModelMatrixf::Translation( 0.0,-2.0, 0.0)*
			ModelMatrixf::RotationY(Degrees(-13 * time));
		cube.Draw();

		// dull white/red striped cube
		cube_prog.frag_subroutines
			.Assign(
				cube_prog.pixel_light_func,
				cube_prog.dull
			).Assign(
				cube_prog.pixel_color_func,
				cube_prog.strips
			).Apply();

		cube_prog.specular_factor = 32;
		cube_prog.color_2 = Vec3f(1.0, 1.0, 1.0);
		cube_prog.color_1 = Vec3f(0.9, 0.2, 0.2);
		cube_prog.tex_scale = Vec2f(8, 6);
		cube_prog.model_matrix =
			ModelMatrixf::RotationY(FullCircles(time / 7.0))*
			ModelMatrixf::Translation( 0.0, 0.0, 2.0)*
			ModelMatrixf::RotationZ(Degrees(27 * time));
		cube.Draw();

		// dull textured cube
		cube_prog.frag_subroutines
			.Assign(
				cube_prog.pixel_color_func,
				cube_prog.texture_bgr
			).Apply();

		cube_prog.tex_scale = Vec2f(1, 1);
		cube_prog.model_matrix =
			ModelMatrixf::RotationY(FullCircles(time / 7.0))*
			ModelMatrixf::Translation( 0.0, 0.0,-2.0)*
			ModelMatrixf::RotationZ(Degrees(-23 * time));
		cube.Draw();
	}
コード例 #11
0
	void RenderShadowMap(GLuint size)
	{
		// matrices
		auto lt_proj= CamMatrixf::PerspectiveX(Degrees(12), 1.0, 85.0, 110.0);
		auto light = CamMatrixf::LookingAt(light_position, Vec3f());
		// setup the texture
		Texture::Active(shadow_tex_unit);

		mask_prog.Use();
		Uniform<Mat4f>(mask_prog, "LightMatrix").Set(lt_proj*light);
		UniformSampler(mask_prog, "ShadowMap").Set(GLuint(shadow_tex_unit));

		draw_prog.Use();
		Uniform<Mat4f>(draw_prog, "LightMatrix").Set(lt_proj*light);
		UniformSampler(draw_prog, "ShadowMap").Set(GLuint(shadow_tex_unit));

		Texture::Target tex_tgt = Texture::Target::_2D;
		shadow_map.Bind(tex_tgt);
		Texture::MinFilter(tex_tgt, TextureMinFilter::Linear);
		Texture::MagFilter(tex_tgt, TextureMagFilter::Linear);
		Texture::WrapS(tex_tgt, TextureWrap::ClampToEdge);
		Texture::WrapT(tex_tgt, TextureWrap::ClampToEdge);
		Texture::CompareMode(tex_tgt, TextureCompareMode::CompareRefToTexture);
		Texture::Image2D(
			tex_tgt,
			0,
			PixelDataInternalFormat::DepthComponent32,
			size, size,
			0,
			PixelDataFormat::DepthComponent,
			PixelDataType::Float,
			nullptr
		);

		// create shadow program
		ShadowProgram shadow_prog(vert_shader);

		// VAO for the meshes in shadow program
		VertexArray vao = meshes.VAOForProgram(shadow_prog);
		vao.Bind();

		// FBO for offscreen rendering of the shadow map
		Framebuffer::Target fbo_tgt = Framebuffer::Target::Draw;
		Framebuffer fbo;
		fbo.Bind(fbo_tgt);
		Framebuffer::AttachTexture(fbo_tgt, FramebufferAttachment::Depth, shadow_map, 0);

		// RBO for offscreen rendering
		Renderbuffer::Target rbo_tgt = Renderbuffer::Target::Renderbuffer;
		Renderbuffer rbo;
		rbo.Bind(rbo_tgt);
		Renderbuffer::Storage(rbo_tgt, PixelDataInternalFormat::RGBA, size, size);
		Framebuffer::AttachRenderbuffer(fbo_tgt, FramebufferAttachment::Color, rbo);

		// setup the matrices
		shadow_prog.projection_matrix.Set(lt_proj);
		shadow_prog.camera_matrix.Set(light);

		// setup and clear the viewport
		gl.Viewport(size, size);
		gl.Clear().DepthBuffer();

		// draw the meshes
		gl.PolygonOffset(1.0, 1.0);
		gl.Enable(Capability::PolygonOffsetFill);
		meshes.Draw();
		gl.Disable(Capability::PolygonOffsetFill);
		gl.Finish();

		// bind the default framebuffer
		DefaultFramebuffer().Bind(Framebuffer::Target::Draw);
	}
コード例 #12
0
	void operator()(void)
	{
		gl.Use(prog);
		mesh.Use();
		mesh.Draw();
	}
コード例 #13
0
	void RenderOnscreen(double)
	{
		screen_prog.Use();
		screen.Use();
		screen.Draw();
	}