本文整理汇总了C++中Context::DepthFunc方法的典型用法代码示例。如果您正苦于以下问题:C++ Context::DepthFunc方法的具体用法?C++ Context::DepthFunc怎么用?C++ Context::DepthFunc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context::DepthFunc方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Render
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();
}
示例2: attr
TorusExample(void)
: make_torus(1.0, 0.5, 18, 36)
, torus_instr(make_torus.Instructions())
, torus_indices(make_torus.Indices())
, transf_prog(make_transf_prog())
, face_prog(make_face_prog())
, frame_prog(make_frame_prog())
, projection_matrix(transf_prog, "ProjectionMatrix")
, camera_matrix(transf_prog, "CameraMatrix")
, model_matrix(transf_prog, "ModelMatrix")
, transf_time(transf_prog, "Time")
{
transf_prog.Use();
torus.Bind();
verts.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_torus.Positions(data);
Buffer::Data(Buffer::Target::Array, data);
VertexArrayAttrib attr(transf_prog, "Position");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
normals.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_torus.Normals(data);
Buffer::Data(Buffer::Target::Array, data);
VertexArrayAttrib attr(transf_prog, "Normal");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
texcoords.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_torus.TexCoordinates(data);
Buffer::Data(Buffer::Target::Array, data);
VertexArrayAttrib attr(transf_prog, "TexCoord");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
face_pp.Bind();
face_prog.Use();
face_pp.UseStages(transf_prog).Vertex().Geometry();
face_pp.UseStages(face_prog).Fragment();
frame_pp.Bind();
frame_prog.Use();
frame_pp.UseStages(transf_prog).Vertex().Geometry();
frame_pp.UseStages(frame_prog).Fragment();
gl.Bind(NoProgramPipeline());
gl.Use(NoProgram());
gl.ClearColor(0.7f, 0.6f, 0.5f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.DepthFunc(CompareFn::Less);
gl.FrontFace(make_torus.FaceWinding());
}
示例3: plane
//.........这里部分代码省略.........
, shadow_tex_side(1024)
{
NoProgram().Use();
shadow_pp.Bind();
shadow_pp.UseStages(transf_prog).Vertex();
shadow_pp.UseStages(shadow_prog).Fragment();
sketch_pp.Bind();
sketch_pp.UseStages(transf_prog).Vertex();
sketch_pp.UseStages(sketch_prog).Fragment();
line_pp.Bind();
line_pp.UseStages(transf_prog).Vertex();
line_pp.UseStages(line_prog).Geometry().Fragment();
Texture::Active(0);
sketch_prog.sketch_tex.Set(0);
{
auto bound_tex = gl.Bound(Texture::Target::_3D, sketch_texture);
for(GLuint i=0; i<sketch_tex_layers; ++i)
{
auto image = images::BrushedMetalUByte(
512, 512,
64 + i*128,
-(2+i*4), +(2+i*4),
64, 256-i*4
);
if(i == 0)
{
bound_tex.Image3D(
0,
PixelDataInternalFormat::RGB,
image.Width(),
image.Height(),
sketch_tex_layers,
0,
image.Format(),
image.Type(),
nullptr
);
}
bound_tex.SubImage3D(
0,
0, 0, i,
image.Width(),
image.Height(),
1,
image.Format(),
image.Type(),
image.RawData()
);
}
bound_tex.GenerateMipmap();
bound_tex.MinFilter(TextureMinFilter::LinearMipmapLinear);
bound_tex.MagFilter(TextureMagFilter::Linear);
bound_tex.WrapS(TextureWrap::Repeat);
bound_tex.WrapT(TextureWrap::Repeat);
bound_tex.WrapR(TextureWrap::ClampToEdge);
}
Texture::Active(1);
sketch_prog.shadow_tex.Set(1);
gl.Bound(Texture::Target::_2D, shadow_tex)
.MinFilter(TextureMinFilter::Linear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::ClampToEdge)
.WrapT(TextureWrap::ClampToEdge)
.CompareMode(TextureCompareMode::CompareRefToTexture)
.Image2D(
0,
PixelDataInternalFormat::DepthComponent32,
shadow_tex_side, shadow_tex_side,
0,
PixelDataFormat::DepthComponent,
PixelDataType::Float,
nullptr
);
gl.Bound(Framebuffer::Target::Draw, frame_shadow_fbo)
.AttachTexture(
FramebufferAttachment::Depth,
shadow_tex,
0
);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::CullFace);
gl.DepthFunc(CompareFn::LEqual);
gl.BlendFunc(BlendFn::SrcAlpha, BlendFn::OneMinusSrcAlpha);
gl.PolygonOffset(1.0, 1.0);
gl.LineWidth(1.5);
}
示例4: attr
//.........这里部分代码省略.........
VertexAttribArray attr(transf_prog, "Position");
attr.Setup(n_per_vertex, DataType::Float);
attr.Enable();
}
normals.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_torus.Normals(data);
Buffer::Data(Buffer::Target::Array, data);
VertexAttribArray attr(transf_prog, "Normal");
attr.Setup(n_per_vertex, DataType::Float);
attr.Enable();
}
texcoords.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_torus.TexCoordinates(data);
Buffer::Data(Buffer::Target::Array, data);
VertexAttribArray attr(transf_prog, "TexCoord");
attr.Setup(n_per_vertex, DataType::Float);
attr.Enable();
}
face_fs.Source(
"#version 330\n"
"in vec3 geomNormal;"
"in vec3 geomLight;"
"in float geomGlow;"
"flat in int geomTop;"
"uniform vec3 TopColor, SideColor;"
"const vec3 LightColor = vec3(1.0, 1.0, 1.0);"
"out vec4 fragColor;"
"void main(void)"
"{"
" float d = max(dot("
" normalize(geomLight),"
" normalize(geomNormal)"
" ), 0.0);"
" vec3 color;"
" if(geomTop != 0)"
" {"
" color = TopColor * d +"
" LightColor * pow(d, 8.0);"
" }"
" else"
" {"
" color = SideColor * geomGlow +"
" LightColor *"
" pow(d, 2.0) * 0.2;"
" }"
" fragColor = vec4(color, 1.0);"
"}"
);
face_fs.Compile();
face_prog.AttachShader(face_fs);
face_prog.MakeSeparable();
face_prog.Link();
ProgramUniform<Vec3f>(face_prog, "TopColor").Set(0.2f, 0.2f, 0.2f);
ProgramUniform<Vec3f>(face_prog, "SideColor").Set(0.9f, 0.9f, 0.2f);
face_pp.Bind();
face_prog.Use();
face_pp.UseStages(transf_prog).Vertex().Geometry();
face_pp.UseStages(face_prog).Fragment();
frame_fs.Source(
"#version 330\n"
"out vec4 fragColor;"
"void main(void)"
"{"
" fragColor = vec4(0.2, 0.1, 0.0, 1.0);"
"}"
);
frame_fs.Compile();
frame_prog.AttachShader(frame_fs);
frame_prog.MakeSeparable();
frame_prog.Link();
frame_pp.Bind();
frame_prog.Use();
frame_pp.UseStages(transf_prog).Vertex().Geometry();
frame_pp.UseStages(frame_prog).Fragment();
ProgramPipeline::Unbind();
Program::UseNone();
gl.ClearColor(0.7f, 0.6f, 0.5f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.DepthFunc(CompareFn::Less);
gl.FrontFace(make_torus.FaceWinding());
}
示例5: attr
TorusExample(void)
: make_torus(1.0, 0.5, 12, 12)
, torus_instr(make_torus.Instructions())
, torus_indices(make_torus.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, light_pos_cam(prog, "LightPosCam")
, front_color(prog, "FrontColor")
, back_color(prog, "BackColor")
{
vs.Source(
"#version 330\n"
"uniform mat4 ModelMatrix, CameraMatrix;"
"in vec4 Position;"
"void main(void)"
"{"
" gl_Position = CameraMatrix *"
" ModelMatrix * Position;"
"}"
);
vs.Compile();
gs.Source(
"#version 330\n"
"layout(triangles) in;"
"layout(triangle_strip, max_vertices = 8) out;"
"uniform mat4 ProjectionMatrix;"
"uniform vec4 LightPosCam;"
"out vec3 geomLightDir;"
"out float geomOpacity;"
"void main(void)"
"{"
" vec4 c = vec4(("
" gl_in[0].gl_Position.xyz+"
" gl_in[1].gl_Position.xyz+"
" gl_in[2].gl_Position.xyz "
" ) * 0.333333, 1.0);"
" for(int v = 0; v != 4; ++v)"
" {"
" vec4 b = gl_in[v%3].gl_Position;"
" vec4 a = vec4("
" b.xyz + (c.xyz - b.xyz)*0.3,"
" 1.0"
" );"
" gl_Position = ProjectionMatrix * a;"
" geomLightDir = (LightPosCam - a).xyz;"
" geomOpacity = 1.0;"
" EmitVertex();"
" gl_Position = ProjectionMatrix * b;"
" geomLightDir = (LightPosCam - b).xyz;"
" geomOpacity = 0.0;"
" EmitVertex();"
" }"
" EndPrimitive();"
"}"
);
gs.Compile();
fs.Source(
"#version 330\n"
"in vec3 geomLightDir;"
"in float geomOpacity;"
"uniform vec3 FrontColor, BackColor;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float l = length(geomLightDir);"
" vec3 color = gl_FrontFacing?"
" FrontColor:"
" BackColor;"
" fragColor = vec4(color*(4.0/l), geomOpacity);"
"}"
);
fs.Compile();
prog.AttachShader(vs);
prog.AttachShader(gs);
prog.AttachShader(fs);
prog.Link();
torus.Bind();
verts.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_torus.Positions(data);
Buffer::Data(Buffer::Target::Array, data);
prog.Use();
VertexAttribArray attr(prog, "Position");
attr.Setup(n_per_vertex, DataType::Float);
attr.Enable();
}
gl.ClearColor(0.8f, 0.7f, 0.6f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.DepthFunc(CompareFn::LEqual);
gl.FrontFace(make_torus.FaceWinding());
//.........这里部分代码省略.........