Advertisement
Guest User

Untitled

a guest
Aug 1st, 2013
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <opengl/glew.h>
  4. #include <opengl/glfw3.h>
  5. #include <glm\glm.hpp>
  6. using namespace glm;
  7.  
  8. int main()
  9. {
  10.     if(!glfwInit())
  11.     {
  12.         printf("\nFailed to initialize GLFW.");
  13.         return -1;
  14.     }
  15.  
  16.     GLFWwindow *window;
  17.  
  18.     glfwWindowHint(GLFW_SAMPLES, 4);
  19.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  20.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  21.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  22.  
  23.     window = glfwCreateWindow(1024, 768, "Simple example", NULL, NULL);
  24.     if(!window)
  25.     {
  26.         printf("\nFailed to create window.");
  27.         glfwTerminate();
  28.         return -1;
  29.     }
  30.  
  31.     glfwMakeContextCurrent(window);
  32.  
  33.     glewExperimental = true;
  34.     if(glewInit() != GLEW_OK)
  35.     {
  36.         printf("\nFailed to initialize GLEW.");
  37.         glfwTerminate();
  38.         return -1;
  39.     }
  40.  
  41.     GLuint VertexArrayID;
  42.     glGenVertexArrays(1, &VertexArrayID);
  43.     glBindVertexArray(VertexArrayID);
  44.  
  45.     static const GLfloat g_vertex_buffer_data[] = {
  46.         -1.0f, -1.0f, 0.0f,
  47.          1.0f, -1.0f, 0.0f,
  48.          0.0f,  1.0f, 0.0f
  49.     };
  50.  
  51.     GLuint vertexBuffer;
  52.     glGenBuffers(1, &vertexBuffer);
  53.     glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
  54.     glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
  55.  
  56.     while(!glfwWindowShouldClose(window))
  57.     {
  58.         glEnableVertexAttribArray(0);
  59.         glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
  60.         glVertexAttribPointer(0,3,GL_FLOAT, GL_FALSE, 0 , (void*)0);
  61.         glDrawArrays(GL_TRIANGLES, 0,3);
  62.         glDisableVertexAttribArray(0);
  63.  
  64.         glfwSwapBuffers(window);
  65.         glfwPollEvents();
  66.     }
  67.  
  68.     glfwDestroyWindow(window);
  69.     glfwTerminate();
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement