OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Why are my shaders not being used?


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Fri Jan 19, 2018 6:45 pm    Post subject:
Why are my shaders not being used?
Reply with quote

Hi all,

The following code renders the square in red (fixed pipeline) rather green (shaders), I guess the shaders are not used.

Code:

#define GLSL330(program) "#version 150\n" #program

const char* vertSource = GLSL330
(
    void main(void)
    {
        gl_Position = ftransform();
    }
);

const char* fragSource = GLSL330
(
    void main(void)
    {
        gl_FragColor = vec4(0,1,0,1);
    }
);

////////////////////////////////////////////////////////////////////////////////
osg::ref_ptr<osg::Geode> SetupNurbsSurface()
{
    osg::ref_ptr<osg::Geode> geode = new osg::Geode();
    assert(geode);
    osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
    assert(geometry);
    osg::ref_ptr<osg::Vec3Array> vertices_osg = new osg::Vec3Array();
    assert(vertices_osg);
    osg::ref_ptr<osg::Vec3Array> normals_osg = new osg::Vec3Array();
    assert(normals_osg);
    osg::ref_ptr<osg::DrawElementsUInt> triangles_osg = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
    assert(triangles_osg);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
    assert(colors);

    // Setup.
    geode->addDrawable(geometry);
    geometry->setVertexArray(vertices_osg);
    geometry->setNormalArray(normals_osg);
    geometry->addPrimitiveSet(triangles_osg);
    geometry->setColorArray(colors);

    // Vertices.
    vertices_osg->push_back(osg::Vec3(-1.0f,  0.0f, 1.0f));
    vertices_osg->push_back(osg::Vec3(-1.0f,  0.0f, 2.0f));
    vertices_osg->push_back(osg::Vec3(-1.0f, -1.0f, 2.0f));
    vertices_osg->push_back(osg::Vec3(-1.0f, -1.0f, 1.0f));

    // Triangles (primitive sets).
    triangles_osg->push_back(0);
    triangles_osg->push_back(1);
    triangles_osg->push_back(2);
    triangles_osg->push_back(0);
    triangles_osg->push_back(2);
    triangles_osg->push_back(3);

    // Colors.
    colors->setBinding(osg::Array::BIND_OVERALL);
    colors->push_back(osg::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));

    // Normals.
    normals_osg->setBinding(osg::Array::BIND_PER_VERTEX);
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));

    // State.
    osg::ref_ptr<osg::Shader> vertShader = new osg::Shader( osg::Shader::VERTEX, vertSource );

    osg::ref_ptr<osg::Shader> fragShader = new osg::Shader( osg::Shader::FRAGMENT, fragSource );

    osg::ref_ptr<osg::Program> program = new osg::Program;
    program->addShader( vertShader.get() );
    program->addShader( fragShader.get() );

    osg::ref_ptr<osg::StateSet> state = geode->getOrCreateStateSet();
    assert(state);

    state->setAttributeAndModes( program.get(), osg::StateAttribute::ON );
//    state->addUniform("TODO");

    return geode;
}


Any idea of what is going on?

Thanks!

Regards,

Antoine[/code]
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 484
Location: France

PostPosted: Fri Jan 19, 2018 9:02 pm    Post subject:
Re: Why are my shaders not being used?
Reply with quote

look command line results
Code:

0(2) : error C7616: global function ftransform is removed after version 140

arennuit wrote:
Hi all,

The following code renders the square in red (fixed pipeline) rather green (shaders), I guess the shaders are not used.

Code:

#define GLSL330(program) "#version 150\n" #program

const char* vertSource = GLSL330
(
    void main(void)
    {
        gl_Position = ftransform();
    }
);

const char* fragSource = GLSL330
(
    void main(void)
    {
        gl_FragColor = vec4(0,1,0,1);
    }
);

