Good evening ^^

I tried to paste some code from a co-worker but it doesnt seem to work and I 
dont know why:

Main.cpp:

Code:

#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/StateSetManipulator>
#include <osgDB/ReadFile>
#include <osg/Uniform>
#include <osg/Geode>
#include <osg/Node>
#include <osg/Group>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/ShapeDrawable>
#include <osg/Shader>
#include <osg/Program>
#include <osg/ref_ptr>
#include <iostream>

int     main(int ac, char **av)
{
        osg::Vec4 red(1.0, 0.0, 0.0, 1.0);
        osg::setNotifyLevel(osg::NOTICE);

        // Viewer init
        osgViewer::Viewer viewer;

        viewer.addEventHandler(new 
osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
    viewer.addEventHandler(new osgViewer::StatsHandler());
        //viewer.addEventHandler(new osgViewer::ThreadingHandler);
    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
        viewer.setUpViewInWindow(100, 100, 800, 600);

        //root
        osg::Group* root = NULL;
        root = new osg::Group();

        //objet de la scene
        osg::Geode* MaGeode=new osg::Geode();

        // Sphere
        osg::ShapeDrawable* sd = new osg::ShapeDrawable;
        osg::Sphere* sphere = new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), 
1.5f);
        sd->setShape(sphere);
        sd->setColor(red);
        MaGeode->addDrawable(sd);

        //code to load and apply basic shader

        osg::StateSet* widgetState = MaGeode->getOrCreateStateSet();
    osg::ref_ptr<osg::Program> pgm = new osg::Program;

        //Read the shader
    osg::Shader* magnifierFrag = osgDB::readShaderFile(osg::Shader::FRAGMENT, 
"point.frag");

    if (magnifierFrag == NULL)
    {
       osg::notify(osg::NOTICE) << "Effect Not Supported !" << std::endl;
       return 0;
    }
        pgm->addShader(magnifierFrag);
        widgetState->addUniform( new osg::Uniform( "x", 50 ));
        widgetState->addUniform( new osg::Uniform( "y", 50 ));
        widgetState->addUniform(new osg::Uniform("drawWidth", 1));
    widgetState->addUniform(new osg::Uniform("drawColor", 
osg::Vec4(255,0,0,255)));
        widgetState->setAttributeAndModes(pgm, osg::StateAttribute::ON );
        root->addChild(MaGeode);
        viewer.setSceneData(root);
        viewer.run();

        return (0);
}



I thought it was the includes but I have included everything.

The program runs without the part on the shaders.
I have my red Sphere.

But as soon as i input the shader part, i have the error "Effect Not Supported 
!"

Here is the shader:


Code:
#version 110

uniform vec4 drawColor;
uniform int drawWidth;
uniform int x;
uniform int y;

void main(void)
{
        gl_FragColor = gl_Color;
        gl_FragColor.w = 1.0;
        if (x >= int(gl_FragCoord.x)-drawWidth && x <= 
int(gl_FragCoord.x)+drawWidth && 
                y >= int(gl_FragCoord.y)-drawWidth && y <= 
int(gl_FragCoord.y)+drawWidth)
        {
                gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
        }
}




Sorry if my mistake is so obvious, but it's out of my range for the moment.
Thank you if you can help!

I'll come back tomorrow.

Have a nice evening!

Ps: I just noticed that i dont know what are: drawWidth and drawColor. But if 
it's not the main problem, can you tell me?

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=15744#15744





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to