Example #1
0
osg::Camera* createInvertedYOrthoCamera(float width, float height) {
	osg::Camera* camera = createOrthoCamera(width, height);

	camera->setProjectionMatrix(createInvertedYOrthoProjectionMatrix(width, height));

	return camera;
}
Example #2
0
// A convenience wrapper for creating a proper orthographic camera using the current
// width and height.
osg::Camera* WindowManager::createParentOrthoCamera() {
    osg::Camera* camera = createOrthoCamera(_width, _height);

    camera->addChild(this);

    return camera;
}
Example #3
0
int main(int argc, char** argv) {
	osgPango::Context& context = osgPango::Context::instance();

	context.init();
	context.addGlyphRenderer("multioutline", new GlyphRendererMultiOutline());

	osgPango::TextTransform* t = new osgPango::TextTransform(osgPango::Text::COLOR_MODE_PALETTE_ONLY);

	osgPango::ColorPalette cp;

	cp.push_back(osg::Vec3(1.0f, 1.0f, 0.0f));
	cp.push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
	cp.push_back(osg::Vec3(1.0f, 1.0f, 1.0f));
	cp.push_back(osg::Vec3(0.0f, 0.0f, 0.0f));

	t->setAlpha(1.0f);
	t->setColorPalette(cp);
	t->setGlyphRenderer("multioutline");
	t->setText(
		"<span font='Cheri Liney 70'>I've got\na lovely bunch\nof coconuts!!!</span>"
		// "<span font='Sans 70'>I've got\na lovely bunch\nof coconuts!!!</span>",
	);

	t->setMatrix(osg::Matrixd::translate(osg::Vec3(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 0.0f)));
	t->setPositionAlignment(osgPango::TextTransform::POS_ALIGN_CENTER_CENTER);
	t->finalize();

	osgViewer::Viewer viewer;

	osg::Group*  group  = new osg::Group();
	osg::Camera* camera = createOrthoCamera(WINDOW_WIDTH, WINDOW_HEIGHT);
	osg::Node*   node   = osgDB::readNodeFile("cow.osg");
	
        viewer.addEventHandler(new osgViewer::StatsHandler());
        viewer.addEventHandler(new osgViewer::WindowSizeHandler());
        viewer.addEventHandler(new osgGA::StateSetManipulator(
                viewer.getCamera()->getOrCreateStateSet()
        ));

	camera->addChild(t);

	group->addChild(node);
	group->addChild(camera);

	viewer.setSceneData(group);
	viewer.getCamera()->setClearColor(osg::Vec4(0.5f, 0.5f, 0.5f, 1.0f));
	viewer.setUpViewInWindow(50, 50, WINDOW_WIDTH, WINDOW_HEIGHT);

	viewer.run();

	// osgPango::Context::instance().writeCachesToPNGFiles("osgpangotest");
	
	return 0;
}
Example #4
0
int main(int argc, char** argv) {
	osgPango::Context& context = osgPango::Context::instance();

	context.init();
	context.addGlyphRenderer("outline", new osgPango::GlyphRendererOutline(2));

	osgPango::TextTransform* t = new osgPango::TextTransform();

	t->setGlyphRenderer("outline");
	t->setText(
		"<span font='Georgia Bold 50' color='black' bgcolor='white'>"
		"osgPango\nand\nosgAnimation"
		"</span>"
	);

	t->finalize();
	
	// TODO: OMG, this is horrible. :)
	osg::Group* group = dynamic_cast<osg::Group*>(t->getChild(0));
	
	if(group) {
		osg::Geode* geode = dynamic_cast<osg::Geode*>(group->getChild(0)); 

	
		if(geode) geode->getDrawable(0)->setUpdateCallback(new GlyphSampler());
	}

	osgViewer::Viewer viewer;

	osg::Camera* camera = createOrthoCamera(WINDOW_WIDTH, WINDOW_HEIGHT);
	
	const osg::Vec2& size = t->getSize();

	// t->setPosition(osg::Vec3(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, 0.0f));
	// t->setAlignment(osgPango::TextTransform::POS_ALIGN_CENTER);

	viewer.addEventHandler(new osgViewer::StatsHandler());
	viewer.addEventHandler(new osgViewer::WindowSizeHandler());
	viewer.addEventHandler(new osgGA::StateSetManipulator(
		viewer.getCamera()->getOrCreateStateSet()
	));

	camera->addChild(t);

	viewer.setUpViewInWindow(50, 50, WINDOW_WIDTH, WINDOW_HEIGHT);
	viewer.setSceneData(camera);
	viewer.getCamera()->setClearColor(osg::Vec4(0.2f, 0.2f, 0.2f, 1.0f));

	viewer.run();

	return 0;
}
Example #5
0
int main(int argc, char** argv)
{
    osgViewer::Viewer   viewer;
    osg::ArgumentParser args(&argc, argv);

    // Make sure we have the minimum args...
    if(argc <= 2)
    {
        osg::notify(osg::FATAL) << "usage: " << args[0] << " fontfile size1 [size2 ...]" << std::endl;

        return 1;
    }


    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
    viewer.addEventHandler(new osgViewer::StatsHandler());
    viewer.addEventHandler(new osgViewer::WindowSizeHandler());

    osg::Group*  group  = new osg::Group();
    osg::Camera* camera = createOrthoCamera(1280.0f, 1024.0f);

    // Create the list of desired sizes.
    Sizes sizes;

    for(int i = 2; i < argc; i++)
    {
        if(!args.isNumber(i)) continue;

        sizes.push_back(std::atoi(args[i]));
    }

    osg::Geode* geode = new osg::Geode();

    // Add all of our osgText drawables.
    for(Sizes::const_iterator i = sizes.begin(); i != sizes.end(); i++)
    {
        std::stringstream ss;

        ss << *i << " 1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        geode->addDrawable(createLabel(ss.str(), args[1], *i));
    }

    camera->addChild(geode);

    group->addChild(camera);

    viewer.setSceneData(group);

    return viewer.run();
}
int main(int argc, char** argv) {
	osgPairo::Context& context = osgPairo::Context::instance();

	context.init();
	context.addGlyphRenderer("gradient", new GlyphRendererGradient());

	osgPairo::TextTransform* t = new osgPairo::TextTransform();

	std::ostringstream os;

	os << "<span font='Verdana Bold 40'>" << LOREM_IPSUM << "</span>";

	t->setGlyphRenderer("gradient");
	t->setText(os.str().c_str(), osgPairo::TextOptions(
		osgPairo::TextOptions::TEXT_ALIGN_CENTER,
		750
	));

	t->finalize();
	// t->setPosition(t->getOriginTranslated());

	osgViewer::Viewer viewer;

	osg::Group*  group  = new osg::Group();
	osg::Camera* camera = createOrthoCamera(800, 600);
	osg::Node*   node   = osgDB::readNodeFile("cow.osg");

        viewer.addEventHandler(new osgViewer::StatsHandler());
        viewer.addEventHandler(new osgViewer::WindowSizeHandler());
        viewer.addEventHandler(new osgGA::StateSetManipulator(
                viewer.getCamera()->getOrCreateStateSet()
        ));

	camera->addChild(t);

	group->addChild(node);
	group->addChild(camera);

	viewer.setSceneData(group);
	viewer.getCamera()->setClearColor(osg::Vec4(0.3f, 0.3f, 0.3f, 1.0f));
	viewer.setUpViewInWindow(50, 50, 800, 600);

	viewer.run();

	// osgPairo::Context::instance().writeCachesToPNGFiles("osgpangocustomrenderer");

	return 0;
}
int main(int argc, char** argv) {
	osg::ArgumentParser args(&argc, argv);
	osgViewer::Viewer   viewer(args);

	osgDB::FilePathList& paths = osgDB::getDataFilePathList();
	
	paths.push_back("../examples/osgcairodistancefield");
	paths.push_back("examples/osgcairodistancefield");
	paths.push_back(".");

	std::string vertPath = "shaders/normal-vert.glsl";
	std::string fragPath = "shaders/normal-frag.glsl";

	while(args.read("--outline")) {
		fragPath = "shaders/outline-frag.glsl";
	}

	while(args.read("--shifted")) {
		vertPath = "shaders/shifted-vert.glsl";
		fragPath = "shaders/shifted-frag.glsl";
	}

	if(args.argc() != 4) {
		OSG_FATAL << "usage: osgcairodistancefield <surface_size> <scan_size> <block_size>" << std::endl;

		return 1;
	}

	vertPath = osgDB::findDataFile(vertPath);
	fragPath = osgDB::findDataFile(fragPath);

	cairo_surface_t* distanceField = createDistanceField(
		std::atoi(args[1]),
		std::atoi(args[2]),
		std::atoi(args[3])
	);

	osg::Geode*   geode   = createDistanceFieldGeode(distanceField);
	osg::Geode*   bg      = createBackgroundGeode(WIDTH, HEIGHT);
	osg::Camera*  camera  = createOrthoCamera(WIDTH, HEIGHT);
	osg::Program* program = new osg::Program();
	osg::Shader*  vert    = osg::Shader::readShaderFile(osg::Shader::VERTEX, vertPath);
	osg::Shader*  frag    = osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragPath);

	float scale  = 1.0f;
	float aMin   = std::max(0.0f, 0.5f - 0.07f / scale);
	float aMax   = std::min(0.5f + 0.07f / scale, 1.0f);
	float radius = 1.0f;
	float ol     = std::max(double(0.2f), double(0.5 - 0.5 / radius)); 
	float oaMax0 = std::max(double(0.0f), ol - 0.07 / scale);
	float oaMax1 = std::min(ol + 0.07 / scale, double(aMin));

	osg::Uniform* color      = new osg::Uniform("Color", osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
	osg::Uniform* styleColor = new osg::Uniform("StyleColor", osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
	osg::Uniform* alphaMin   = new osg::Uniform("AlphaMin", aMin);
	osg::Uniform* alphaMax   = new osg::Uniform("AlphaMax", aMax);
	osg::Uniform* alphaMax0  = new osg::Uniform("OutlineAlphaMax0", oaMax0);
	osg::Uniform* alphaMax1  = new osg::Uniform("OutlineAlphaMax1", oaMax1);
	osg::Uniform* texture    = new osg::Uniform(osg::Uniform::SAMPLER_2D, "Texture");

	texture->set(0);

	program->addShader(vert);
	program->addShader(frag);

	osg::MatrixTransform* matrix = new osg::MatrixTransform();

	matrix->getOrCreateStateSet()->setAttributeAndModes(program);
	matrix->getOrCreateStateSet()->addUniform(color);
	matrix->getOrCreateStateSet()->addUniform(styleColor);
	matrix->getOrCreateStateSet()->addUniform(alphaMin);
	matrix->getOrCreateStateSet()->addUniform(alphaMax);
	matrix->getOrCreateStateSet()->addUniform(alphaMax0);
	matrix->getOrCreateStateSet()->addUniform(alphaMax1);
	matrix->getOrCreateStateSet()->addUniform(texture);
	matrix->addChild(geode);

	camera->addChild(matrix);
	camera->addChild(bg);

	viewer.setSceneData(camera);
	viewer.setUpViewInWindow(50, 50, WIDTH, HEIGHT);
	viewer.addEventHandler(new ScaleSet());

	int r = viewer.run();

	cairo_surface_destroy(distanceField);

	return r;
}