Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #define GLEW_STATIC
  2. #include <GL/glew.h>
  3. #include <GLFW\glfw3.h>
  4. #include <iostream>
  5.  
  6. void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
  7. {
  8. // Когда пользователь нажимает ESC, мы устанавливаем свойство WindowShouldClose в true,
  9. // и приложение после этого закроется
  10. if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  11. glfwSetWindowShouldClose(window, GL_TRUE);
  12. }
  13.  
  14. int main()
  15. {
  16. //Инициализация GLFW
  17. glfwInit();
  18. //Настройка GLFW
  19. //Задается минимальная требуемая версия OpenGL.
  20. //Мажорная
  21. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  22. //Минорная
  23. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  24. //Установка профайла для которого создается контекст
  25. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  26. //Выключение возможности изменения размера окна
  27. glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  28. GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);
  29. if (window == nullptr)
  30. {
  31. std::cout << "Failed to create GLFW window" << std::endl;
  32. glfwTerminate();
  33. return -1;
  34. }
  35. glfwMakeContextCurrent(window);
  36. glewExperimental = GL_TRUE;
  37. if (glewInit() != GLEW_OK)
  38. {
  39. std::cout << "Failed to initialize GLEW" << std::endl;
  40. return -1;
  41. }
  42. int width, height;
  43. glfwGetFramebufferSize(window, &width, &height);
  44.  
  45. glViewport(0, 0, width, height);
  46. glfwSetKeyCallback(window, key_callback);
  47. while (!glfwWindowShouldClose(window))
  48. {
  49. // Проверяем события и вызываем функции обратного вызова.
  50. glfwPollEvents();
  51.  
  52. // Команды отрисовки здесь
  53. glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
  54. glClear(GL_COLOR_BUFFER_BIT);
  55.  
  56. // Меняем буферы местами
  57. glfwSwapBuffers(window);
  58. }
  59. glfwTerminate();
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement