Advertisement
Guest User

elmindreda

a guest
Sep 27th, 2010
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. // Iterate through various window hint permuations and list the results
  2. // Copyright (c) 2010 BenXYZ
  3. //
  4. // Modified by Camilla Berglund <elmindreda@elmindreda.org>
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. #include <GL/glfw.h>
  10.  
  11. int screenw = 800;
  12. int screenh = 600;
  13.  
  14. #define USE_FORWARD_COMPAT(x) ((x) & 0x01)
  15. #define USE_CORE_PROFILE(x)   ((x) & 0x02)
  16.  
  17. int main(int argc, char *argv[])
  18. {
  19.     if (!glfwInit())
  20.     {
  21.         fprintf(stderr, "Failed to initialise GLFW\n");
  22.         exit(EXIT_FAILURE);
  23.     }
  24.  
  25.     // Iterate though forward-compat and core profile permuations
  26.     for (int hintswitch = 0;  hintswitch < 4;  hintswitch++)
  27.     {
  28.         printf("Test run with%s forward-compatibility %s with%s core profile\n",
  29.                USE_FORWARD_COMPAT(hintswitch) ? "" : "out",
  30.                USE_FORWARD_COMPAT(hintswitch) == USE_CORE_PROFILE(hintswitch) ? "and" : "but",
  31.                USE_CORE_PROFILE(hintswitch) ? "" : "out");
  32.  
  33.         // Iterate through major and minor OpenGL version permuations
  34.         for (int imaj = 1;  imaj < 5;  imaj++)
  35.         {
  36.             for (int imin = 0;  imin < 10;  imin++)
  37.             {
  38.                 // Set all window hints each time, as glfwOpenWindow resets them
  39.  
  40.                 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, imaj);
  41.                 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, imin);
  42.  
  43.                 if (USE_FORWARD_COMPAT(hintswitch))
  44.                     glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  45.  
  46.                 if (USE_CORE_PROFILE(hintswitch))
  47.                     glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  48.  
  49.                 printf("OpenGL version: %d.%d ", imaj, imin);
  50.  
  51.                 // Try to create the desired context
  52.                 if (glfwOpenWindow(screenw, screenh, 0, 0, 0, 0, 0, 0, GLFW_WINDOW) == GL_TRUE)
  53.                 {
  54.                     printf("works\t(reports %d.%d)\n",
  55.                            glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR),
  56.                            glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR));
  57.  
  58.                     glfwCloseWindow();
  59.                 }
  60.                 else
  61.                     printf("FAILED\n");
  62.             }
  63.         }
  64.  
  65.         printf("\n");
  66.     }
  67.  
  68.     exit(EXIT_SUCCESS);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement