void Render() {
        using namespace oglplus;

        gl.Clear().ColorBuffer().DoIt();

        GLfloat t = GLfloat(FrameTime());

        rndr.Use();

        text_stream.str(std::string());
        text_stream << "Time: " << std::fixed << std::setw(5)
                    << std::setprecision(3) << t << " [s]";
        if(time_str != text_stream.str()) {
            time_str = text_stream.str();
            time_layout.Set(time_str);
        }

        rndr.SetCamera(CamMatrixf::Orbiting(
          Vec3f(),
          GLfloat(9.0 + SineWave(t / 7.0) * 3.0),
          -FullCircles(t / 17.0),
          Degrees(SineWave(t / 21.0) * 35)));

        rndr.SetLayoutTransform(ModelMatrixf::Translation(-3.0f, 0.7f, 1.1f));
        rndr.Render(oglp_layout);

        rndr.SetLayoutTransform(ModelMatrixf::Translation(-6.0f, -0.7f, 0.0f));
        rndr.Render(desc_layout);

        rndr.SetLayoutTransform(
          ModelMatrixf::Translation(-4.0f, -2.0f, -0.5f) *
          ModelMatrixf::Scale(0.7f, 0.7f, 0.5f));
        rndr.Render(time_layout);
    }
Пример #2
0
	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
		);
	}
Пример #3
0
	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);
	}