大佬教程收集整理的这篇文章主要介绍了Linux使用OpenGL 3.2 w / FBO在屏幕外渲染,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有ubuntu机器,以及用OS X编写的命令行应用程序,它使用FBO在屏幕外渲染.这是代码的一部分.
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="">figurations;
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="">figs[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在屏幕外渲染所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。