我试图使用OpenGL与共享的上下文(因为在窗口之间共享纹理)通过FreeGLUT库.它工作的很好,我可以分享纹理,但我失败了,在程序的结尾或窗口关闭鼠标.
我已经验证了模拟问题的代码:(http://pastie.org/9437038)
// file: main.c
// compile: gcc -o test -lglut main.c
// compile: gcc -o test -lglut -DTIME_LIMIT main.c
#include "GL/freeglut.h"
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int winA, winB, winC;
int n;
glutInit(&argc, argv);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE , GLUT_ACTION_CONTINUE_EXECUTION);
//glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
winA = glutCreateWindow("Test A");
glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);
winB = glutCreateWindow("Test B");
winC = glutCreateWindow("Test C");
printf("loop\n");
#ifdef TIME_LIMIT
for (n=0;n<50;n++)
{
glutMainLoopEvent();
usleep(5000);
}
#else //TIMELIMIT
glutMainLoop();
#endif // TIME_LIMIT
printf("Destroy winC\n");
glutDestroyWindow(winC);
printf("Destroy winB\n");
glutDestroyWindow(winB);
printf("Destroy winA\n");
glutDestroyWindow(winA);
printf("Normal end\n");
return 0;
}输出:
loop
X Error of failed request: GLXBadContext
Major opcode of failed request: 153 (GLX)
Minor opcode of failed request: 4 (X_GLXDestroyContext)
Serial number of failed request: 113
Current serial number in output stream: 114
Segmentation fault使用TIME_LIMIT输出:
loop
Destroy winC
Destroy winB
Destroy winA
Segmentation fault不需要调用glutSetOption(GLUT_RENDERING_CONTEXT,GLUT_USE_CURRENT_CONTEXT);它工作得很好。
有谁知道我在做什么坏事吗?
发布于 2014-08-01 18:17:17
选项GLUT_USE_CURRENT_CONTEXT不创建共享上下文。它只是意味着所有窗口都使用相同的GL上下文。您只有一个GL conxtext,当您第一次销毁使用该文本的窗口时,则销毁它,因此其他销毁调用失败。我所知道的任何一个GLUT实现实际上都不支持GL上下文共享。
GLUT_USE_CURRENT_CONTEXT更像是一个黑客(而且它也不是过剩规范的一部分),而不是一个很好的实现。它可以使用一些引用计数来销毁上下文,而不是在最后一个使用它的窗口被销毁之前,但事实并非如此。
https://stackoverflow.com/questions/25085662
复制相似问题