Change OpenGL context version(Dirty hack)

Hello guys,
I made a little dirty hack for setting your desired OpenGL context version.

Add the following code in OF.
This goes in ofAppRunner.h on line 15:

void ofSetupOpenGL(ofPtr<ofAppBaseWindow> windowPtr); //THIS IS HACKED!!! window must setup manually
void  ofSetupOpenGL(ofAppBaseWindow * windowPtr); //THIS IS ALSO HACKED!!! window must setup manually

Now in ofAppRunner.cpp on line 59:

void ofSetupOpenGL(ofAppBaseWindow * windowPtr){
	ofSetupOpenGL(ofPtr<ofAppBaseWindow>(windowPtr,std::ptr_fun(noopDeleter)));
}

And on line 173 add:

void ofSetupOpenGL(ofPtr<ofAppBaseWindow> windowPtr){
	if(!ofGetCurrentRenderer()) {
	#ifdef USE_PROGRAMMABLE_GL
	    ofPtr<ofBaseRenderer> renderer(new ofGLProgrammableRenderer(false));
	#else
	    ofPtr<ofBaseRenderer> renderer(new ofGLRenderer(false));
	#endif
	    ofSetCurrentRenderer(renderer,false);
    }

	window = windowPtr;
}

In main.cpp add this code instead of the default one:

int main( ){
	ofSetLogLevel(OF_LOG_VERBOSE); //optional
	ofAppGLFWWindow windowApp; // important
	ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE); //important
	ofSetupOpenGL(&windowApp); //our version of ofSetupOpenGL()

	//This needs to be setup manually
	windowApp.setOpenGLVersion(3, 3);
	windowApp.setupOpenGL(800, 600, OF_WINDOW);


	// this kicks off the running of my app
	// can be OF_WINDOW or OF_FULLSCREEN
	// pass in width and height too:
	ofRunApp(new ofApp());

}

I tested it only on desktop. It will not work on ARM or Raspberry PI. That issue is easy resolved by adding the following code in void ofSetupOpenGL(ofPtr<ofAppBaseWindow> windowPtr) right after window = windowPtr

if(ofIsGLProgrammableRenderer()){
        #if defined(TARGET_RASPBERRY_PI)
		static_cast<ofAppEGLWindow*>(window.get())->setGLESVersion(2);
		#elif defined(TARGET_LINUX_ARM)
		static_cast<ofAppGLFWWindow*>(window.get())->setOpenGLVersion(2,0);
		#endif
	}else{
	    #if defined(TARGET_LINUX_ARM) && !defined(TARGET_RASPBERRY_PI)
		static_cast<ofAppGLFWWindow*>(window.get())->setOpenGLVersion(1,0);
		#endif
	}

I hope this will help you as much as it helped me. :smile:
Cheers!

2 Likes