我有一些为 Linux 编写的代码,我需要重新实现这些代码,以便它可以在 Windows 和 Linux 上运行。它目前是 X-Windows、GLX 和 OpenGL 2.1,我正在使用 SDL2 和使用 GLEW 的兼容 OpenGL 扩展(它仍在旧的(Centos 5.3)Linux 平台以及带有 6 年旧显卡的最新 Windows 上运行)。
我被困在如何替换 glXMakeContextCurrent 上。这当前用于选择读取和绘制像素缓冲区 (GLXPbuffer) 并与上下文关联。我一直在研究使用像素缓冲区对象来替换 GLXPbuffers 但不知道如何使用此类技术复制 glXMakeContextCurrent 的功能,或者是否有更好的方法来做到这一点。
现有代码对其进行设置,使其呈现为 GLXPbuffer,然后使用 glCopyPixels 使用指定的上下文从一个可绘制对象(一个 GLXPbuffer)复制到另一个(另一个 GLXPbuffer),并在 glXMakeContextCurrent 调用中指定 Draw 和 Read Drawables 和 Context . 这是一个主要是 2D 的 OpenGL 应用程序。
在不使用 GLX 的情况下如何实现这一点,即它可以在 Windows(以及 Linux)上运行?
这是一个代码段,显示了当前代码的作用:
Display *dpy;
GLXContext osr_ctx;
GLXPbuffer pbuf2, osr_pbuf;
void sel_drc( GLXDrawable dst, GLXDrawable src, SDL_GLContext ctx )
{
if ( !src )
{
if ( !glXMakeCurrent( dpy, dst, ctx ) )
{
Error( "glXMakeCurrent" );
}
}
else
{
if ( !glXMakeContextCurrent( dpy, dst, src, ctx ) )
{
Error( "glXMakeContextCurrent" );
}
}
}
// Display dpy is set up elsewhere.
// GLXContext and GLXPbuffers get created elsewhere and stored in osr_ctx, pbuf2, osr_pbuf
// The Display and GLXContexts are to be replaced by their SDL2 equivalents.
// GLXPbuffers are currently planned to be Pixel Buffer Objects:
// GLuint pboIds[2];
// glGenBuffers(2, pboIds);
// glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[0]);
// glBufferData(GL_PIXEL_UNPACK_BUFFER, DATA_SIZE, 0, GL_STREAM_DRAW);
// etc.
//
sel_drc( osr_pbuf, pbuf2, osr_ctx );
glRasterPos2f( 0.1, 0.1 );
glCopyPixels ( 0, 0, 576, 576, GL_COLOR );