Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <vgl.h>
  3. #include <LoadShaders.h>
  4. using std::cerr;
  5. using std::endl;
  6.  
  7. enum VAO_IDs { Triangles, NumVAOs };
  8. enum Buffer_IDs { ArrayBuffer, NumBuffers };
  9. enum Attrib_IDs { vPosition = 0 };
  10. GLuint VAOs[NumVAOs];
  11. GLuint Buffers[NumBuffers];
  12. const GLuint NumVertices = 6;
  13. //---------------------------------------------------------------------
  14. //
  15. // init
  16. //
  17. void
  18.     init(void)
  19. {
  20.     glGenVertexArrays(NumVAOs, VAOs);
  21.     glBindVertexArray(VAOs[Triangles]);
  22.     GLfloat vertices[NumVertices][2] = {
  23.         { -0.90, -0.90 }, // Triangle 1
  24.         { 0.85, -0.90 },
  25.         { -0.90, 0.85 },
  26.         { 0.90, -0.85 }, // Triangle 2
  27.         { 0.90, 0.90 },
  28.         { -0.85, 0.90 }
  29.     };
  30.     glGenBuffers(NumBuffers, Buffers);
  31.     glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
  32.     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),
  33.         vertices, GL_STATIC_DRAW);
  34.     ShaderInfo shaders[] = {
  35.         { GL_VERTEX_SHADER, "triangles.vert" },
  36.         { GL_FRAGMENT_SHADER, "triangles.frag" },
  37.         { GL_NONE, NULL }
  38.     };
  39.     GLuint program = LoadShaders(shaders);
  40.     glUseProgram(program);
  41.     glVertexAttribPointer(vPosition, 2, GL_FLOAT,
  42.         GL_FALSE, 0, BUFFER_OFFSET(0));
  43.     glEnableVertexAttribArray(vPosition);
  44. }
  45. //---------------------------------------------------------------------
  46. //
  47. // display
  48. //
  49. void
  50.     display(void)
  51. {
  52.     glClear(GL_COLOR_BUFFER_BIT);
  53.     glBindVertexArray(VAOs[Triangles]);
  54.     glDrawArrays(GL_TRIANGLES, 0, NumVertices);
  55.     glFlush();
  56. }
  57. //---------------------------------------------------------------------
  58. //
  59. // main
  60. //
  61. int
  62.     main(int argc, char** argv)
  63. {
  64.     glutInit(&argc, argv);
  65.     glutInitDisplayMode(GLUT_RGBA);
  66.     glutInitWindowSize(512, 512);
  67.     glutInitContextVersion(4, 3);
  68.     glutInitContextProfile(GLUT_CORE_PROFILE);
  69.     glutCreateWindow(argv[0]);
  70.     if (glewInit()) {
  71.         cerr << "Unable to initialize GLEW ... exiting" << endl;
  72.         exit(EXIT_FAILURE);
  73.     }
  74.     init();
  75.     glutDisplayFunc(display);
  76.     glutMainLoop();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement