Hi Forum,

I know that this topic is widely discussed here to run shading language 4 with 
OpenGL 3 and onwards using the compatibility profile. I checked the 
osgsimplegl3 and osgvertexattrib array example. Then i try to compile the a 
simple application with a pass through shader only , but i am having the 
following error:


Code:

Got an X11ErrorHandling call display=0x9c41880 event=0xb3fadf2c
GLXBadDrawable
Major opcode: 135
Minor opcode: 11
Error code: 146
Request serial: 9503
Current serial: 9503
  ResourceID: 73400323




I am also attaching the code snippet for your kind review:


Code:

int main()
{
  osg::ref_ptr<osg::Node> root = createSceneGraph();

  const std::string version("3.1");
  osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits();
  traits->windowDecoration = true;
  traits->doubleBuffer = true;
  traits->glContextVersion = version;


  osg::ref_ptr< osg::GraphicsContext > gc = 
osg::GraphicsContext::createGraphicsContext( traits.get() );

  if( !gc.valid() )
   {
       osg::notify( osg::FATAL ) << "Unable to create OpenGL v" << version << " 
context." << std::endl;
       return( 1 );
   }

  osg::ref_ptr<osg::Camera> camera = new osg::Camera;
  camera->setGraphicsContext(gc.get());

  osgViewer::Viewer viewer;
  viewer.setCamera(camera.get());
  viewer.setSceneData(root.get());

  return viewer.run() ;
}

osg::ref_ptr<osg::Node> createSceneGraph()
{
  //create an object to store the geometry in
  osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;

  //create an array of four vertices
  osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;

  v->push_back(osg::Vec3(-0.8f, -0.8f, 0.0f));
  v->push_back(osg::Vec3(0.8f, -0.8f, 0.0f));
  v->push_back(osg::Vec3(0.0f,  0.8f, 0.0f));

//  geom->setVertexArray(v.get());

  //make sure that vertex array is used
  geom->setUseDisplayList(false);
  geom->setVertexAttribArray(0,v.get());
  geom->setVertexAttribBinding(0,osg::Geometry::BIND_PER_VERTEX);

  //create an array of three colors
  osg::ref_ptr<osg::Vec3Array> c = new osg::Vec3Array;
  c->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
  c->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
  c->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));

//  geom->setColorArray(c.get());
  geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
  geom->setVertexAttribArray(1,c.get());
  geom->setVertexAttribBinding(1,geom->getColorBinding());


  //draw a three-vertex tringle from the stored data
  geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,3));

  //add the geometry to the geode and return the geode
  osg::ref_ptr<osg::Geode> geode = new osg::Geode;
  geode->addDrawable(geom.get());


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


  osg::ref_ptr<osg::Program> basicPrimitiveShaderProg = new osg::Program;

  osg::ref_ptr<osg::Shader> 
primitiveVertexShader(osg::Shader::readShaderFile(osg::Shader::VERTEX,"shaders/basic.vert"));
  osg::ref_ptr<osg::Shader> 
elephantFragmentShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT,"shaders/basic.frag"));

  basicPrimitiveShaderProg->addShader(primitiveVertexShader.get());
  basicPrimitiveShaderProg->addShader(elephantFragmentShader.get());

  basicPrimitiveShaderProg->addBindAttribLocation("VertexPosition",0);
  basicPrimitiveShaderProg->addBindAttribLocation("VertexColor",1);

  
primitiveState->setAttributeAndModes(basicPrimitiveShaderProg.get(),osg::StateAttribute::ON);


  return geode.get();
}





If i miss anything, i would be glad to be notified .

Thanks
Sajjadul

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





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

Reply via email to