root/OpenSceneGraph/trunk/examples/osgwidgetshader/osgwidgetshader.cpp @ 12292

Revision 12292, 1.8 kB (checked in by robert, 3 years ago)

Ran svn propset -R svn:eol-style native . on the OpenSceneGraph

  • Property svn:eol-style set to native
RevLine 
[8588]1// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
2// $Id: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
3
[8602]4#include <osgDB/FileUtils>
[8588]5#include <osgWidget/Util>
6#include <osgWidget/WindowManager>
7#include <osgWidget/Canvas>
8
9const unsigned int MASK_2D = 0xF0000000;
10
11osgWidget::Widget* createWidget(
[8600]12    const std::string&       name,
13    osgWidget::color_type    col,
[8693]14    osgWidget::Widget::Layer layer
[8588]15) {
[8600]16    osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
[8588]17
[8600]18    widget->setColor(col, col, col, 0.2f);
19    widget->setLayer(layer);
[8588]20
[8600]21    return widget;
[8588]22}
23
24int main(int argc, char** argv) {
[8600]25    osgViewer::Viewer viewer;
[8588]26
[8600]27    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
28        &viewer,
29        1280.0f,
30        1024.0f,
31        MASK_2D
32    );
33   
34    osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
[8588]35
[8600]36    canvas->attachMoveCallback();
37    canvas->attachScaleCallback();
[8588]38
[8600]39    canvas->addWidget(
40        createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW),
41        0.0f,
42        0.0f
43    );
44   
45    canvas->addWidget(
46        createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE),
47        200.0f,
48        0.0f
49    );
[8588]50
[8600]51    canvas->addWidget(
52        createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
53        400.0f,
54        0.0f
55    );
[8588]56
57
[8600]58    wm->addChild(canvas);
[8588]59
[8600]60    osg::Program* program = new osg::Program();
[8588]61
[8600]62    program->addShader(osg::Shader::readShaderFile(
63        osg::Shader::VERTEX,
[8602]64        osgDB::findDataFile("osgWidget/osgwidgetshader-vert.glsl")
[8600]65    ));
66   
67    program->addShader(osg::Shader::readShaderFile(
68        osg::Shader::FRAGMENT,
[8602]69        osgDB::findDataFile("osgWidget/osgwidgetshader-frag.glsl")
[8600]70    ));
[8588]71
[8600]72    canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
[8588]73
[8600]74    return osgWidget::createExample(viewer, wm);
[8588]75}
Note: See TracBrowser for help on using the browser.