wglcreatecontextarb ne fonctionne pas

wglcreatecontextarb ne fonctionne pas - C - Programmation

Marsh Posté le 16-04-2023 à 00:57:10    

A l'aide :
 
 
Bonjour,
J'ai un projet opengl fonctionne quand je passe wglCreateContext (mais la fonction est obsoléte et sera retirer dans le long terme),
Mais quand je veux utiliser la fonction de remplacement 'wglCreateContextAttribsARB' , aucun primitive dessiner ,seul la fonction glClearColor fonctionne.
 
Sur le web il n'y pas de sample utilisant la fonction wglCreateContextAttribsARB

Code :
  1. static void
  2. init_opengl_extensions(void)
  3. {
  4. // Before we can load extensions, we need a dummy OpenGL context, created using a dummy window.
  5. // We use a dummy window because you can only set the pixel format for a window once. For the
  6. // real window, we want to use wglChoosePixelFormatARB (so we can potentially specify options
  7. // that aren't available in PIXELFORMATDESCRIPTOR), but we can't load and use that before we
  8. // have a context.
  9. WNDCLASSA window_class = { 0 };
  10. window_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  11. window_class.lpfnWndProc = DefWindowProcA;
  12. window_class.hInstance = GetModuleHandle(0);
  13. window_class.lpszClassName = "Dummy_WGL_djuasiodwa";
  14. if (!RegisterClassA(&window_class)) {
  15.  fatal_error("Failed to register dummy OpenGL window." );
  16. }
  17. HWND dummy_window = CreateWindowExA(
  18.  0,
  19.  window_class.lpszClassName,
  20.  "Dummy OpenGL Window",
  21.  0,
  22.  CW_USEDEFAULT,
  23.  CW_USEDEFAULT,
  24.  CW_USEDEFAULT,
  25.  CW_USEDEFAULT,
  26.  0,
  27.  0,
  28.  window_class.hInstance,
  29.  0);
  30. if (!dummy_window) {
  31.  fatal_error("Failed to create dummy OpenGL window." );
  32. }
  33. HDC dummy_dc = GetDC(dummy_window);
  34. PIXELFORMATDESCRIPTOR pfd;
  35. pfd.nSize = sizeof(pfd);
  36. pfd.nVersion = 1;
  37. pfd.iPixelType = PFD_TYPE_RGBA;
  38. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  39.  pfd.cColorBits = 32;
  40.  pfd.cAlphaBits = 8;
  41.  pfd.iLayerType = PFD_MAIN_PLANE;
  42.  pfd.cDepthBits = 24;
  43.  pfd.cStencilBits = 8;
  44. int pixel_format = ChoosePixelFormat(dummy_dc, &pfd);
  45. if (!pixel_format) {
  46.  fatal_error("Failed to find a suitable pixel format." );
  47. }
  48. if (!SetPixelFormat(dummy_dc, pixel_format, &pfd)) {
  49.  fatal_error("Failed to set the pixel format." );
  50. }
  51. HGLRC dummy_context = wglCreateContext(dummy_dc);
  52. if (!dummy_context) {
  53.  fatal_error("Failed to create a dummy OpenGL rendering context." );
  54. }
  55. if (!wglMakeCurrent(dummy_dc, dummy_context)) {
  56.  fatal_error("Failed to activate dummy OpenGL rendering context." );
  57. }
  58. wglCreateContextAttribsARB = (wglCreateContextAttribsARB_type*)wglGetProcAddress(
  59.  "wglCreateContextAttribsARB" );
  60. wglChoosePixelFormatARB = (wglChoosePixelFormatARB_type*)wglGetProcAddress(
  61.  "wglChoosePixelFormatARB" );
  62. wglMakeCurrent(dummy_dc, 0);
  63. wglDeleteContext(dummy_context);
  64. ReleaseDC(dummy_window, dummy_dc);
  65. DestroyWindow(dummy_window);
  66. }
  67. void EnableOpenGL(HWND hWnd, HDC* hDC, HGLRC* hRC)
  68. {
  69. init_opengl_extensions();
  70. // get the device context (DC)
  71.  /*wglCreateContextAttribsARB = (wglCreateContextAttribsARB_type*)wglGetProcAddress(
  72.  "wglCreateContextAttribsARB" );
  73.  wglChoosePixelFormatARB = (wglChoosePixelFormatARB_type*)wglGetProcAddress(
  74.   "wglChoosePixelFormatARB" );*/
  75.  if ((wglCreateContextAttribsARB != NULL)&&(wglChoosePixelFormatARB!=NULL))
  76.  {
  77.   *hDC = GetDC(hWnd);
  78.  // int pixel_format_attribs[] = {
  79.  //WGL_DRAW_TO_WINDOW_ARB,     GL_TRUE,
  80.  //WGL_SUPPORT_OPENGL_ARB,     GL_TRUE,
  81.  //WGL_DOUBLE_BUFFER_ARB,      GL_TRUE,
  82.  //WGL_ACCELERATION_ARB,       WGL_FULL_ACCELERATION_ARB,
  83.  //WGL_PIXEL_TYPE_ARB,         WGL_TYPE_RGBA_ARB,
  84.  //WGL_SAMPLE_BUFFERS_ARB,  GL_TRUE ,
  85.  //WGL_COLOR_BITS_ARB,         32,
  86.  //WGL_DEPTH_BITS_ARB,         24,
  87.  //WGL_STENCIL_BITS_ARB,       8,
  88.  //0,0
  89.  // };
  90.   int pixel_format_attribs[] = {
  91.   WGL_SUPPORT_OPENGL_ARB, 1,
  92.  WGL_DRAW_TO_WINDOW_ARB, 1,
  93.  /*WGL_DRAW_TO_BITMAP_ARB, 1,*/
  94.  WGL_DOUBLE_BUFFER_ARB, 1,
  95.  //WGL_SWAP_LAYER_BUFFERS_ARB, 1,
  96.  WGL_COLOR_BITS_ARB, 32,
  97.  WGL_RED_BITS_ARB, 8,
  98.  WGL_GREEN_BITS_ARB, 8,
  99.  WGL_BLUE_BITS_ARB, 8,
  100.  WGL_ALPHA_BITS_ARB, 8,
  101.  WGL_DEPTH_BITS_ARB, 8,
  102.  WGL_STENCIL_BITS_ARB, 8,
  103.  WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
  104.  WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
  105.  0
  106.   };
  107.   int pixel_format;
  108.   UINT num_formats;
  109.   wglChoosePixelFormatARB(*hDC, pixel_format_attribs, 0, 1, &pixel_format, &num_formats);
  110.   if (!num_formats) {
  111.     fatal_error("Failed to set the OpenGL 3.3 pixel format." );
  112.   }
  113.   PIXELFORMATDESCRIPTOR pfd;
  114.   DescribePixelFormat(*hDC, pixel_format, sizeof(pfd), &pfd);
  115.   if (!SetPixelFormat(*hDC, pixel_format, &pfd)) {
  116.    fatal_error("Failed to set the OpenGL 3.3 pixel format." );
  117.   }
  118.   // Specify that we want to create an OpenGL 3.3 core profile context
  119.   int gl33_attribs[] = {
  120.    WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
  121.    WGL_CONTEXT_MINOR_VERSION_ARB, 3,
  122.    WGL_CONTEXT_PROFILE_MASK_ARB,  WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
  123.    0,
  124.   };
  125.   *hRC = wglCreateContextAttribsARB(*hDC, 0, gl33_attribs);
  126.  }
  127.  else
  128.  {
  129.   *hRC = wglCreateContext(*hDC);
  130.   wglMakeCurrent(*hDC, *hRC);
  131.   }
  132. wglMakeCurrent(*hDC, *hRC);
  133. }
  134. #endif
  135. char checkShaderCompilation(GLuint shaderID)
  136. {
  137. GLint compilationStatus = 0;
  138. // Vérification de la compilation pour le vertex shader
  139. glGetShaderiv(opengl.vertexID, GL_COMPILE_STATUS, &compilationStatus);
  140. //if (compilationStatus != GL_TRUE)
  141. {
  142.  // Nous savons que la compilation a échoué, donc nous devons savoir pourquoi
  143.  // Nous devons récupéré la taille du log
  144.  GLint logLength = 0;
  145.  char* log = NULL;
  146.  glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength);
  147.  if (logLength > 0)
  148.  {
  149.   // Maintenant que nous avons la taille, nous pouvons alloué la mémoire suffisante pour ce log
  150.   log = (char*)malloc(logLength);
  151.   if (log == NULL)
  152.   {
  153.    fprintf(stderr, "Erreur d'allocation de mémoire pour le log de la compilation du shader\n" );
  154.    return 0;
  155.   }
  156.   glGetShaderInfoLog(shaderID, logLength, &logLength, log);
  157.   // On peut afficher le message
  158.   fprintf(stderr, "Erreur de compilation:\n%s", log);
  159.   MessageBox(NULL, log, NULL, MB_ICONHAND);
  160.   // Et on n'oublie pas de libéré la mémoire
  161.   free(log);
  162.   return 0;
  163.  }
  164.  else
  165.   return 1;
  166. }
  167. return 1; // Pas d'erreur
  168. }


 
Ca ne marche pas , et j'y suis depuis 3 heures.
 
 
 
Pour information je travaille sous Vmware player 17.01 : 17.0.1 build-21139696
 
Ce n'est pas un probléme de shader.
 
Merci

Reply

Marsh Posté le 16-04-2023 à 00:57:10   

Reply

Marsh Posté le 16-04-2023 à 17:11:39    

Je ne pourrais pas te répondre, mais de manière générale, tu devrais faire attention à la mise en page de ton code, car la c'est assez indigeste. :o Aussi je suppose que tu as activé les Warnings de ton compilateur? Tu utilises lequel, GCC? Dans ce cas -Wall -Wextra -Werror à rajouter en ligne de commande.

 

EDIT: Aussi ton exemple n'est pas complet, il manque les #include au début et la main(). Pour simplifier la vie aux aidants il faut toujours donner un exemple complet (soit compilable) mais le plus court possible.


Message édité par rat de combat le 16-04-2023 à 17:29:57

---------------
Si vous ouvrez un sujet merci de ne pas le "laisser mourir" subitement et de le marquer comme "résolu" le cas échéant!
Reply

Marsh Posté le 18-04-2023 à 12:28:58    

Et il y a un #endif au milieu du code sans #if correspondant...
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed