Advertisement
Guest User

Untitled

a guest
Jun 14th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <GLFW\glfw3.h>
  2. #include <GLES2\gl2.h>
  3. #include <iostream>
  4.  
  5. using std::cout;
  6. using std::endl;
  7.  
  8. void printInfo(GLFWwindow *window) {
  9.     const GLubyte *version = glGetString(GL_VERSION);
  10.     const GLubyte *vendor = glGetString(GL_VENDOR);
  11.     const GLubyte *renderer = glGetString(GL_RENDERER);
  12.     const GLubyte *extensions = glGetString(GL_EXTENSIONS);
  13.     cout << "Version: " << version << endl;
  14.     cout << "Vendor: " << vendor << endl;
  15.     cout << "Renderer: " << renderer << endl;
  16.     cout << "Extensions: " << extensions << endl;
  17.  
  18.     int api   = glfwGetWindowAttrib(window, GLFW_CLIENT_API);
  19.     int major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
  20.     int minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
  21.     int revision = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
  22.  
  23.     if(api == GLFW_OPENGL_API) {
  24.         cout << "OpenGL" << endl;
  25.     }
  26.     else if(api == GLFW_OPENGL_ES_API) {
  27.         cout << "OpenGL ES" << endl;
  28.     }
  29.  
  30.     cout << "Major version: " << major << endl;
  31.     cout << "Minor version: " << minor << endl;
  32. }
  33.  
  34. void errorHandler(int code, const char *description) {
  35.     cout << "GLFW error reported." << endl;
  36.     cout << "\tCode: " << code << endl;
  37.     cout << "\tDescription: " << description << endl;
  38. }
  39.  
  40. int main(void)
  41. {
  42.     GLFWwindow* window;
  43.  
  44.     /* Initialize the library */
  45.     glfwSetErrorCallback(errorHandler);
  46.  
  47.     if (!glfwInit())
  48.         return -1;
  49.    
  50.     /* Create a windowed mode window and its OpenGL context */
  51.     glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
  52.    
  53.     window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
  54.     if (!window)
  55.     {
  56.         glfwTerminate();
  57.         return -1;
  58.     }
  59.  
  60.     /* Make the window's context current */
  61.     glfwMakeContextCurrent(window);
  62.  
  63.     // Set up the shaders
  64.     printInfo(window);
  65.     GLuint handle = glCreateProgram();
  66.     if(handle == 0) {
  67.         cout << "Could not create a shader program handle." << endl;
  68.     }
  69.  
  70.     /* Loop until the user closes the window */
  71.     while (!glfwWindowShouldClose(window))
  72.     {
  73.         /* Render here */
  74.  
  75.         /* Swap front and back buffers */
  76.         glfwSwapBuffers(window);
  77.  
  78.         /* Poll for and process events */
  79.         glfwPollEvents();
  80.     }
  81.  
  82.     glfwTerminate();
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement