Advertisement
alestane

OpenGL init

Jan 25th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. GLfloat vertices[] = {
  2.     -1.0f, -1.0f,  1.0f,
  3.      1.0f, -1.0f,  1.0f,
  4.     -1.0f,  1.0f,  1.0f,
  5.      1.0f,  1.0f,  1.0f,
  6.     -1.0f, -1.0f, -1.0f,
  7.      1.0f, -1.0f, -1.0f,
  8.      1.0f,  1.0f, -1.0f,
  9.     -1.0f,  1.0f, -1.0f,
  10. };
  11.  
  12.     glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
  13.     glClearDepth( 1.0f );
  14.     glEnable( GL_DEPTH_TEST );
  15.     glDepthFunc( GL_LEQUAL );
  16.  
  17.     glViewport( 0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height) ); // 640 x 480
  18.  
  19.     glUseProgram(prog) // already successfully compiled and linked
  20.     glUniform1f(glGetAttribLocation(prog, "height"), 2.0f);
  21.     glUniform1f(glGetAttribLocation(prog, "aspect"), 4.0f/3.0f);
  22.     glUniform1f(glGetAttribLocation(prog, "zNear"), -2.0f);
  23.     glUniform1f(glGetAttribLocation(prog, "zFar"), 2.0f);
  24.     glGenBuffers(1, &vbo);
  25.     glBindBuffer(GL_ARRAY_BUFFER, vbo);
  26.     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
  27.     glGenVertexArrays(1, &vao);
  28.     glBindVertexArray(vao);
  29.     GLuint name = glGetAttribLocation(prog, "position");
  30.     glEnableVertexAttribArray(name);
  31.     glVertexAttribPointer(name, 3, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<void*>(0));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement