[osg-users] glGetString returning NULL
sherman wilcox
wilcox.sherman at gmail.com
Thu Jul 31 09:14:02 PDT 2008
Thanks for the reply - I am running osgViewer in single threaded mode
- still returns NULL. The drawable trick works as expected, but I
don't understand why this doesn't work in the main render loop when in
single threaded mode. I *think* this worked in 2.4. Almost positive.
Anyway, here's a simple example. glGetString fails in the loop but
succeeds in the drawable. Note the usage of single threaded mode. I'm
not so concerned about having to move this code to a drawable, but
perhaps this is indicative of a larger issue?
#include <iostream>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
class CglGetString : public osg::Drawable
{
public:
CglGetString()
{
setUseDisplayList(false);
};
virtual bool isSameKindAs(const Object* obj) const { return
dynamic_cast<const CglGetString*>(obj)!=NULL; }
virtual Object* cloneType() const { return new CglGetString(); }
virtual Object* clone(const osg::CopyOp& copyop) const { return new
CglGetString(); }
virtual void drawImplementation(osg::RenderInfo& renderInfo) const
{
char* extensions = (char*)glGetString(GL_EXTENSIONS);
}
protected:
};
int main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
osgViewer::Viewer viewer(arguments);
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
osg::Referenced::setThreadSafeReferenceCounting(true);
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.setCameraManipulator(new osgGA::TrackballManipulator);
// load the data
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
if (!loadedModel)
{
std::cout << arguments.getApplicationName() <<": No data loaded"
<< std::endl;
return 1;
}
osg::ref_ptr<osg::Group> group = new osg::Group();
group->addChild(loadedModel.get());
if(1)
{
osg::Geode *geode = new osg::Geode();
geode->addDrawable(new CglGetString());
group->addChild(geode);
}
viewer.setSceneData( group.get() );
viewer.realize();
while(!viewer.done())
{
viewer.frame();
char* extensions = (char*)glGetString(GL_EXTENSIONS);
}
return 0;
}
On Thu, Jul 31, 2008 at 4:34 AM, Gordon Tomlinson
<gordon at gordon-tomlinson.com> wrote:
> This will in most case always return NULL in OSG 2.x and above
>
> You Have to do OpenGL calls where in the Processes/Thread that has the
> OpenGL context which in OSG is the Draw Processes, so you have to do
> anything with OpenGL in Draw Call callbacks
>
> You cannot do OpenGL calls in the App Process/Thread as your doing below (
> UNLESS you have OSG in Single Thread MODE )
>
>
>
> __________________________________________________________
> Gordon Tomlinson
>
> gordon at GordonTomlinson.com
> IM: gordon3dBrit at 3dscenegraph.com
> www.vis-sim.com www.gordontomlinson.com
> __________________________________________________________
>
> -----Original Message-----
> From: osg-users-bounces at lists.openscenegraph.org
> [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of sherman
> wilcox
> Sent: Wednesday, July 30, 2008 8:29 PM
> To: OpenSceneGraph Users
> Subject: [osg-users] glGetString returning NULL
>
> Running latest version of OSG in SVN, calling glGetString(...) from
> main render loop (single threaded osgViewer). Like this:
>
> while(viewer.done() == false)
> {
> viewer.frame();
>
> char* extensions = (char*)glGetString(GL_EXTENSIONS);
> }
>
>
> extensions is always NULL. Am I doing something wrong here? Could
> someone else test this?
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
More information about the osg-users
mailing list