本文整理汇总了C++中Program::Use方法的典型用法代码示例。如果您正苦于以下问题:C++ Program::Use方法的具体用法?C++ Program::Use怎么用?C++ Program::Use使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program::Use方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
double Draw(double time)
{
assert(!shapes.empty());
assert(ishape != shapes.end());
shapes::ShapeWrapper& shape = *ishape;
const double interval = 11.0;
double segment = time - shape_time;
double fade = segment*(interval-segment);
fade -= 1.0;
if(fade < 0.0) fade = 0.0;
fade = std::sqrt(fade/interval);
if(fade > 1.0) fade = 1.0;
if(segment > interval)
{
if(++ishape == shapes.end())
{
ishape = shapes.begin();
}
shape_time = time;
}
gl.Clear().DepthBuffer();
float dist = (1.0+SineWave(time / 13.0))*2.5;
projection_matrix.Set(
CamMatrixf::PerspectiveX(
Degrees(45),
1.0,
1.0+dist,
shape.BoundingSphere().Radius()*2.0+1.0+dist
)
);
camera_matrix.Set(
CamMatrixf::Orbiting(
Vec3f(),
shape.BoundingSphere().Radius()+1.5+dist,
FullCircles(time / 27.0),
Degrees(SineWave(time / 23.0) * 89)
)
);
model_matrix.Set(
ModelMatrixf::RotationA(
Vec3f(1,1,1),
FullCircles(time /-37.0)
)
);
prog.Use();
shape.Use();
shape.Draw();
return fade;
}
示例2: Render
void Render(double time)
{
fbo.Bind(Framebuffer::Target::Draw);
gl.Clear().ColorBuffer().DepthBuffer();
main_prog.Use();
cube.Bind();
camera_matrix.Set(
CamMatrixf::Orbiting(
Vec3f(),
20.5,
FullCircles(time / 20.0),
Degrees(SineWave(time / 25.0) * 30)
)
);
auto i = cube_matrices.begin(), e = cube_matrices.end();
while(i != e)
{
model_matrix.Set(*i);
ambient_color.Set(0.7f, 0.6f, 0.2f);
diffuse_color.Set(1.0f, 0.8f, 0.3f);
face_instr.Draw(face_indices);
ambient_color.Set(0.1f, 0.1f, 0.1f);
diffuse_color.Set(0.3f, 0.3f, 0.3f);
edge_instr.Draw(edge_indices);
++i;
}
dfb.Bind(Framebuffer::Target::Draw);
gl.Clear().ColorBuffer().DepthBuffer();
dof_prog.Use();
screen.Bind();
focus_depth.Set(0.6 + SineWave(time / 9.0)*0.3);
gl.Enable(Capability::Blend);
gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
gl.Disable(Capability::Blend);
}
示例3: RenderPlane
void RenderPlane(std::size_t p)
{
gl.Enable(Capability::Blend);
plane_prog.Use();
plane_normal.Set(make_plane[p].Normal());
plane[p].Bind();
plane_instr.Draw(plane_indices);
gl.Disable(Capability::Blend);
}
示例4: Reshape
void Reshape(GLuint vp_width, GLuint vp_height)
{
width = vp_width;
height = vp_height;
tex_side = width < height ? width : height;
gl.Viewport(width, height);
Mat4f projection = CamMatrixf::PerspectiveX(
Degrees(48),
float(width)/height,
1, 15
);
plane_prog.Use();
plane_proj_matrix.Set(projection);
shape_prog.Use();
shape_proj_matrix.Set(projection);
}
示例5: Render
void Render(const Mat4f& model)
{
prog.Use();
model_matrix.Set(model);
// bind the VAO
sphere.Bind();
// use the instructions to draw the sphere
// (this basically calls glDrawArrays* or glDrawElements*)
sphere_instr.Draw(sphere_indices);
}
示例6: make_prog
static Program make_prog(void)
{
VertexShader vs;
vs.Source(
"#version 130\n"
"uniform mat4 ProjectionMatrix, ModelMatrix, CameraMatrix;"
"uniform vec4 ClipPlane;"
"attribute vec4 Position;"
"attribute vec2 TexCoord;"
"varying vec2 vertTexCoord;"
"void main(void)"
"{"
" vertTexCoord = TexCoord;"
" gl_Position = "
" ModelMatrix *"
" Position;"
" gl_ClipDistance[0] = dot(ClipPlane, gl_Position);"
" gl_Position = "
" ProjectionMatrix *"
" CameraMatrix *"
" gl_Position;"
"}"
);
vs.Compile();
FragmentShader fs;
fs.Source(
"#version 130\n"
"varying vec2 vertTexCoord;"
"void main(void)"
"{"
" float i = ("
" int(vertTexCoord.x*36) % 2+"
" int(vertTexCoord.y*24) % 2"
" ) % 2;"
" if(gl_FrontFacing)"
" {"
" gl_FragColor = vec4(1-i/2, 1-i/2, 1-i/2, 1.0);"
" }"
" else"
" {"
" gl_FragColor = vec4(0+i/2, 0+i/2, 0+i/2, 1.0);"
" }"
"}"
);
fs.Compile();
Program prog;
prog.AttachShader(vs);
prog.AttachShader(fs);
prog.Link();
prog.Use();
return prog;
}
示例7: Reshape
void Reshape(GLuint width, GLuint height)
{
gl.Viewport(width, height);
auto projection = CamMatrixf::PerspectiveX(
Degrees(60),
double(width)/height,
1, 20
);
prog.Use();
projection_matrix.Set(projection);
}
示例8: Reshape
void Reshape(GLuint width, GLuint height)
{
gl.Viewport(width, height);
prog.Use();
projection_matrix.Set(
CamMatrixf::PerspectiveX(
Degrees(75),
double(width)/height,
1, 30
)
);
}
示例9: Reshape
void Reshape(GLuint width, GLuint height)
{
gl.Viewport(width, height);
prog.Use();
Uniform<Mat4f>(prog, "ProjectionMatrix").Set(
CamMatrixf::PerspectiveX(
Degrees(70),
double(width)/height,
1, 20
)
);
}
示例10: Render
void Render(double time)
{
gl.Clear().ColorBuffer().DepthBuffer();
auto camera = CamMatrixf::Orbiting(
Vec3f(),
8.5,
FullCircles(time / 5.0),
Degrees(15 + (-SineWave(time/10.0)+1.0)* 0.5 * 75)
);
ModelMatrixf model =
ModelMatrixf::Translation(0.0f, 2.5f, 0.0) *
ModelMatrixf::RotationA(
Vec3f(1.0f, 1.0f, 1.0f),
FullCircles(time / 7.0)
);
plane_prog.Use();
plane_camera_matrix.Set(camera);
plane.Bind();
gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
shape_prog.Use();
shape_camera_matrix.Set(camera);
shape_model_matrix.Set(model);
shape.Bind();
shape_instr.Draw(shape_indices);
halo_prog.Use();
halo_camera_matrix.Set(camera);
halo_model_matrix.Set(model);
gl.DepthMask(false);
gl.Enable(Capability::Blend);
shape_instr.Draw(shape_indices);
gl.Disable(Capability::Blend);
gl.DepthMask(true);
}
示例11: Render
void Render(double time)
{
gl.Clear().ColorBuffer().DepthBuffer();
auto cameraMatrix = CamMatrixf::Orbiting(
Vec3f(0.0f, 3.0f, 0.0f),
8.0f,
FullCircles(time / 12.0),
Degrees(SineWave(time / 20.0) * 80)
);
plane.Bind();
plane_prog.Use();
Uniform<Mat4f>(plane_prog, "CameraMatrix").Set(cameraMatrix);
gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4);
gl.Enable(Capability::Blend);
volume.Bind();
volume_prog.Use();
Uniform<Mat4f>(volume_prog, "CameraMatrix").Set(cameraMatrix);
Uniform<Vec3f>(volume_prog, "ViewX").Set(
cameraMatrix.Row(0).xyz()
);
Uniform<Vec3f>(volume_prog, "ViewY").Set(
cameraMatrix.Row(1).xyz()
);
Uniform<Vec3f>(volume_prog, "ViewZ").Set(
cameraMatrix.Row(2).xyz()
);
gl.DrawArraysInstanced(
PrimitiveType::Points,
0, 1,
samples
);
gl.Disable(Capability::Blend);
}
示例12: Render
void Render(double time)
{
gl.Clear().ColorBuffer().DepthBuffer();
auto lightPos = light_path.Position(time * 0.05);
auto cameraMatrix = CamMatrixf::Orbiting(
Vec3f(),
4.5f,
Degrees(0),
Degrees(SineWave(time / 20.0) * 80)
);
light.Bind();
light_prog.Use();
Uniform<Vec3f>(light_prog, "LightPos").Set(lightPos);
Uniform<Mat4f>(light_prog, "CameraMatrix").Set(cameraMatrix);
sphere_instr.Draw(sphere_indices);
clouds.Bind();
cloud_prog.Use();
Uniform<Vec3f>(cloud_prog, "LightPos").Set(lightPos);
Uniform<Mat4f>(cloud_prog, "CameraMatrix").Set(cameraMatrix);
Uniform<Vec4f>(cloud_prog, "ViewX").Set(cameraMatrix.Row(0));
Uniform<Vec4f>(cloud_prog, "ViewY").Set(cameraMatrix.Row(1));
Uniform<Vec4f>(cloud_prog, "ViewZ").Set(cameraMatrix.Row(2));
for(std::size_t i=0, n=positions.size(); i!=n; ++i)
{
cloud_tex[i].Bind(Texture::Target::_3D);
gl.DrawArraysInstanced(
PrimitiveType::Points,
i, 1,
samples
);
}
}
示例13: GLuint
Particle(const VertexShader& vs, FragmentShader&& frag)
: sphere_instr(make_sphere.Instructions())
, sphere_indices(make_sphere.Indices())
, fs(std::forward<FragmentShader>(frag))
{
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
projection_matrix = (prog/"ProjectionMatrix");
camera_matrix = (prog/"CameraMatrix");
model_matrix = (prog/"ModelMatrix");
light_pos = (prog/"LightPos");
// bind the VAO for the sphere
sphere.Bind();
const GLuint n_attr = 2;
// pointers to the vertex attribute data build functions
typedef GLuint (shapes::Sphere::*Func)(std::vector<GLfloat>&) const;
Func func[n_attr] = {
&shapes::Sphere::Positions,
&shapes::Sphere::Normals,
};
// managed references to the VBOs
Reference<Buffer> vbo[n_attr] = {verts, normals};
// vertex attribute identifiers from the shaders
const GLchar* ident[n_attr] = {"Position", "Normal"};
for(GLuint i=0; i!=n_attr; ++i)
{
// bind the VBO
vbo[i].Bind(Buffer::Target::Array);
// make the data
std::vector<GLfloat> data;
GLuint n_per_vertex = (make_sphere.*func[i])(data);
// upload the data
Buffer::Data(Buffer::Target::Array, data);
// setup the vertex attrib
VertexArrayAttrib attr(prog, ident[i]);
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
}
示例14: Use
void Use(void)
{
gl.ClearDepth(1.0f);
gl.ClearColor(0.8f, 0.8f, 0.8f, 0.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::CullFace);
gl.CullFace(Face::Back);
dfb.Bind(Framebuffer::Target::Draw);
gl.Viewport(width, height);
prog.Use();
cube.Use();
SetProjection();
}
示例15: 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));
}