本文整理汇总了C++中oglplus::Context::Enable方法的典型用法代码示例。如果您正苦于以下问题:C++ Context::Enable方法的具体用法?C++ Context::Enable怎么用?C++ Context::Enable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oglplus::Context
的用法示例。
在下文中一共展示了Context::Enable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gl
DSATextureExample(int /*argc*/, const char** /*argv*/)
: gl()
, prog(make_prog())
, projection_matrix(prog, "ProjectionMatrix")
, camera_matrix(prog, "CameraMatrix")
, model_matrix(prog, "ModelMatrix")
, textured_cube(
oglplus::List("Position")("Normal")("TexCoord").Get(),
oglplus::shapes::Cube(),
prog
)
{
using namespace oglplus;
checker.target = Texture::Target::_2D;
checker.Image2D(images::CheckerRedBlack(256, 256, 8, 8));
checker.GenerateMipmap();
checker.MinFilter(TextureMinFilter::LinearMipmapLinear);
checker.MagFilter(TextureMagFilter::Linear);
checker.Anisotropy(2.0);
checker.WrapS(TextureWrap::Repeat);
checker.WrapT(TextureWrap::Repeat);
checker.Bind();
(prog/"Checker") = 0;
(prog/"LightPos") = Vec3f(10.0f, 20.0f, 30.0f);
gl.ClearColor(0.3f, 0.3f, 0.3f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::CullFace);
}
示例2:
PathExample(int, const char**)
{
using namespace oglplus;
PathNVCommand commands[] = {
PathNVCommand::MoveTo,
PathNVCommand::LineTo,
PathNVCommand::LineTo,
PathNVCommand::LineTo,
PathNVCommand::LineTo,
PathNVCommand::Close
};
GLfloat coords[] = {
0.00, 0.85,
0.65,-0.80,
-0.85, 0.30,
0.85, 0.30,
-0.65,-0.80
};
path.Commands(
sizeof(commands)/sizeof(commands[0]),
commands,
sizeof(coords)/sizeof(coords[0]),
coords
);
path.StrokeWidth(0.01);
path.JoinStyle(PathNVJoinStyle::Round);
GLfloat dash_array[] = {0.05, 0.02};
path.DashArray(
sizeof(dash_array)/sizeof(dash_array[0]),
dash_array
);
glc.MatrixMode(CompatibilityMatrixMode::Projection);
glc.LoadIdentity();
glc.MatrixMode(CompatibilityMatrixMode::Modelview);
glc.LoadIdentity();
gl.ClearColor(1.0f, 1.0f, 1.0f, 0.0f);
gl.ClearStencil(0);
gl.StencilMask(~0);
gl.StencilFunc(CompareFunction::NotEqual, 0, 0x1F);
gl.StencilOp(
StencilOperation::Keep,
StencilOperation::Keep,
StencilOperation::Zero
);
gl.Enable(Capability::StencilTest);
}
示例3: gl
STBTruetypeExample(int argc, const char** argv)
: gl()
, tr(oglplus::text::STBTrueTypeRendering(0, 1, 2))
, font(tr.LoadFont((argc>1)?argv[1]:"FreeSans"))
, oglp_layout(tr.MakeLayout(font, "OGLplus"))
, desc_layout(tr.MakeLayout(font, u8"a C++ wrapper for OpenGL©"))
, time_layout(tr.MakeLayout(font, 25))
, rndr(tr.GetRenderer(
oglplus::FragmentShader(
oglplus::ObjectDesc("Pixel color"),
oglplus::StrCRef(
"#version 330\n"
"vec4 PixelColor("
" vec4 TexelColor,"
" vec3 GlyphPosition,"
" float GlyphXOffset,"
" vec2 GlyphExtent,"
" vec2 GlyphCoord,"
" float LayoutWidth"
")"
"{"
" float g = GlyphXOffset / LayoutWidth;"
" float b = GlyphCoord.y;"
" vec3 Color = mix("
" vec3(1.0, 0.2, 0.2+0.8*b), "
" vec3(0.2, 1.0, 0.2+0.8*b), "
" g"
" );"
" return vec4(Color, TexelColor.r);"
"}")
)
)
)
{
using namespace oglplus;
rndr.Use();
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.Enable(Capability::Blend);
gl.BlendFunc(
BlendFunction::SrcAlpha,
BlendFunction::DstAlpha
);
}
示例4: gl
PangoCairoTextExample(int argc, const char** argv)
: gl()
, tr(0)
, font(tr.LoadFont((argc>2)?argv[2]:"Sans 38"))
, layout(tr.MakeLayout(font, 48))
, rndr(tr.GetRenderer(
oglplus::FragmentShader(
oglplus::ObjectDesc("Pixel color"),
"#version 330\n"
"uniform vec3 Color;"
"uniform float Opacity;"
"vec4 PixelColor("
" vec4 TexelColor,"
" vec3 GlyphPosition,"
" float GlyphXOffset,"
" vec2 GlyphExtent,"
" vec2 GlyphCoord,"
" float LayoutWidth"
")"
"{"
" return vec4(Color, TexelColor.r*Opacity);"
"}"
)
)
), rndr_color(rndr.GetUniform<oglplus::Vec3f>("Color"))
, rndr_opacity(rndr.GetUniform<GLfloat>("Opacity"))
, prev_interval(-1)
, current_line(0)
{
using namespace oglplus;
rndr.Use();
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.Enable(Capability::Blend);
gl.BlendFunc(
BlendFunction::SrcAlpha,
BlendFunction::DstAlpha
);
rndr.SetAlignment(text::Alignment::Center);
}
示例5:
TextExample(int /*argc*/, const char** /*argv*/)
: text_glyphs(128)
{
using namespace oglplus;
GLfloat font_scale = 48;
text_glyphs.GlyphRange(
PathNVFontTarget::Standard,
"Sans",
PathNVFontStyle::Bold,
0, 128,
PathNVMissingGlyph::Use,
~0,
font_scale
);
GLfloat color_gen_coeffs[9] = {
-0.6f, 0.0f, 0.8f,
0.0f, 0.0f, 0.0f,
0.5f, 0.0f, 0.5f
};
npr.ColorGen(
PathNVColor::Primary,
PathNVGenMode::ObjectBoundingBox,
PathNVColorFormat::RGB,
color_gen_coeffs
);
gl.ClearColor(1.0f, 1.0f, 1.0f, 0.0f);
gl.ClearStencil(0);
gl.StencilMask(~0);
gl.StencilFunc(CompareFunction::NotEqual, 0, 0xFF);
gl.StencilOp(
StencilOperation::Keep,
StencilOperation::Keep,
StencilOperation::Zero
);
gl.Enable(Capability::StencilTest);
}
示例6: attr
GLMBoxesExample(int, const char**)
: cube_instr(make_cube.Instructions())
, cube_indices(make_cube.Indices())
{
// Set the vertex shader source
vs.Source(
"#version 330\n"
"uniform mat4 CameraMatrix, ScaleMatrix;"
"uniform vec3 LightPos;"
"uniform float Time;"
"in vec4 Position;"
"in vec3 Normal;"
"out vec3 vertColor;"
"void main(void)"
"{"
" float angle = gl_InstanceID * 10 * 2 * 3.14159 / 360.0;"
" float ct = cos(angle+Time);"
" float st = sin(angle+Time);"
" mat4 ModelMatrix = mat4("
" ct, 0.0, st, 0.0,"
" 0.0, 1.0, 0.0, 0.0,"
" -st, 0.0, ct, 0.0,"
" 0.0, 0.0, 0.0, 1.0 "
" ) * mat4("
" 1.0, 0.0, 0.0, 0.0,"
" 0.0, 1.0, 0.0, 0.0,"
" 0.0, 0.0, 1.0, 0.0,"
" 12.0, 0.0, 0.0, 1.0 "
" ) * mat4("
" ct, -st, 0.0, 0.0,"
" st, ct, 0.0, 0.0,"
" 0.0, 0.0, 1.0, 0.0,"
" 0.0, 0.0, 0.0, 1.0 "
" );"
" gl_Position = "
" ModelMatrix *"
" ScaleMatrix *"
" Position;"
" vec3 vertLightDir = normalize(LightPos - gl_Position.xyz);"
" vec3 vertNormal = normalize(("
" ModelMatrix *"
" vec4(Normal, 0.0)"
" ).xyz);"
" gl_Position = CameraMatrix * gl_Position;"
" vertColor = abs(normalize("
" Normal -"
" vec3(1.0, 1.0, 1.0) +"
" Position.xyz*0.2"
" )) * (0.6 + 0.5*max(dot(vertNormal, vertLightDir), 0.0));"
"}"
);
// compile it
vs.Compile();
// set the fragment shader source
fs.Source(
"#version 330\n"
"in vec3 vertColor;"
"out vec3 fragColor;"
"void main(void)"
"{"
" fragColor = vertColor;"
"}"
);
// 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();
// bind the VBO for the cube vertex positions
positions.Bind(oglplus::Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Positions(data);
// upload the data
oglplus::Buffer::Data(oglplus::Buffer::Target::Array, data);
// setup the vertex attribs array for the vertices
oglplus::VertexArrayAttrib attr(prog, "Position");
attr.Setup<GLfloat>(n_per_vertex);
attr.Enable();
}
// bind the VBO for the cube normals
normals.Bind(oglplus::Buffer::Target::Array);
{
std::vector<GLfloat> data;
GLuint n_per_vertex = make_cube.Normals(data);
// upload the data
oglplus::Buffer::Data(oglplus::Buffer::Target::Array, data);
//.........这里部分代码省略.........
示例7: gl
BitmapGlyphExample(int argc, const char** argv)
: gl()
, tr(0, 1, 2)
, font(tr.LoadFont((argc>1)?argv[1]:"Sans"))
, oglp_layout(tr.MakeLayout(font, "OGLplus"))
#if !OGLPLUS_NO_UNICODE_LITERALS
, desc_layout(tr.MakeLayout(font, u8"a C++ wrapper for OpenGL©"))
#else
, desc_layout(tr.MakeLayout(font, "a C++ wrapper for OpenGL(c)"))
#endif
, time_layout(tr.MakeLayout(font, 25))
, rndr(tr.GetRenderer(
oglplus::GeometryShader(
oglplus::ObjectDesc("Layout transform"),
"#version 150\n"
"uniform mat4 ProjectionMatrix,CameraMatrix,LayoutMatrix;"
"mat4 Matrix = ProjectionMatrix*CameraMatrix*LayoutMatrix;"
"vec4 TransformLayout(vec3 GlyphPosition)"
"{"
" return Matrix * vec4(GlyphPosition, 1.0);"
"}"
),
oglplus::GeometryShader(
oglplus::ObjectDesc("Glyph transform"),
"#version 150\n"
"uniform float Time;"
"vec3 TransformGlyph("
" vec4 LogicalMetrics,"
" vec4 InkMetrics,"
" vec2 Pos,"
" float XOffs,"
" float LayoutWidth,"
" int Idx"
")"
"{"
" float a = Idx*0.7+Time*2.4;"
" return vec3("
" Pos.x+XOffs,"
" Pos.y+sin(a)*0.1,"
" cos(a)*0.05"
" );"
"}"
),
oglplus::FragmentShader(
oglplus::ObjectDesc("Pixel color"),
"#version 150\n"
"vec4 PixelColor("
" vec4 TexelColor,"
" vec3 GlyphPosition,"
" float GlyphXOffset,"
" vec2 GlyphExtent,"
" vec2 GlyphCoord,"
" float LayoutWidth"
")"
"{"
" float g = GlyphXOffset / LayoutWidth - GlyphCoord.x;"
" vec3 Color = mix("
" vec3(1.0, 0.2+0.8*g, 0.2), "
" vec3(0.2, 0.2+0.8*g, 1.0), "
" (GlyphPosition.z+0.1)/0.2"
" );"
" return vec4(Color, TexelColor.r);"
"}"
)
)
), rndr_projection_matrix(rndr.GetUniform<oglplus::Mat4f>("ProjectionMatrix"))
, rndr_camera_matrix(rndr.GetUniform<oglplus::Mat4f>("CameraMatrix"))
, rndr_layout_matrix(rndr.GetUniform<oglplus::Mat4f>("LayoutMatrix"))
, rndr_time(rndr.GetUniform<GLfloat>("Time"))
{
using namespace oglplus;
rndr.Use();
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.Enable(Capability::Blend);
gl.BlendFunc(
BlendFunction::SrcAlpha,
BlendFunction::DstAlpha
);
}
示例8: input
//.........这里部分代码省略.........
// get the poly block pointer
auto poly_ptr = object_data_data.TryGet<void*>("mpoly", nullptr);
// and the loop block pointer
auto loop_ptr = object_data_data.TryGet<void*>("mloop", nullptr);
// open the poly and loop blocks (if we have both)
if(poly_ptr && loop_ptr)
{
auto poly_data = blend_file[poly_ptr];
auto loop_data = blend_file[loop_ptr];
// get the number of polys in the block
std::size_t n_polys = poly_data.BlockElementCount();
// get the fields of poly and loop
auto poly_loopstart_field = poly_data.Field<int>("loopstart");
auto poly_totloop_field = poly_data.Field<int>("totloop");
auto loop_v_field = loop_data.Field<int>("v");
// make a vector of index data
std::vector<GLuint> is;
for(std::size_t f=0; f!=n_polys; ++f)
{
int ls = poly_loopstart_field.Get(f);
int tl = poly_totloop_field.Get(f);
for(int l=0; l!=tl; ++l)
{
int v = loop_v_field.Get(ls+l);
is.push_back(v+index_offset);
}
is.push_back(0); // primitive restart index
}
// append the values
idx_data.insert(idx_data.end(), is.begin(), is.end());
}
index_offset += n_verts;
}
}
}
catch(...)
{ }
// and get the pointer to the nex block
object_link_ptr = object_link_data.Field<void*>("next").Get();
}
meshes.Bind();
positions.Bind(Buffer::Target::Array);
{
Buffer::Data(Buffer::Target::Array, pos_data);
VertexAttribArray attr(prog, "Position");
attr.Setup<GLfloat>(3);
attr.Enable();
}
normals.Bind(Buffer::Target::Array);
{
Buffer::Data(Buffer::Target::Array, nml_data);
VertexAttribArray attr(prog, "Normal");
attr.Setup<GLfloat>(3);
attr.Enable();
}
indices.Bind(Buffer::Target::ElementArray);
Buffer::Data(Buffer::Target::ElementArray, idx_data);
element_count = idx_data.size();
// find the extremes of the mesh(es)
GLfloat min_x = pos_data[3], max_x = pos_data[3];
GLfloat min_y = pos_data[4], max_y = pos_data[4];
GLfloat min_z = pos_data[5], max_z = pos_data[5];
for(std::size_t v=1, vn=pos_data.size()/3; v!=vn; ++v)
{
GLfloat x = pos_data[v*3+0];
GLfloat y = pos_data[v*3+1];
GLfloat z = pos_data[v*3+2];
if(min_x > x) min_x = x;
if(min_y > y) min_y = y;
if(min_z > z) min_z = z;
if(max_x < x) max_x = x;
if(max_y < y) max_y = y;
if(max_z < z) max_z = z;
}
// position the camera target
camera_target = Vec3f(
(min_x + max_x) * 0.5,
(min_y + max_y) * 0.5,
(min_z + max_z) * 0.5
);
// and calculate a good value for camera distance
camera_distance = 1.1*Distance(camera_target, Vec3f(min_x, min_y, min_z))+1.0;
gl.ClearColor(0.17f, 0.22f, 0.17f, 0.0f);
gl.ClearDepth(1.0f);
gl.Enable(Capability::DepthTest);
gl.Enable(Capability::PrimitiveRestart);
}
示例9: gl
//.........这里部分代码省略.........
"#version 150\n"
"uniform mat4 ProjectionMatrix,CameraMatrix,LayoutMatrix;"
"mat4 Matrix = ProjectionMatrix*CameraMatrix*LayoutMatrix;"
"vec4 TransformLayout(vec3 GlyphPosition)"
"{"
" return Matrix * vec4(GlyphPosition, 1.0);"
"}")
),
oglplus::GeometryShader(
oglplus::ObjectDesc("Glyph transform"),
oglplus::StrCRef("#version 150\n"
"uniform float Time;"
"uniform int Axis;"
"vec3 TransformGlyph("
" vec4 LogicalMetrics,"
" vec4 InkMetrics,"
" vec2 Pos,"
" float XOffs,"
" float LayoutWidth,"
" int Idx"
")"
"{"
" float a = Idx*0.3+Time*2.4;"
" float cx = cos(a);"
" float sx = sin(a);"
" mat3 m;"
" vec3 v;"
" vec3 o = vec3(XOffs, 0, 0);"
" vec3 p = vec3(Pos, 0);"
" if(Axis == 0)"
" {"
" m = mat3("
" 1, 0, 0,"
" 0, cx, sx,"
" 0,-sx, cx "
" );"
" v = vec3(0, (InkMetrics.z-InkMetrics.w)*0.5, 0);"
" }"
" else if(Axis == 1)"
" {"
" m = mat3("
" cx, 0,-sx,"
" 0, 1, 0,"
" sx, 0, cx "
" );"
" v = vec3((InkMetrics.y-InkMetrics.x)*0.5, 0, 0);"
" }"
" else if(Axis == 2)"
" {"
" m = mat3("
" 1, 0, 0,"
" 0,-cx,-sx,"
" 0, sx,-cx "
" );"
" v = vec3(0, 0, 0);"
" }"
" return m*(p-v)+(o+v);"
"}")
),
oglplus::FragmentShader(
oglplus::ObjectDesc("Pixel color"),
oglplus::StrCRef("#version 150\n"
"vec4 PixelColor("
" vec4 TexelColor,"
" vec3 GlyphPosition,"
" float GlyphXOffset,"
" vec2 GlyphExtent,"
" vec2 GlyphCoord,"
" float LayoutWidth"
")"
"{"
" float g = GlyphXOffset / LayoutWidth;"
" vec3 Color = mix("
" vec3(1.0, 0.2, 0.2), "
" vec3(0.2, 0.4, 1.0), "
" g"
" );"
" return vec4(Color, TexelColor.r);"
"}")
)
)
), rndr_projection_matrix(rndr.GetUniform<oglplus::Mat4f>("ProjectionMatrix"))
, rndr_camera_matrix(rndr.GetUniform<oglplus::Mat4f>("CameraMatrix"))
, rndr_layout_matrix(rndr.GetUniform<oglplus::Mat4f>("LayoutMatrix"))
, rndr_time(rndr.GetUniform<GLfloat>("Time"))
, rndr_axis(rndr.GetUniform<GLint>("Axis"))
{
using namespace oglplus;
rndr.Use();
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.Enable(Capability::Blend);
gl.BlendFunc(
BlendFunction::SrcAlpha,
BlendFunction::DstAlpha
);
}
示例10: TextExample
TextExample(int /*argc*/, const char** /*argv*/)
: text("OpenGL")
, text_path(text.size())
, glyph_indices(make_glyph_indices())
, glyph_spacings(glyph_indices.size()) {
using namespace oglplus;
GLfloat font_scale = 64;
text_path.Glyphs(
PathNVFontTarget::Standard,
"Sans",
PathNVFontStyle::Bold,
text,
PathNVMissingGlyph::Use,
~0,
font_scale);
text_path.GetSpacing(
PathNVListMode::AccumAdjacentPairs,
glyph_indices,
1.0f,
1.0f,
PathNVTransformType::TranslateX,
glyph_spacings);
glyph_spacings.insert(glyph_spacings.begin(), 0);
glyph_spacings.pop_back();
glyph_indices.pop_back();
GLfloat text_left = glyph_spacings.front();
GLfloat text_right = glyph_spacings.back();
GLfloat font_min_max[2];
text_path.GetMetricRange(
PathNVMetricQuery::FontYMinBounds | PathNVMetricQuery::FontYMaxBounds,
1,
0,
font_min_max);
projection.Ortho(
text_left - 10,
text_right + 10,
font_min_max[0],
font_min_max[1],
-1.0,
+1.0);
modelview.LoadIdentity();
gl.ClearColor(1.0f, 1.0f, 1.0f, 0.0f);
gl.ClearStencil(0);
gl.StencilMask(~0);
gl.StencilFunc(CompareFunction::NotEqual, 0, 0xFF);
gl.StencilOp(
StencilOperation::Keep,
StencilOperation::Keep,
StencilOperation::Zero);
gl.Enable(Capability::StencilTest);
}