2008-07-16 01:21:25 +08:00
|
|
|
// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
|
|
|
|
// $Id: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
|
|
|
|
|
2008-07-16 06:30:51 +08:00
|
|
|
#include <osgDB/FileUtils>
|
2008-07-16 01:21:25 +08:00
|
|
|
#include <osgWidget/Util>
|
|
|
|
#include <osgWidget/WindowManager>
|
|
|
|
#include <osgWidget/Canvas>
|
|
|
|
|
|
|
|
const unsigned int MASK_2D = 0xF0000000;
|
|
|
|
|
|
|
|
osgWidget::Widget* createWidget(
|
2008-07-16 06:03:59 +08:00
|
|
|
const std::string& name,
|
|
|
|
osgWidget::color_type col,
|
2008-07-26 04:50:42 +08:00
|
|
|
osgWidget::Widget::Layer layer
|
2008-07-16 01:21:25 +08:00
|
|
|
) {
|
2008-07-16 06:03:59 +08:00
|
|
|
osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-07-16 06:03:59 +08:00
|
|
|
widget->setColor(col, col, col, 0.2f);
|
|
|
|
widget->setLayer(layer);
|
2008-07-16 01:21:25 +08:00
|
|
|
|
2008-07-16 06:03:59 +08:00
|
|
|
return widget;
|
2008-07-16 01:21:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2008-07-16 06:03:59 +08:00
|
|
|
osgViewer::Viewer viewer;
|
|
|
|
|
|
|
|
osgWidget::WindowManager* wm = new osgWidget::WindowManager(
|
|
|
|
&viewer,
|
|
|
|
1280.0f,
|
|
|
|
1024.0f,
|
|
|
|
MASK_2D
|
|
|
|
);
|
|
|
|
|
|
|
|
osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
|
|
|
|
|
|
|
|
canvas->attachMoveCallback();
|
|
|
|
canvas->attachScaleCallback();
|
|
|
|
|
|
|
|
canvas->addWidget(
|
|
|
|
createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW),
|
|
|
|
0.0f,
|
|
|
|
0.0f
|
|
|
|
);
|
|
|
|
|
|
|
|
canvas->addWidget(
|
|
|
|
createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE),
|
|
|
|
200.0f,
|
|
|
|
0.0f
|
|
|
|
);
|
|
|
|
|
|
|
|
canvas->addWidget(
|
|
|
|
createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
|
|
|
|
400.0f,
|
|
|
|
0.0f
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
wm->addChild(canvas);
|
|
|
|
|
|
|
|
osg::Program* program = new osg::Program();
|
|
|
|
|
|
|
|
program->addShader(osg::Shader::readShaderFile(
|
|
|
|
osg::Shader::VERTEX,
|
2008-07-16 06:30:51 +08:00
|
|
|
osgDB::findDataFile("osgWidget/osgwidgetshader-vert.glsl")
|
2008-07-16 06:03:59 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
program->addShader(osg::Shader::readShaderFile(
|
|
|
|
osg::Shader::FRAGMENT,
|
2008-07-16 06:30:51 +08:00
|
|
|
osgDB::findDataFile("osgWidget/osgwidgetshader-frag.glsl")
|
2008-07-16 06:03:59 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
|
|
|
|
|
|
|
|
return osgWidget::createExample(viewer, wm);
|
2008-07-16 01:21:25 +08:00
|
|
|
}
|