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

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
Line 
1// -*-c++-*- osgWidget - Code by: Jeremy Moles (cubicool) 2007-2008
2// $Id: osgwidgetshader.cpp 28 2008-03-26 15:26:48Z cubicool $
3
4#include <osgDB/FileUtils>
5#include <osgWidget/Util>
6#include <osgWidget/WindowManager>
7#include <osgWidget/Canvas>
8
9const unsigned int MASK_2D = 0xF0000000;
10
11osgWidget::Widget* createWidget(
12    const std::string&       name,
13    osgWidget::color_type    col,
14    osgWidget::Widget::Layer layer
15) {
16    osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
17
18    widget->setColor(col, col, col, 0.2f);
19    widget->setLayer(layer);
20
21    return widget;
22}
23
24int main(int argc, char** argv) {
25    osgViewer::Viewer viewer;
26
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");
35
36    canvas->attachMoveCallback();
37    canvas->attachScaleCallback();
38
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    );
50
51    canvas->addWidget(
52        createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
53        400.0f,
54        0.0f
55    );
56
57
58    wm->addChild(canvas);
59
60    osg::Program* program = new osg::Program();
61
62    program->addShader(osg::Shader::readShaderFile(
63        osg::Shader::VERTEX,
64        osgDB::findDataFile("osgWidget/osgwidgetshader-vert.glsl")
65    ));
66   
67    program->addShader(osg::Shader::readShaderFile(
68        osg::Shader::FRAGMENT,
69        osgDB::findDataFile("osgWidget/osgwidgetshader-frag.glsl")
70    ));
71
72    canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
73
74    return osgWidget::createExample(viewer, wm);
75}
Note: See TracBrowser for help on using the browser.