////////////////////////////////////////////////////////////////////////////////
osg::ref_ptr<osg::Geode> SetupNurbsSurface()
{
    osg::ref_ptr<osg::Geode> geode = new osg::Geode();
    assert(geode);
    osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
    assert(geometry);
    osg::ref_ptr<osg::Vec3Array> vertices_osg = new osg::Vec3Array();
    assert(vertices_osg);
    osg::ref_ptr<osg::Vec3Array> normals_osg = new osg::Vec3Array();
    assert(normals_osg);
    osg::ref_ptr<osg::DrawElementsUInt> triangles_osg = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);
    assert(triangles_osg);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
    assert(colors);

    // Setup.
    geode->addDrawable(geometry);
    geometry->setVertexArray(vertices_osg);
    geometry->setNormalArray(normals_osg);
    geometry->addPrimitiveSet(triangles_osg);
    geometry->setColorArray(colors);

    // Vertices.
    vertices_osg->push_back(osg::Vec3(-1.0f,  0.0f, 1.0f));
    vertices_osg->push_back(osg::Vec3(-1.0f,  0.0f, 2.0f));
    vertices_osg->push_back(osg::Vec3(-1.0f, -1.0f, 2.0f));
    vertices_osg->push_back(osg::Vec3(-1.0f, -1.0f, 1.0f));

    // Triangles (primitive sets).
    triangles_osg->push_back(0);
    triangles_osg->push_back(1);
    triangles_osg->push_back(2);
    triangles_osg->push_back(0);
    triangles_osg->push_back(2);
    triangles_osg->push_back(3);

    // Colors.
    colors->setBinding(osg::Array::BIND_OVERALL);
    colors->push_back(osg::Vec4f(1.0f, 0.0f, 0.0f, 1.0f));

    // Normals.
    normals_osg->setBinding(osg::Array::BIND_PER_VERTEX);
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
    normals_osg->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));

    // State.
    osg::ref_ptr<osg::Shader> vertShader = new osg::Shader( osg::Shader::VERTEX, vertSource );

    osg::ref_ptr<osg::Shader> fragShader = new osg::Shader( osg::Shader::FRAGMENT, fragSource );

    osg::ref_ptr<osg::Program> program = new osg::Program;
    program->addShader( vertShader.get() );
    program->addShader( fragShader.get() );

    osg::ref_ptr<osg::StateSet> state = geode->getOrCreateStateSet();
    assert(state);

    state->setAttributeAndModes( program.get(), osg::StateAttribute::ON );
//    state->addUniform("TODO");

    return geode;
}


Any idea of what is going on?

Thanks!

Regards,

Antoine[/code]
Back to top
View user's profile Send private message Visit poster's website
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Fri Jan 19, 2018 10:34 pm    Post subject:
Reply with quote

Hi Julien,

Thanks for getting back to me, your post seems relevant but I am having another (unrelated) issue before I can fully test the fix code. I will post a separate issue.

Thanks a lot,

Antoine
Back to top
View user's profile Send private message
arennuit
User


Joined: 06 Dec 2013
Posts: 70

PostPosted: Mon Jan 22, 2018 2:28 pm    Post subject:
Reply with quote

Hi Julien,

Your answer was right and your help very much appreciated!

PS: as an added note, the platform I use has a rather dull GPU and I had to downgrade

Code:

#define GLSL330(program) "#version 150\n" #program


to

Code:

#define GLSL330(program) "#version 130\n" #program


For it to work.

Thanks a lot,

Antoine.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts EXTERNAL: Re: Value of a variable in... Rowley, Marlin R General 3 Fri Sep 28, 2018 1:39 pm View latest post
No new posts Value of a variable in shaders? Rowley, Marlin R General 4 Thu Sep 27, 2018 6:14 pm View latest post
No new posts Shaders with multiple views using Vie... robertosfield General 5 Wed May 09, 2018 9:20 am View latest post
No new posts EXTERNAL: Re: Getting a callback to u... Rowley, Marlin R General 1 Tue Apr 10, 2018 6:58 pm View latest post
No new posts Getting a callback to update shaders? Rowley, Marlin R General 2 Tue Apr 10, 2018 12:49 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP