예제 #1
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
		);
	}
예제 #2
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);
	}
	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
		);
	}
	STBTruetypeExample(int argc, const char** argv)
	 : gl()
	 , tr(0, 1, 2)
	 , font(tr.LoadFont((argc>1)?argv[1]:"FreeSans"))
	 , 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"),
				oglplus::StrCRef(
				"#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
		);
	}