Linux 使用OpenGL 3.2+;带固定基地运营商
我有一台ubuntu机器,还有一个用OSX编写的命令行应用程序,它使用FBOs在屏幕外呈现一些东西。这是代码的一部分Linux 使用OpenGL 3.2+;带固定基地运营商,linux,opengl,fbo,glx,Linux,Opengl,Fbo,Glx,我有一台ubuntu机器,还有一个用OSX编写的命令行应用程序,它使用FBOs在屏幕外呈现一些东西。这是代码的一部分 this->systemProvider->setupContext(); //be careful with this one. to add thingies to identify if a context is set up or not this->systemProvider->useContext(); gle
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, GL_RENDERBUFFER, depthRenderBuffer);
“系统提供程序”是一个围绕OS X的NSopunLLeVice的C++包装器,它只用于创建渲染上下文并使其处于当前状态,而不将其与窗口关联。所有渲染都在FBO中进行
我试图使用GLX为Linux(Ubuntu)使用相同的方法,但我很难做到这一点,因为我看到GLX需要像素缓冲区 我正在尝试遵循本教程: 最后,它使用一个像素缓冲区使上下文成为当前的,我听说这是不推荐的,我们应该放弃它,转而使用帧缓冲区对象,这是对的(我可能是错的)有人有更好的方法或想法吗?我不知道这是否是最好的解决方案,但它确实对我有效 将函数绑定到我们可以使用的局部变量
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, 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], 0, True, context_attribs);
int pBufferAttribs[] = {
GLX_PBUFFER_WIDTH, (int)this->initialWidth,
GLX_PBUFFER_HEIGHT, (int)this->initialHeight,
None
};
this->pbuffer = glXCreatePbuffer(display, fbConfigs[0], pBufferAttribs);
XFree(fbConfigs);
XSync(display, False);
if(!glXMakeContextCurrent(display, pbuffer, pbuffer, openGLContext)){
std::cout << "error with content creation\n";
}else{
std::cout << "made a context the current context\n";
}
设置上下文:
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], 0, True, context_attribs);
int pBufferAttribs[] = {
GLX_PBUFFER_WIDTH, (int)this->initialWidth,
GLX_PBUFFER_HEIGHT, (int)this->initialHeight,
None
};
this->pbuffer = glXCreatePbuffer(display, fbConfigs[0], pBufferAttribs);
XFree(fbConfigs);
XSync(display, False);
if(!glXMakeContextCurrent(display, pbuffer, pbuffer, openGLContext)){
std::cout << "error with content creation\n";
}else{
std::cout << "made a context the current context\n";
}
glXCreateContextAttribsARB=(glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte*)“glXCreateContextAttribsARB”);
glXMakeContextCurrentARB=(glXMakeContextCurrentARBProc)glXGetProcAddressARB((const GLubyte*)“glXMakeContextCurrent”);
display=XOpenDisplay(空);
如果(显示==NULL){
标准::cout initialWidth,
GLX_PBUFFER_高度,(int)此->初始高度,
没有一个
};
此->pbuffer=glXCreatePbuffer(显示,fbConfigs[0],pBufferAttribs);
XFree(fbConfigs);
XSync(显示,False);
使用上下文:
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], 0, True, context_attribs);
int pBufferAttribs[] = {
GLX_PBUFFER_WIDTH, (int)this->initialWidth,
GLX_PBUFFER_HEIGHT, (int)this->initialHeight,
None
};
this->pbuffer = glXCreatePbuffer(display, fbConfigs[0], pBufferAttribs);
XFree(fbConfigs);
XSync(display, False);
if(!glXMakeContextCurrent(display, pbuffer, pbuffer, openGLContext)){
std::cout << "error with content creation\n";
}else{
std::cout << "made a context the current context\n";
}
if(!glXMakeContextCurrent(display,pbuffer,pbuffer,openGLContext)){
很好,是的,渲染缓冲区现在没有多大用处。你能详细说明一下吗?渲染缓冲区是什么意思?你有更好的跨平台替代方案吗?我可能说的“渲染缓冲区”是什么意思?你的代码正在使用它们。我希望你能详细说明这些替代方案,为什么你不认为它们不是很有用,因为在一个小型的谷歌搜索中,人们说最好的方法之一是使用fbo,不仅用于屏幕外渲染,还用于渲染到纹理效果。我很想听听你的替代方案。@BartekBanachewicz我相信他说的是像素缓冲区,而不是渲染缓冲区。我正试图在Ubuntu上使用GLX做完全相同的事情。OP提到的链接使用像素缓冲区来生成上下文。但是像素缓冲区不受欢迎,FBO是首选。他问的是如果我们想使用FBO,需要做什么。我的编译器是tellin告诉我“glXCreateContextAttribsARBProc”是一个未知的类型名