Hello everyone

I try to set up custom opengl context on Widget, but i run into X Error
Qt Code:
  1. X Error: BadMatch (invalid parameter attributes) 8
  2. Extension: 135 (Uknown extension)
  3. Minor opcode: 5 (Unknown request)
  4. Resource id: 0x4400003
To copy to clipboard, switch view to plain text mode 

I think that this could be problem with colormap, because default window colormap could be created based on different frame buffer than frame buffer used to created context.
I don't know how change colormap attached to window, can anyone help please?

Some code below:

Qt Code:
  1. typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
  2.  
  3. Widget::Widget(QWidget *parent) :
  4. QWidget(parent)
  5. {
  6. this->setAutoFillBackground(false);
  7. this->setAttribute(Qt::WA_OpaquePaintEvent);
  8. this->setAttribute(Qt::WA_NoSystemBackground);
  9. this->setAttribute(Qt::WA_NativeWindow);
  10. this->setAttribute(Qt::WA_PaintOnScreen, true);
  11. this->setAttribute(Qt::WA_StyledBackground, false);
  12. this->setAttribute(Qt::WA_PaintUnclipped);
  13.  
  14. this->xInfo = this->x11Info();
  15.  
  16. this->findBestFrameBuffer();
  17.  
  18. GLXContext context = 0;
  19.  
  20. glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
  21. glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
  22.  
  23. int contextAttribs[] =
  24. {
  25. GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
  26. GLX_CONTEXT_MINOR_VERSION_ARB, 3,
  27. //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
  28. None
  29. };
  30.  
  31.  
  32. context = glXCreateContextAttribsARB(this->xInfo.display(), this->fbConfig, 0, True, contextAttribs);
  33. qDebug("context %p ", context);
  34.  
  35.  
  36. glXMakeCurrent(this->xInfo.display(), this->winId(), context);
  37. }
  38.  
  39. void Widget::findBestFrameBuffer()
  40. {
  41. static int visualAttribs[] =
  42. {
  43. GLX_X_RENDERABLE , True,
  44. GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT,
  45. GLX_RENDER_TYPE , GLX_RGBA_BIT,
  46. GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR,
  47. GLX_RED_SIZE , 8,
  48. GLX_GREEN_SIZE , 8,
  49. GLX_BLUE_SIZE , 8,
  50. GLX_ALPHA_SIZE , 8,
  51. GLX_DEPTH_SIZE , 24,
  52. GLX_STENCIL_SIZE , 8,
  53. GLX_DOUBLEBUFFER , True,
  54. //GLX_SAMPLE_BUFFERS , 1,
  55. //GLX_SAMPLES , 4,
  56. None
  57. };
  58. int fbCount = 0;
  59.  
  60. GLXFBConfig* fbConfigsList = glXChooseFBConfig(this->xInfo.display(), this->xInfo.screen(), visualAttribs, &fbCount);
  61.  
  62. qDebug("%i frame buffers found", fbCount);
  63.  
  64. int bestFbCfg = -1;
  65. int worstFbCfg = -1;
  66. int bestNumberOfSamples = -1;
  67. int worstNumberOfSamples = 999;
  68. XVisualInfo* visualInfo = NULL;
  69. int sampleBuffers = 0;
  70. int samples = 0;
  71.  
  72. for( int i = 0 ; i < fbCount ; i++ )
  73. {
  74. visualInfo = glXGetVisualFromFBConfig(this->xInfo.display(), fbConfigsList[i]);
  75.  
  76. if( visualInfo != NULL )
  77. {
  78. glXGetFBConfigAttrib(this->xInfo.display(), fbConfigsList[i], GLX_SAMPLE_BUFFERS, &sampleBuffers);
  79. glXGetFBConfigAttrib(this->xInfo.display(), fbConfigsList[i], GLX_SAMPLES, &samples);
  80.  
  81. qDebug("\t matching %i fbCOnfig, visualId %p sampleBUffers %i samples %i", i+1, visualInfo->visualid, sampleBuffers, samples);
  82.  
  83. if( bestFbCfg < 0 || sampleBuffers && samples > bestNumberOfSamples )
  84. {
  85. bestFbCfg = i;
  86. bestNumberOfSamples = samples;
  87. }
  88.  
  89. if( worstFbCfg < 0 || !sampleBuffers | samples < worstNumberOfSamples )
  90. {
  91. worstFbCfg = i;
  92. worstNumberOfSamples = samples;
  93. }
  94.  
  95. }
  96.  
  97. XFree(visualInfo);
  98. }
  99.  
  100. qDebug("best fb %i worst fb %i", bestFbCfg+1, worstFbCfg+1);
  101.  
  102. this->fbConfig = fbConfigsList[bestFbCfg];
  103. XFree(fbConfigsList);
  104. }
  105.  
  106. void Widget::paintEvent(QPaintEvent *)
  107. {
  108.  
  109. }
To copy to clipboard, switch view to plain text mode 


Regards