
this->systemProvIDer->setupContext(); //be careful with this one. to add thingIEs to IDentify if a context is set up or not this->systemProvIDer->useContext(); glewExperimental = GL_TRUE; glewInit(); gluint framebuffer,renderbuffer,depthRenderBuffer; gluint imageWIDth = _vIEwPortWIDth,imageHeight = _vIEwPortHeight; //Set up a FBO with one renderbuffer attachment glGenFramebuffers(1,&framebuffer); glBindFramebuffer(GL_FRAMEBUFFER,framebuffer); glGenRenderbuffers(1,&renderbuffer); glBindRenderbuffer(GL_RENDERBUFFER,renderbuffer); glrenderbufferStorage(GL_RENDERBUFFER,GL_RGB,imageWIDth,imageHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_color_ATTACHMENT0,GL_RENDERBUFFER,renderbuffer); //Now bind a depth buffer to the FBO glGenRenderbuffers(1,&depthRenderBuffer); glBindRenderbuffer(GL_RENDERBUFFER,depthRenderBuffer); glrenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,_vIEwPortWIDth,_vIEwPortHeight); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,depthRenderBuffer);
“系统提供程序”是围绕OS X的NSOpenGLContext的C包装器,它仅用于创建渲染上下文并使其成为当前,而不将其与窗口相关联.所有渲染都发生在FBO中.
我正在尝试使用与GLX相同的linux(Ubuntu)方法,但我很难做到这一点,因为我看到GLX需要一个像素缓冲区.
我正在尝试按照本教程:
http://renderingpipeline.com/2012/05/windowless-opengl/
最后它使用一个像素缓冲区来使上下文变为当前,我听说它已被弃用,我们应该放弃它而支持帧缓冲对象,这是对的(我可能错了).
有没有人有更好的方法或想法?
解决方法 我不知道这是否是最好的解决方案,但它肯定对我有用.将函数绑定到我们可以使用的局部变量
typedef GLXContext (*glXCreateContextAttribsARBProc)(display*,GLXFBConfig,GLXContext,Bool,const int*);typedef Bool (*glXMakeContextCurrentARBProc)(display*,GLXDrawable,GLXContext);static glXCreateContextAttribsARBProc glXCreateContextAttribsARB = NulL;static glXMakeContextCurrentARBProc glXMakeContextCurrentARB = NulL;
我们的对象作为类属性:
display *display;GLXPbuffer pbuffer;GLXContext openGLContext;
设置上下文:
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const glubyte *) "glXCreateContextAttribsARB" ); glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc) glXGetProcAddressARB( (const glubyte *) "glXMakeContextCurrent"); display = XOpendisplay(NulL); if (display == NulL){ std::cout << "error getting the X display"; } static int visualAttribs[] = {None}; int numberOfFrameBufferConfigurations; GLXFBConfig *fbConfigs = glXChooseFBConfig(display,DefaultScreen(display),visualAttribs,&numberOfFrameBufferConfigurations); int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB,3,GLX_CONTEXT_MInor_VERSION_ARB,2,GLX_CONTEXT_FLAGS_ARB,GLX_CONTEXT_DEBUG_BIT_ARB,GLX_CONTEXT_PROfile_MASK_ARB,GLX_CONTEXT_CORE_PROfile_BIT_ARB,None }; std::cout << "initialising context..."; this->openGLContext = glXCreateContextAttribsARB(display,fbConfigs[0],True,context_attribs); int pBufferAttribs[] = { GLX_PBUFFER_WIDTH,(int)this->initialWIDth,GLX_PBUFFER_HEIGHT,(int)this->initialHeight,None }; this->pbuffer = glXCreatePbuffer(display,pBufferAttribs); XFree(fbConfigs); XSync(display,False); 使用上下文:
if(!glXMakeContextCurrent(display,pbuffer,openGLContext)){ std::cout << "error with content creation\n";}else{ std::cout << "made a context the current context\n";} 在那之后,人们可以正常使用FBO,就像在任何其他场合一样.直到今天,我的问题实际上没有答案(如果有更好的选择),所以我只是提供一个对我有用的解决方案.在我看来,GLX不像OpenGL那样使用像素缓冲区的概念,因此我的困惑.渲染屏幕外的首选方法是FBO,但是要在linux上创建OpenGL上下文,必须创建像素缓冲区(GLX类型).之后,使用我在问题中提供的代码的FBO将按预期工作,就像在OS X上一样.
总结以上是内存溢出为你收集整理的Linux使用OpenGL 3.2 w / FBO在屏幕外渲染全部内容,希望文章能够帮你解决Linux使用OpenGL 3.2 w / FBO在屏幕外渲染所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)