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

Revision 8600, 1.7 kB (checked in by robert, 6 years ago)

Converted tabs to four spaces

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 <osgWidget/Util>
5#include <osgWidget/WindowManager>
6#include <osgWidget/Canvas>
7
8const unsigned int MASK_2D = 0xF0000000;
9
10osgWidget::Widget* createWidget(
11    const std::string&       name,
12    osgWidget::color_type    col,
13    osgWidget::Widget::LAYER layer
14) {
15    osgWidget::Widget* widget = new osgWidget::Widget(name, 200.0f, 200.0f);
16
17    widget->setColor(col, col, col, 0.2f);
18    widget->setLayer(layer);
19
20    return widget;
21}
22
23int main(int argc, char** argv) {
24    osgViewer::Viewer viewer;
25
26    osgWidget::WindowManager* wm = new osgWidget::WindowManager(
27        &viewer,
28        1280.0f,
29        1024.0f,
30        MASK_2D
31    );
32   
33    osgWidget::Canvas* canvas = new osgWidget::Canvas("canvas");
34
35    canvas->attachMoveCallback();
36    canvas->attachScaleCallback();
37
38    canvas->addWidget(
39        createWidget("w1", 0.2f, osgWidget::Widget::LAYER_LOW),
40        0.0f,
41        0.0f
42    );
43   
44    canvas->addWidget(
45        createWidget("w2", 0.4f, osgWidget::Widget::LAYER_MIDDLE),
46        200.0f,
47        0.0f
48    );
49
50    canvas->addWidget(
51        createWidget("w3", 0.6f, osgWidget::Widget::LAYER_HIGH),
52        400.0f,
53        0.0f
54    );
55
56
57    wm->addChild(canvas);
58
59    osg::Program* program = new osg::Program();
60
61    program->addShader(osg::Shader::readShaderFile(
62        osg::Shader::VERTEX,
63        "osgWidget/osgwidgetshader-vert.glsl"
64    ));
65   
66    program->addShader(osg::Shader::readShaderFile(
67        osg::Shader::FRAGMENT,
68        "osgWidget/osgwidgetshader-frag.glsl"
69    ));
70
71    canvas->getGeode()->getOrCreateStateSet()->setAttribute(program);
72
73    return osgWidget::createExample(viewer, wm);
74}
Note: See TracBrowser for help on using the browser.