Created
August 5, 2016 18:27
-
-
Save vicrucann/cbe1022387d985774c4f04c204e88110 to your computer and use it in GitHub Desktop.
Obtain OpenGL version from OSG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#ifdef _WIN32 | |
#include <Windows.h> | |
#endif | |
#include <osgViewer/Viewer> | |
#include <osg/GLExtensions> | |
const int OSG_WIDTH = 1024; | |
const int OSG_HEIGHT = 960; | |
class TestSupportOperation : public osg::GraphicsOperation | |
{ | |
public: | |
TestSupportOperation() | |
: osg::Referenced(true) | |
, osg::GraphicsOperation("TestSupportOperation", false) | |
, m_supported(true) | |
, m_errorMsg() | |
, m_version(1.3) | |
{} | |
virtual void operator() (osg::GraphicsContext* gc) | |
{ | |
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex); | |
osg::GLExtensions* gl2ext = gc->getState()->get<osg::GLExtensions>(); | |
if( gl2ext ){ | |
if( !gl2ext->isGlslSupported ) | |
{ | |
m_supported = false; | |
m_errorMsg = "ERROR: GLSL not supported by OpenGL driver."; | |
} | |
else | |
m_version = gl2ext->glVersion; | |
} | |
else{ | |
m_supported = false; | |
m_errorMsg = "ERROR: GLSL not supported."; | |
} | |
} | |
OpenThreads::Mutex m_mutex; | |
bool m_supported; | |
std::string m_errorMsg; | |
float m_version; | |
}; | |
int main(int, char**) | |
{ | |
#ifdef _WIN32 | |
::SetProcessDPIAware(); | |
#endif | |
osgViewer::Viewer viewer; | |
viewer.setUpViewInWindow(100,100,OSG_WIDTH, OSG_HEIGHT); | |
// openGL version: | |
osg::ref_ptr<TestSupportOperation> so = new TestSupportOperation; | |
viewer.setRealizeOperation(so.get()); | |
viewer.realize(); | |
if (so->m_supported) | |
std::cout << "GLVersion=" << so->m_version << std::endl; | |
else | |
std::cout << so->m_errorMsg << std::endl; | |
return viewer.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment