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);
    }
    void Reshape() {
        using namespace oglplus;

        gl.Viewport(Width(), Height());

        rndr.SetProjection(
          CamMatrixf::PerspectiveX(Degrees(60), Width() / Height(), 1, 60));
    }
Ejemplo n.º 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);
	}
Ejemplo n.º 4
0
	void Render(void)
	{
		using namespace oglplus;

		GLfloat t = GLfloat(FrameTime());
		GLfloat i = t*0.3f;
		int interval = int(i);
		GLfloat f = i - GLfloat(interval);
		if(prev_interval < interval)
		{
			LoadNext();
			prev_interval = interval;
		}

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

		rndr_opacity.Set(SineWave(f*0.5f));

		rndr.SetLayoutTransform(ModelMatrixf::TranslationZ(-20.0f+16.0f*f));
		rndr.Render(layout);
	}
Ejemplo n.º 5
0
	void LoadNext(void)
	{
		typedef oglplus::text::Direction Dir;
		struct {
			Dir direction;
			const char* text;
		} lines[] = {
			{Dir::LeftToRight, u8"Hello world"},
			{Dir::LeftToRight, u8"Nazdar svet"},
			{Dir::LeftToRight, u8"Γεια σας κόσμο"},
			{Dir::LeftToRight, u8"Привет мир"},
			{Dir::LeftToRight, u8"Witaj świecie"},
			{Dir::LeftToRight, u8"Здравей свят"},
			{Dir::LeftToRight, u8"Ahoj světe"},
			{Dir::LeftToRight, u8"Moi maailma"},
			{Dir::LeftToRight, u8"Bonjour tout le monde"},
			{Dir::LeftToRight, u8"Hallo welt"},
			{Dir::LeftToRight, u8"Բարեւ աշխարհ"},
			{Dir::LeftToRight, u8"Hej världen"},
			{Dir::LeftToRight, u8"Прывітанне свет"},
			{Dir::LeftToRight, u8"Olá mundo"},
			{Dir::LeftToRight, u8"Здраво свете"},
			{Dir::LeftToRight, u8"Zdravo svet"},
			{Dir::LeftToRight, u8"Hola mundo"},
			{Dir::LeftToRight, u8"Merhaba dünya"},
			{Dir::LeftToRight, u8"Привіт світ"},
			{Dir::LeftToRight, u8"Pozdrav svijetu"},
			{Dir::LeftToRight, u8"Hello világ"},
			{Dir::RightToLeft, u8"مرحبا العالم"},
			{Dir::LeftToRight, u8"Ciao mondo"},
			{Dir::LeftToRight, u8"Здраво светот"},
			{Dir::RightToLeft, u8"שלום עולם"},
			{Dir::LeftToRight, u8"Hei verden"}
		};
		const std::size_t line_count = sizeof(lines)/sizeof(lines[0]);

		layout.Set(lines[current_line].text);

		rndr.SetDirection(lines[current_line].direction);
		rndr_color.Set(
			0.1f+GLfloat(0.8f*std::rand())/RAND_MAX,
			0.3f+GLfloat(0.7f*std::rand())/RAND_MAX,
			0.1f+GLfloat(0.8f*std::rand())/RAND_MAX
		);

		if(++current_line >= line_count)
			current_line = 0;
	}
Ejemplo n.º 6
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
		);
	}