本文整理汇总了C++中shapes::Cube::Tangents方法的典型用法代码示例。如果您正苦于以下问题:C++ Cube::Tangents方法的具体用法?C++ Cube::Tangents怎么用?C++ Cube::Tangents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapes::Cube
的用法示例。
在下文中一共展示了Cube::Tangents方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attr
CubeExample(void)
: cube_instr(make_cube.Instructions())
, cube_indices(make_cube.Indices())
, prog(make_prog())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, light_pos(prog, "LightPos")
{
gl.Bind(cube);
gl.Bind(Buffer::Target::Array, verts);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Positions(data);
gl.Current(Buffer::Target::Array).Data(data);
VertexArrayAttrib attr(prog, "Position");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
gl.Bind(Buffer::Target::Array, normals);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Normals(data);
gl.Current(Buffer::Target::Array).Data(data);
VertexArrayAttrib attr(prog, "Normal");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
gl.Bind(Buffer::Target::Array, tangents);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Tangents(data);
gl.Current(Buffer::Target::Array).Data(data);
VertexArrayAttrib attr(prog, "Tangent");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
gl.Bind(Buffer::Target::Array, texcoords);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.TexCoordinates(data);
gl.Current(Buffer::Target::Array).Data(data);
VertexArrayAttrib attr(prog, "TexCoord");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
// setup the textures
{
Texture::Active(0);
UniformSampler(prog, "ColorTex").Set(0);
gl.Bind(Texture::Target::_2D, colorTex);
gl.Current(Texture::Target::_2D)
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::Repeat)
.WrapT(TextureWrap::Repeat)
.Image2D(images::LoadTexture("wooden_crate"))
.GenerateMipmap();
}
{
Texture::Active(1);
UniformSampler(prog, "NormalTex").Set(1);
gl.Bind(Texture::Target::_2D, normalTex);
gl.Current(Texture::Target::_2D)
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::Repeat)
.WrapT(TextureWrap::Repeat)
.Image2D(
images::NormalMap(
images::LoadTexture("wooden_crate-hmap")
)
).GenerateMipmap();
}
//
gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::CullFace);
gl.FrontFace(make_cube.FaceWinding());
}
示例2: attr
CubeExample(void)
: cube_instr(make_cube.Instructions())
, cube_indices(make_cube.Indices())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, light_pos(prog, "LightPos")
{
namespace se = oglplus::smart_enums;
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 ProjectionMatrix, CameraMatrix, ModelMatrix;"
"in vec4 Position;"
"in vec3 Normal;"
"in vec3 Tangent;"
"in vec2 TexCoord;"
"out vec3 vertLight;"
"out vec2 vertTexCoord;"
"out mat3 NormalMatrix;"
"uniform vec3 LightPos;"
"void main(void)"
"{"
" vec3 fragNormal = mat3(ModelMatrix) * Normal;"
" vec3 fragTangent = mat3(ModelMatrix) * Tangent;"
" NormalMatrix[0] = fragTangent;"
" NormalMatrix[1] = cross(fragNormal, fragTangent);"
" NormalMatrix[2] = fragNormal;"
" gl_Position = ModelMatrix * Position;"
" vertLight = LightPos - gl_Position.xyz;"
" vertTexCoord = TexCoord;"
" gl_Position = ProjectionMatrix * CameraMatrix * gl_Position;"
"}"
);
// compile it
vs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"uniform sampler2D ColorTex, NormalTex;"
"in mat3 NormalMatrix;"
"in vec3 vertLight;"
"in vec2 vertTexCoord;"
"out vec4 fragColor;"
"void main(void)"
"{"
" float l = dot(vertLight, vertLight);"
" vec3 n = texture(NormalTex, vertTexCoord).xyz;"
" vec3 finalNormal = NormalMatrix * n;"
" float d = (l > 0.0) ? dot("
" normalize(vertLight), "
" finalNormal"
" ) / l : 0.0;"
" float i = 0.2 + 4.5*max(d, 0.0);"
" vec4 t = texture(ColorTex, vertTexCoord);"
" fragColor = vec4(t.rgb*i, 1.0);"
"}"
);
// compile it
fs.Compile();
// attach the shaders to the program
prog.AttachShader(vs);
prog.AttachShader(fs);
// link and use it
prog.Link();
prog.Use();
// bind the VAO for the cube
cube.Bind();
verts.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Positions(data);
Buffer::Data(se::Array(), data);
VertexAttribArray attr(prog, "Position");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
normals.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Normals(data);
Buffer::Data(se::Array(), data);
VertexAttribArray attr(prog, "Normal");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
tangents.Bind(Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Tangents(data);
Buffer::Data(se::Array(), data);
VertexAttribArray attr(prog, "Tangent");
attr.Setup<GLfloat>(n_per_vertex);
//.........这里部分代码省略.........
示例3: CubeExample
CubeExample()
: cube_instr(make_cube.Instructions())
, cube_indices(make_cube.Indices())
, prog(make())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, light_pos(prog, "LightPos") {
// bind the VAO for the cube
gl.Bind(cube);
gl.Bind(Buffer::Target::Array, verts);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Positions(data);
Buffer::Data(Buffer::Target::Array, data);
(prog | "Position").Setup<GLfloat>(n_per_vertex).Enable();
}
gl.Bind(Buffer::Target::Array, normals);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Normals(data);
Buffer::Data(Buffer::Target::Array, data);
(prog | "Normal").Setup<GLfloat>(n_per_vertex).Enable();
}
gl.Bind(Buffer::Target::Array, tangents);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Tangents(data);
Buffer::Data(Buffer::Target::Array, data);
(prog | "Tangent").Setup<GLfloat>(n_per_vertex).Enable();
}
gl.Bind(Buffer::Target::Array, texcoords);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.TexCoordinates(data);
Buffer::Data(Buffer::Target::Array, data);
(prog | "TexCoord").Setup<GLfloat>(n_per_vertex).Enable();
}
{
auto img = images::SphereBumpMap(512, 512, 2, 2);
Uniform<GLsizei>(prog, "BumpTexWidth").Set(img.Width());
Uniform<GLsizei>(prog, "BumpTexHeight").Set(img.Height());
UniformSampler(prog, "BumpTex").Set(0);
Texture::Active(0);
gl.Bound(Texture::Target::_2D, bumpTex)
.MinFilter(TextureMinFilter::LinearMipmapLinear)
.MagFilter(TextureMagFilter::Linear)
.WrapS(TextureWrap::Repeat)
.WrapT(TextureWrap::Repeat)
.Image2D(img)
.GenerateMipmap();
}
//
gl.ClearColor(0.1f, 0.1f, 0.1f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::CullFace);
gl.FrontFace(make_cube.FaceWinding());
}