Advertisement
Guest User

open gl backup

a guest
May 27th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #define GL_SILENCE_DEPRECATION                      //выключаем предупреждения mac os о open gl
  2. /*
  3. #include <openGL/gl.h> // библиотеки на open gl для mac
  4. #include <GLUT/glut.h>
  5. #include <GLFW/glfw3.h>
  6. #define GLEW_STATIC
  7. #include <GL/glew.h>
  8. #include <stdio.h>
  9.  
  10. */
  11.  
  12. #include <iostream>
  13. #define GLEW_STATIC
  14. #include <GL/glew.h>
  15. #include <GLFW/glfw3.h>
  16.  
  17. int main(void)
  18. {
  19.     GLFWwindow* window;                     //инициализируем библиотеку
  20.     if (!glfwInit())
  21.         return -1;
  22.     window = glfwCreateWindow(640, 480, "Hello World",      //создаем окно контекста open gl
  23.                               NULL, NULL);
  24.     if (!window)                            //проверка открылось ли окно
  25.     {
  26.         glfwTerminate();
  27.         return -1;
  28.     }
  29.    
  30.     glfwMakeContextCurrent(window);             //сделать данное контекстное окно главным
  31.     if (glewInit() != GLEW_OK)
  32.         std::cout << "Error" << std::endl;
  33.     std::cout << glGetString(GL_VERSION) <<
  34.     std::endl;
  35.     float positions[6] = {
  36.         -0.5f, -0.5f,
  37.         0.0f, 0.5f,
  38.         0.5f, -0.5f
  39.     };
  40.     unsigned int buffer;
  41.     glGenBuffers (1, &buffer);
  42.     glBindBuffer (GL_ARRAY_BUFFER, buffer);
  43.     glBufferData (GL_ARRAY_BUFFER, 6 *
  44.                   sizeof(float), positions, GL_STATIC_DRAW);
  45.     glEnableVertexAttribArray(0);
  46.     glVertexAttribPointer(0,2, GL_FLOAT, GL_FALSE,
  47.                           sizeof(float) * 2, 0);
  48.     glBindBuffer (GL_ARRAY_BUFFER, 0);
  49.     //unsigned int(a);
  50.     //glGenBuffers(1, &a);
  51.  
  52.     while (!glfwWindowShouldClose(window))          //цикл пока пользователь не закроет окно
  53.     {
  54.        
  55.         glClear(GL_COLOR_BUFFER_BIT);               //рендер
  56.  
  57.         glDrawArrays(GL_TRIANGLES, 0, 3);           //рисуем трeугольник
  58.         glfwSwapBuffers(window);                    //меняет передний и задний буферы
  59.        
  60.         glfwPollEvents();
  61.     }
  62.     glfwTerminate();
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement