void opengl_init()

in roboschool/cpp-household/render-simple.cpp [670:719]


void opengl_init(const boost::shared_ptr<Household::World>& wref)
{
	boost::shared_ptr<SimpleRender::Context>& cx = wref->cx;
	cx.reset(new SimpleRender::Context(wref));
	cx->fmt = QSurfaceFormat::defaultFormat();
	
	cx->surf = new QOffscreenSurface();
	cx->surf->setFormat(cx->fmt);
	cx->surf->create();

	// This doesn't work no matter how you put it -- widgets do not share context.
	// QOpenGLContext::areSharing() is reporting true, put you can't reference framebuffers or VAOs.
	if (1) {
		QOpenGLContext* glcx = QOpenGLContext::globalShareContext();
		QSurfaceFormat fmt_req = cx->fmt;
		QSurfaceFormat fmt_got = glcx->format();
		int got_version = fmt_got.majorVersion()*1000 + fmt_got.minorVersion();
		bool ok_without_shadows = got_version >= 3003;
		bool ok_all_features    = got_version >= 4001;
		if (!ok_without_shadows) {
			fprintf(stderr, "\n\nCannot initialize OpenGL context.\n");
			fprintf(stderr, "Requested version: %i.%i\n", fmt_req.majorVersion(), fmt_req.minorVersion());
			fprintf(stderr, "Actual version: %i.%i\n", fmt_got.majorVersion(), fmt_got.minorVersion());
			fprintf(stderr, "(it must be at least 3.3 to work)\n");
			fprintf(stderr, "For possible fixes, see:\n\nhttps://github.com/openai/roboschool/issues/2\n\n");
			assert(0);
		}
		cx->glcx = glcx;
		cx->ssao_enable = ok_all_features;
		cx->glcx->makeCurrent(cx->surf);
	} else {
		cx->dummy_openglwidget = new QOpenGLWidget();
		cx->dummy_openglwidget->setFormat(cx->fmt);
		cx->dummy_openglwidget->makeCurrent();
		cx->dummy_openglwidget->show();
		QOpenGLContext* glcx = cx->dummy_openglwidget->context();
		assert(glcx);
		glcx->makeCurrent(cx->surf);

		QOpenGLWidget* test = new QOpenGLWidget();
		test->setFormat(cx->fmt);
		test->show();
		test->context() ;
		bool hurray = QOpenGLContext::areSharing(
			glcx,
			test->context());
		cx->glcx = glcx;
		assert(hurray);
	}
}