本文整理汇总了C++中shapes::ShapeWrapper::UseInProgram方法的典型用法代码示例。如果您正苦于以下问题:C++ ShapeWrapper::UseInProgram方法的具体用法?C++ ShapeWrapper::UseInProgram怎么用?C++ ShapeWrapper::UseInProgram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapes::ShapeWrapper
的用法示例。
在下文中一共展示了ShapeWrapper::UseInProgram方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParallaxExample
ParallaxExample()
: prog(make_prog())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, camera_position(prog, "CameraPosition")
, light_position(prog, "LightPosition")
, shape(
List("Position")("TexCoord").Get(),
shapes::Plane(
Vec3f(),
Vec3f(1.0f, 0.0f, 0.0f),
Vec3f(0.0f, 0.0f, -1.0f),
32,
32)) {
shape.UseInProgram(prog);
auto tex_image = images::LoadTexture("stones_color_hmap");
Texture::Active(0);
try {
UniformSampler(prog, "ColorMap").Set(0);
gl.Bound(Texture::Target::_2D, color_tex)
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::Repeat)
.WrapT(TextureWrap::Repeat)
.Image2D(tex_image)
.GenerateMipmap();
} catch(Error&) {
}
Texture::Active(1);
try {
UniformSampler(prog, "BumpMap").Set(1);
gl.Bound(Texture::Target::_2D, bump_tex)
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::Repeat)
.WrapT(TextureWrap::Repeat)
.Image2D(
images::NormalMap(tex_image, images::NormalMap::FromAlpha()))
.GenerateMipmap();
} catch(Error&) {
}
gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
gl.ClearDepth(1.0f);
(Capability::DepthTest) << true;
(Capability::CullFace) << false;
(Functionality::ClipDistance | 0) << true;
(Functionality::ClipDistance | 1) << true;
(Functionality::ClipDistance | 2) << true;
}
示例2: ParallaxMapExample
ParallaxMapExample()
: prog(make())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, camera_position(prog, "CameraPosition")
, light_position(prog, "LightPosition")
, shape(
List("Position")("Normal")("Tangent")("TexCoord").Get(),
shapes::Torus(1.0f, 0.5, 72, 48)) {
shape.UseInProgram(prog);
auto tex_image = images::LoadTexture("bricks_color_hmap");
Texture::Active(0);
try {
UniformSampler(prog, "ColorMap").Set(0);
gl.Bound(Texture::Target::_2D, color_tex)
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::Repeat)
.WrapT(TextureWrap::Repeat)
.Image2D(tex_image)
.GenerateMipmap();
} catch(Error&) {
}
Texture::Active(1);
try {
UniformSampler(prog, "BumpMap").Set(1);
gl.Bound(Texture::Target::_2D, bump_tex)
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::Repeat)
.WrapT(TextureWrap::Repeat)
.Image2D(
images::NormalMap(tex_image, images::NormalMap::FromAlpha()))
.GenerateMipmap();
} catch(Error&) {
}
gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Disable(Capability::CullFace);
gl.Enable(Functionality::ClipDistance, 0);
gl.Enable(Functionality::ClipDistance, 1);
gl.Enable(Functionality::ClipDistance, 2);
}
示例3: shape
//.........这里部分代码省略.........
"uniform vec3 LightPosition;"
"flat in mat3 geomPositionFront;"
"flat in mat3 geomTexCoordFront;"
"flat in vec3 geomWFront;"
"noperspective in vec3 geomBarycentric;"
"in vec3 geomPosition;"
"in vec3 geomTexCoord;"
"out vec3 fragColor;"
"vec3 vcdiv(vec3 a, vec3 b)"
"{"
" return vec3(a.x/b.x, a.y/b.y, a.z/b.z);"
"}"
"void main(void)"
"{"
" const vec3 one = vec3(1.0, 1.0, 1.0);"
" vec3 bzfv = vcdiv(geomBarycentric,geomWFront);"
" vec3 p0 = geomPosition;"
" vec3 p1 = (geomPositionFront*bzfv)/dot(one,bzfv);"
" vec3 tc0 = geomTexCoord;"
" vec3 tc1 = (geomTexCoordFront*bzfv)/dot(one,bzfv);"
" ivec2 ts = textureSize(BumpMap, 0);"
" int mts = max(ts.x, ts.y);"
" vec2 dtc = tc1.xy - tc0.xy;"
" float mdtc = max(abs(dtc.x), abs(dtc.y));"
" int nsam = max(min(int(mdtc*mts), mts/2), 1);"
" float step = 1.0 / nsam;"
" for(int s=0; s<=nsam; ++s)"
" {"
" vec3 tc = mix(tc1, tc0, s*step);"
" vec4 bm = texture(BumpMap, tc.xy);"
" if(tc.z <= bm.w)"
" {"
" vec3 p = mix(p1, p0, s*step);"
" vec3 ldir = normalize(LightPosition - p);"
" float l = max(dot(ldir, bm.xzy), 0.0)*1.3;"
" fragColor = texture(ColorMap, tc.xy).rgb*l;"
" return;"
" }"
" }"
" discard;"
"}"
)).Compile();
prog.AttachShader(fs);
prog.Link();
prog.Use();
shape.UseInProgram(prog);
auto tex_image = images::LoadTexture("stones_color_hmap");
Texture::Active(0);
try
{
UniformSampler(prog, "ColorMap").Set(0);
auto bound_tex = Bind(color_tex, Texture::Target::_2D);
bound_tex.Image2D(tex_image);
bound_tex.GenerateMipmap();
bound_tex.MinFilter(TextureMinFilter::LinearMipmapLinear);
bound_tex.MagFilter(TextureMagFilter::Linear);
bound_tex.WrapS(TextureWrap::Repeat);
bound_tex.WrapT(TextureWrap::Repeat);
}
catch(Error&){ }
Texture::Active(1);
try
{
UniformSampler(prog, "BumpMap").Set(1);
auto bound_tex = Bind(bump_tex, Texture::Target::_2D);
bound_tex.Image2D(
images::NormalMap(
tex_image,
images::NormalMap::FromAlpha()
)
);
bound_tex.GenerateMipmap();
bound_tex.MinFilter(TextureMinFilter::LinearMipmapLinear);
bound_tex.MagFilter(TextureMagFilter::Linear);
bound_tex.WrapS(TextureWrap::Repeat);
bound_tex.WrapT(TextureWrap::Repeat);
}
catch(Error&){ }
gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Disable(Capability::CullFace);
gl.Enable(Functionality::ClipDistance, 0);
gl.Enable(Functionality::ClipDistance, 1);
gl.Enable(Functionality::ClipDistance, 2);
}
示例4: SkyBoxExample
//.........这里部分代码省略.........
" float a = 0.1;"
" fragColor = "
" 0.1*vec3(1.0, 1.0, 1.0)*(a+l)+"
" 0.9*sky_color(normalize(vertViewRefl));"
"}");
shape_fs.Compile();
shape_prog.AttachShader(shape_fs);
FragmentShader sky_fs;
sky_fs.Source(
"#version 140\n"
"const float WorldRadius = 6371000;"
"const float AtmThickness = 50000;"
"const vec3 AirColor = vec3(0.32, 0.36, 0.45);"
"const vec3 LightColor = vec3(1.0, 1.0, 1.0);"
"uniform vec3 SunPosition;"
"uniform samplerCube EnvMap;"
"float atm_intersection(vec3 v)"
"{"
" const vec3 c = vec3(0.0, -WorldRadius, 0.0);"
" const float r = WorldRadius + AtmThickness;"
" const float c_c = dot(-c, -c);"
" float v_c = dot( v, -c);"
" return (-v_c + sqrt(v_c*v_c - c_c + r*r))/AtmThickness;"
"}"
"vec3 sky_color(vec3 vd)"
"{"
" vec3 up = vec3(0.0, 1.0, 0.0);"
" vec3 ld = normalize(SunPosition);"
" vec4 cl = texture(EnvMap, vd);"
" float ai = atm_intersection(vd);"
" float al = max(dot(ld, up) + 0.12, 0.0);"
" float vl = max(dot(vd, ld), 0.0);"
" float ct = (1.0-cl.a)*cl.b;"
" vec3 ac = max(LightColor-AirColor*pow(ai, 0.33), vec3(0.0, 0.0, "
"0.0));"
" vec3 Sun = "
" ac*(vl>0.995+0.004*al ? 1.0:0.0);"
" vec3 Air = "
" min(AirColor*sqrt(pow(al,0.25)*ai), vec3(al, al, al)*1.5)+"
" ac*pow(min(vl+0.001*ai, 1.0), 1024.0/pow(ai, 2.0))+"
" ac*(vl/(1.0+pow(3.0*al, 8.0)))*pow(ai, 0.6)*0.5;"
" vec3 Clouds ="
" ac*pow(min(vl*(cl.g+cl.b), 1.015), 64.0)*pow(ct, 2.0)+"
" ac*pow(min(vl*cl.g+cl.b, 1.020), 32.0)*ct+"
" ac*pow(min(vl*cl.g*cl.b, 1.010), 16.0)*pow(ct, 0.5)+"
" ac*0.7*min(cl.g + cl.b*0.5, 1.0)*al+"
" ac*(cl.g*(1.0-cl.b*0.2)*5.0)*pow(1.0-al, 2.0)*(al)+"
" LightColor*0.5*min(al + cl.g*0.4+cl.b*0.1, 1.0)*sqrt(al);"
" return mix(Air, Clouds, cl.a*(1.0-cl.r*0.8))+Sun*(1.0-cl.a);"
"}");
sky_fs.Compile();
sky_box_prog.AttachShader(sky_fs);
shape_prog.AttachShader(sky_fs);
sky_box_prog.Link();
sky_box.UseInProgram(sky_box_prog);
shape_prog.Link();
shape.UseInProgram(shape_prog);
{
ProgramUniformSampler(sky_box_prog, "EnvMap").Set(0);
ProgramUniformSampler(shape_prog, "EnvMap").Set(0);
Texture::Active(0);
gl.Bound(Texture::Target::CubeMap, env_map)
.MinFilter(TextureMinFilter::Linear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::ClampToEdge)
.WrapT(TextureWrap::ClampToEdge)
.WrapR(TextureWrap::ClampToEdge);
Texture::ImageCM(
0, images::LoadTexture("clouds01-cm_0", false, false));
Texture::ImageCM(
1, images::LoadTexture("clouds01-cm_1", false, false));
Texture::ImageCM(
2, images::LoadTexture("clouds01-cm_2", false, false));
Texture::ImageCM(
3, images::LoadTexture("clouds01-cm_3", false, false));
Texture::ImageCM(
4, images::LoadTexture("clouds01-cm_4", false, false));
Texture::ImageCM(
5, images::LoadTexture("clouds01-cm_5", false, false));
}
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
}