之前遇到的问题是,在linux上基于ffmpeg增加使用opengl的模块,opengl只是用来映射投影等等,并不需要窗口显示到screen。所以需要使用一种方法不会创建screen还能对opengl进行初始化和正常使用。
首先需要启动linux下的 window X图形界面,目的是利用OpenGL 3.0增加的接口glXCreateContextAttribsARB。该接口同时还需要GLX1.4以上版本的支持。
首先,拿到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;
...
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc) glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc) glXGetProcAddressARB( (const GLubyte *) "glXMakeContextCurrent" );
const char *displayName = NULL;
Display* display = XOpenDisplay( displayName );
static int visualAttribs[] = { None };
int numberOfFramebufferConfigurations = 0;
GLXFBConfig* fbConfigs = glXChooseFBConfig( display, DefaultScreen(display), visualAttribs, &numberOfFramebufferConfigurations );
int context_attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB,
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
None
};
glContext = glXCreateContextAttribs(s->display, fbConfigs[0], 0, 1, context_attribs);
int pbufferAttribs[] = {
GLX_PBUFFER_WIDTH, 32,
GLX_PBUFFER_HEIGHT, 32,
None
};
s->pbuffer = glXCreatePbuffer(s->display, fbConfigs[0], pbufferAttribs);
XFree(fbConfigs);
XSync(s->display, False);
if(!glXMakeContextCurrent(s->display, s->pbuffer, s->pbuffer, s->glContext[0]))
{
//error case here
}