本文整理汇总了C++中Framebuffer::Bind方法的典型用法代码示例。如果您正苦于以下问题:C++ Framebuffer::Bind方法的具体用法?C++ Framebuffer::Bind怎么用?C++ Framebuffer::Bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Framebuffer
的用法示例。
在下文中一共展示了Framebuffer::Bind方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderFrameShadowMap
void RenderFrameShadowMap(
const Vec3f& light_position,
const Mat4f& torus_matrix,
const Mat4f& light_proj_matrix
)
{
frame_shadow_fbo.Bind(Framebuffer::Target::Draw);
gl.Viewport(shadow_tex_side, shadow_tex_side);
gl.ClearDepthBuffer(1.0f);
gl.CullFace(Face::Back);
transf_prog.camera_matrix.Set(light_proj_matrix);
transf_prog.camera_position.Set(light_position);
// Render the torus' frame
transf_prog.model_matrix.Set(torus_matrix);
shadow_pp.Bind();
gl.Enable(Capability::PolygonOffsetFill);
torus.Draw(
[](GLuint phase) -> bool
{
return (phase <= 3);
}
);
gl.Disable(Capability::PolygonOffsetFill);
}
示例2: RenderGlassShadowMap
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);
}
示例3: Update
void Update(double time)
{
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.hmap_1.Set(holder.HMapUnit1());
prog.hmap_2.Set(holder.HMapUnit2());
prog.time.Set(time);
screen.Use();
gl.Disable(Capability::DepthTest);
screen.Draw();
gl.Enable(Capability::DepthTest);
holder.Swap();
}
示例4: Render
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);
}
示例5: Use
void Use(void)
{
gl.ClearDepth(1.0f);
gl.ClearColor(0.9f, 0.4f, 0.4f, 1.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::CullFace);
gl.CullFace(Face::Back);
fbo.Bind(Framebuffer::Target::Draw);
gl.Viewport(tex_side, tex_side);
prog.Use();
shape.Use();
projection_matrix.Set(CamMatrixf::PerspectiveX(Degrees(48), 1.0, 1, 100));
}
示例6: size
FlowSimulator(
const images::Image& flow_map_image,
GLuint first_tex_unit
): size(1024)
, prog(size)
, holder(size, first_tex_unit, flow_map_image)
, screen(List("Position")("TexCoord").Get(), shapes::Screen(), prog)
{
Uniform<SLtoCpp<SLDataType::Sampler2D>> flow_map(prog, "FlowMap");
flow_map.Set(holder.FlowMapUnit());
fbo.Bind(Framebuffer::Target::Draw);
Framebuffer::AttachColorTexture(
Framebuffer::Target::Draw,
0,
holder.BumpMap(),
0
);
}
示例7: SetupLightMask
void SetupLightMask(void)
{
Texture::Active(light_tex_unit);
Texture::Target tex_tgt = Texture::Target::Rectangle;
light_mask.Bind(tex_tgt);
draw_prog.Use();
UniformSampler(draw_prog, "LightMap").Set(GLuint(light_tex_unit));
Texture::MinFilter(tex_tgt, TextureMinFilter::Linear);
Texture::MagFilter(tex_tgt, TextureMagFilter::Linear);
Texture::WrapS(tex_tgt, TextureWrap::ClampToEdge);
Texture::WrapT(tex_tgt, TextureWrap::ClampToEdge);
Framebuffer::Target fbo_tgt = Framebuffer::Target::Draw;
light_fbo.Bind(fbo_tgt);
Framebuffer::AttachTexture(fbo_tgt, FramebufferAttachment::Color, light_mask, 0);
Renderbuffer::Target rbo_tgt = Renderbuffer::Target::Renderbuffer;
light_rbo.Bind(rbo_tgt);
Framebuffer::AttachRenderbuffer(fbo_tgt, FramebufferAttachment::Depth, light_rbo);
}
示例8: Bind
void Bind(void)
{
fbo.Bind(Framebuffer::Target::Draw);
}
示例9: Render
void Render(double time)
{
// render into the texture
fbo.Bind(Framebuffer::Target::Draw);
gl.Viewport(tex_side, tex_side);
gl.ClearDepth(1.0f);
gl.ClearColor(0.4f, 0.9f, 0.4f, 1.0f);
gl.Clear().ColorBuffer().DepthBuffer();
torus_prog.Use();
torus_projection_matrix.Set(
CamMatrixf::PerspectiveX(Degrees(60), 1.0, 1, 30)
);
torus_camera_matrix.Set(
CamMatrixf::Orbiting(
Vec3f(),
3.5,
Degrees(time * 25),
Degrees(SineWave(time / 30.0) * 90)
)
);
torus_model_matrix.Set(
ModelMatrixf::RotationA(
Vec3f(1.0f, 1.0f, 1.0f),
FullCircles(time * 0.5)
)
);
torus.Bind();
gl.FrontFace(make_torus.FaceWinding());
torus_instr.Draw(torus_indices);
// render the textured cube
Framebuffer::BindDefault(Framebuffer::Target::Draw);
gl.Viewport(width, height);
gl.ClearDepth(1.0f);
gl.ClearColor(0.8f, 0.8f, 0.8f, 0.0f);
gl.Clear().ColorBuffer().DepthBuffer();
cube_prog.Use();
cube_projection_matrix.Set(
CamMatrixf::PerspectiveX(
Degrees(70),
double(width)/height,
1, 30
)
);
cube_camera_matrix.Set(
CamMatrixf::Orbiting(
Vec3f(),
3.0,
Degrees(time * 35),
Degrees(SineWave(time / 20.0) * 60)
)
);
cube_model_matrix.Set(
ModelMatrixf::RotationX(FullCircles(time * 0.25))
);
cube.Bind();
gl.FrontFace(make_cube.FaceWinding());
cube_instr.Draw(cube_indices);
}
示例10: RenderShadowMap
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);
}
示例11: Render
void Render(double time)
{
//
// the camera matrix
Mat4f camera = CamMatrixf::Orbiting(
Vec3f(),
6.5 + SineWave(time / 16.0) * 1.5,
FullCircles(time / 12.0),
Degrees(SineWave(time / 30.0) * 90)
);
//
// the model matrix
Mat4f model = ModelMatrixf::RotationA(
Vec3f(1.0f, 1.0f, 1.0f),
FullCircles(time / 10.0)
);
// the light position
Vec3f lightPos(0.0f, SineWave(time / 7.0) * 0.5, 0.0f);
//
SetProgramUniform(shape_prog, "LightPos", lightPos);
SetProgramUniform(depth_prog, "LightPos", lightPos);
SetProgramUniform(light_prog, "LightPos", lightPos);
//
SetProgramUniform(shape_prog, "CameraMatrix", camera);
SetProgramUniform(light_prog, "CameraMatrix", camera);
SetProgramUniform(shape_prog, "ModelMatrix", model);
SetProgramUniform(depth_prog, "ModelMatrix", model);
// render the shadow map
depth_fbo.Bind(Framebuffer::Target::Draw);
gl.DrawBuffer(ColorBuffer::None);
gl.Viewport(tex_side, tex_side);
gl.Clear().DepthBuffer();
depth_prog.Use();
shape.Bind();
shape_instr.Draw(shape_indices);
// render the output frame
Framebuffer::BindDefault(Framebuffer::Target::Draw);
gl.DrawBuffer(ColorBuffer::Back);
gl.Viewport(width, height);
gl.Clear().ColorBuffer().DepthBuffer();
shape_prog.Use();
shape.Bind();
shape_instr.Draw(shape_indices);
gl.Enable(Capability::Blend);
light_prog.Use();
SetUniform(light_prog, "ViewX", camera.Row(0).xyz());
SetUniform(light_prog, "ViewY", camera.Row(1).xyz());
SetUniform(light_prog, "ViewZ", camera.Row(2).xyz());
light.Bind();
gl.DrawArraysInstanced(
PrimitiveType::Points,
0, 1,
sample_count
);
gl.Disable(Capability::Blend);
}